Crate compose_spec
source ·Expand description
compose_spec
is a library for (de)serializing from/to the Compose specification.
This library attempts to make interacting with and creating Compose files as idiomatic and correct as possible.
PathBuf
s are used for fields which denote a path.- Enums are used for fields which conflict with each other.
- Values are fully parsed and validated when they have a defined format.
- Lists that must contain unique values use
IndexSet
, otherwise they areVec
s. - Strings which represent a span of time are converted to/from
Duration
s, see theduration
module.
Note that the Deserialize
implementations of many types make use of
Deserializer::deserialize_any()
. This means that
you should only attempt to deserialize them from self-describing formats like YAML or JSON.
§Examples
use compose_spec::{Compose, Service, service::Image};
let yaml = "\
services:
caddy:
image: docker.io/library/caddy:latest
ports:
- 8000:80
- 8443:443
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- caddy-data:/data
volumes:
caddy-data:
";
// Deserialize `Compose`
let compose: Compose = serde_yaml::from_str(yaml)?;
// Serialize `Compose`
let value = serde_yaml::to_value(&compose)?;
// Get the `Image` of the "caddy" service
let caddy: Option<&Service> = compose.services.get("caddy");
let image: &Option<Image> = &caddy.unwrap().image;
let image: &Image = image.as_ref().unwrap();
assert_eq!(image, "docker.io/library/caddy:latest");
assert_eq!(image.name(), "docker.io/library/caddy");
assert_eq!(image.tag(), Some("latest"));
§Short or Long Syntax Values
Many values within the Compose specification can be represented in either a short or long
syntax. The enum ShortOrLong
is used to for these values. Conversion from the Short
syntax to the Long
syntax is always possible. The AsShort
trait is used for Long
syntax types which may be represented directly as the Short
syntax type if additional
options are not set.
Re-exports§
pub use self::config::Config;
pub use self::network::Network;
pub use self::secret::Secret;
pub use self::service::Service;
Modules§
- Utilities for working with
Duration
s.
Structs§
- The Compose file is a YAML file defining a containers based application.
- Valid extension key string.
- Validated identifier for use as a map key in a
Compose
file. - A Compose sub-project to include.
- Valid map key string.
- Validated
Compose
project name. - A named volume which can be reused across multiple
Service
s.
Enums§
- Error returned when attempting to create a
ExtensionKey
. - Error returned when attempting to create a
Identifier
. - Error returned when attempting to create a
MapKey
. - Error returned when attempting to create a
Name
. - A single item or a list of unique items.
- A list of unique strings or a map with optional single values.
- A numerical
Value
. - Error returned when parsing a
Number
from a string. - A string or number value.
- Error returned when failing to convert a
Number
into another type. - Error returned when attempting to convert
Value
into another type. - A single string, number, or boolean value.
- Represents any valid YAML value.
Traits§
- Trait for types that represent a long syntax which could also be represented in a short syntax.
Type Aliases§
- Configs allow
Service
s to adapt their behavior without needing to rebuild the container image. - Extensions can be used to enable experimental features or make a
Compose
file easier to maintain via anchors and aliases. - Map with optional single values.
- Named networks which allow for
Service
s to communicate with each other. - Sensitive data that a
Service
may be granted access to. - Named volumes which can be reused across multiple
Service
s.