Skip to main content

from_resource

Function from_resource 

Source
pub fn from_resource(
    project: &str,
    resource_name: &str,
    kind: &ResourceKind,
) -> Result<ResolvedResource, SpecError>
Expand description

Resolve a manifest resource declaration into a ResolvedResource.

This is the single entry point into lightshuttle-spec. It dispatches on kind and applies all v0 defaults:

  • Image: falls back to the official Alpine image for the declared version (e.g. postgres:16-alpine, redis:7-alpine).
  • Database name (postgres): defaults to resource_name.
  • User (postgres): defaults to "postgres".
  • Password: generated with a 24-character CSPRNG-backed alphabet when absent from the manifest.
  • Ports: uses the canonical default port for postgres (5432) and redis (6379).
  • Healthcheck: injects pg_isready / redis-cli ping when the manifest omits a healthcheck for managed services.

The container name is always <project>_<resource_name> and also serves as the DNS hostname inside the project network.

§Errors

Returns crate::SpecError::InvalidSpec when a port mapping, volume string, or duration in the manifest is syntactically invalid.

§Example

use lightshuttle_manifest::{PostgresConfig, ResourceKind};
use lightshuttle_spec::from_resource;

let kind = ResourceKind::Postgres(PostgresConfig::default());
let resolved = from_resource("acme", "db", &kind).unwrap();

// Container name follows the `<project>_<resource>` convention.
assert_eq!(resolved.spec.name, "acme_db");
// A connection URL is always present for postgres.
assert!(resolved.outputs["url"].starts_with("postgres://"));