Skip to content
This repository has been archived by the owner on Apr 10, 2024. It is now read-only.

Commit

Permalink
Update to latest Compose spec
Browse files Browse the repository at this point in the history
  • Loading branch information
seowalex committed Apr 30, 2023
1 parent 3695d61 commit f4d89ef
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Update the `--volumes` flag description in the `down` command to properly reflect that it does not remove named volumes.
- Add support for `cgroup` and `uts` in service definition.
- Make `network_mode` and `networks` mutually exclusive attributes.

## [0.1.7] - 2023-03-31

Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ keywords = ["podman", "compose", "docker", "docker-compose"]
categories = ["command-line-utilities"]

[dependencies]
anyhow = "1.0.70"
anyhow = "1.0.71"
atty = "0.2.14"
automod = "1.0.8"
byte-unit = { version = "4.0.19", default-features = false, features = ["serde", "std"] }
Expand Down
4 changes: 4 additions & 0 deletions src/compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ pub(crate) fn parse(config: &Config, no_interpolate: bool) -> Result<Compose> {
bail!("Service \"{name}\" does not have an image specified");
}

if service.network_mode.is_some() && service.networks.keys().any(|key| key != "default") {
bail!("Service \"{name}\" cannot have networks due to the network mode set");
}

if service.network_mode.as_deref().unwrap_or_default() == "host"
&& !service.ports.is_empty()
{
Expand Down
10 changes: 10 additions & 0 deletions src/compose/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub(crate) struct Service {
pub(crate) blkio_config: Option<BlkioConfig>,
pub(crate) cap_add: Vec<String>,
pub(crate) cap_drop: Vec<String>,
pub(crate) cgroup: Option<String>,
pub(crate) cgroup_parent: Option<String>,
#[serde_as(as = "PickFirst<(_, CommandOrString)>")]
pub(crate) command: Vec<String>,
Expand Down Expand Up @@ -173,6 +174,7 @@ pub(crate) struct Service {
pub(crate) ulimits: IndexMap<String, ResourceLimit>,
pub(crate) user: Option<String>,
pub(crate) userns_mode: Option<String>,
pub(crate) uts: Option<String>,
#[serde_as(as = "SetLastValueWins<PickFirst<(_, ServiceVolumeOrString)>>")]
pub(crate) volumes: IndexSet<ServiceVolume>,
pub(crate) volumes_from: Vec<String>,
Expand Down Expand Up @@ -267,6 +269,10 @@ impl Service {
args.extend([String::from("--cap-drop"), cap_drop]);
}

if let Some(cgroup) = self.cgroup.as_ref().cloned() {
args.extend([String::from("--cgroupns"), cgroup]);
}

if let Some(cgroup_parent) = self.cgroup_parent.as_ref().cloned() {
args.extend([String::from("--cgroup-parent"), cgroup_parent]);
}
Expand Down Expand Up @@ -594,6 +600,10 @@ impl Service {
args.extend([String::from("--userns"), userns_mode]);
}

if let Some(uts) = self.uts.as_ref().cloned() {
args.extend([String::from("--uts"), uts]);
}

for volume in self.volumes_from.iter().cloned() {
args.extend([String::from("--volumes-from"), volume]);
}
Expand Down

0 comments on commit f4d89ef

Please sign in to comment.