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

Commit

Permalink
Cleanup and remove failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
seowalex committed Jan 18, 2023
1 parent c63f286 commit b4207b5
Show file tree
Hide file tree
Showing 58 changed files with 31 additions and 915 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `logs` command.
- `ps` command.
- `top` command.
- `images` command.
- `port` command.
- `ls` command.
- `convert` command.
Expand Down
2 changes: 0 additions & 2 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub(crate) enum ExtCommand {
Logs(logs::Args),
Ps(ps::Args),
Top(top::Args),
Images(images::Args),
Port(port::Args),
Ls(ls::Args),
}
Expand Down Expand Up @@ -62,7 +61,6 @@ pub(crate) async fn run(command: Command, config: Config) -> Result<()> {
ExtCommand::Logs(args) => logs::run(args, &podman, &file).await,
ExtCommand::Ps(args) => ps::run(args, &podman, &file).await,
ExtCommand::Top(args) => top::run(args, &podman, &file).await,
ExtCommand::Images(args) => images::run(args, &podman, &file).await,
ExtCommand::Port(args) => port::run(args, &podman, &file).await,
ExtCommand::Ls(args) => ls::run(args, &podman).await,
}?
Expand Down
4 changes: 1 addition & 3 deletions src/commands/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,9 @@ pub(crate) fn run(args: Args, config: &Config) -> Result<()> {
println!("{profile}");
}
} else if args.images {
for (name, service) in file.services {
for service in file.services.into_values() {
if let Some(image) = service.image {
println!("{image}");
} else {
println!("{}-{name}", file.name.as_ref().unwrap());
}
}
} else {
Expand Down
29 changes: 3 additions & 26 deletions src/commands/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ use tokio_stream::wrappers::BroadcastStream;

use crate::{
commands::down,
compose::{
self,
types::{Compose, FileReference, ServiceVolume, ServiceVolumeType},
},
compose::types::{Compose, FileReference, ServiceVolume, ServiceVolumeType},
config::Config,
podman::{types::Pod, Podman},
progress::{Finish, Progress},
Expand All @@ -32,14 +29,6 @@ use crate::{
pub(crate) struct Args {
pub(crate) services: Vec<String>,

/// Build images before starting containers
// #[arg(long, conflicts_with = "no_build")]
// build: bool,

/// Don't build an image, even if it's missing
// #[arg(long, conflicts_with = "build")]
// no_build: bool,

/// Pull image before running
#[arg(long, value_enum)]
pub(crate) pull: Option<PullPolicy>,
Expand Down Expand Up @@ -260,13 +249,7 @@ async fn create_containers(
let mut dependencies = file
.services
.iter()
.flat_map(|(to, service)| {
service
.depends_on
.keys()
.chain(service.links.keys())
.map(move |from| (from, to, ()))
})
.flat_map(|(to, service)| service.depends_on.keys().map(move |from| (from, to, ())))
.collect::<DiGraphMap<_, _>>();

for service in file.services.keys() {
Expand Down Expand Up @@ -369,13 +352,7 @@ async fn create_containers(
.collect::<Vec<_>>();
let pull_policy =
args.pull.as_ref().map(ToString::to_string).or_else(|| {
service.pull_policy.as_ref().and_then(|pull_policy| {
if *pull_policy == compose::types::PullPolicy::Build {
None
} else {
Some(pull_policy.to_string())
}
})
service.pull_policy.as_ref().map(ToString::to_string)
});

let networks = service
Expand Down
86 changes: 0 additions & 86 deletions src/commands/images.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/commands/restart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ async fn restart_containers(
service
.depends_on
.keys()
.chain(service.links.keys())
.filter(|service| containers.keys().contains(service))
.map(move |from| (from, to, ()))
})
Expand Down
1 change: 0 additions & 1 deletion src/commands/rm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ pub(crate) async fn remove_containers(
service
.depends_on
.keys()
.chain(service.links.keys())
.filter(|service| containers.keys().contains(service))
.map(move |to| (from, to, ()))
})
Expand Down
29 changes: 5 additions & 24 deletions src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ use fastrand::Rng;

use crate::{
commands::{create, start},
compose::{
self,
types::{
parse_port, parse_service_volume, Compose, FileReference, Port, Service, ServiceVolume,
ServiceVolumeType,
},
compose::types::{
parse_port, parse_service_volume, Compose, FileReference, Port, Service, ServiceVolume,
ServiceVolumeType,
},
config::Config,
podman::Podman,
Expand Down Expand Up @@ -83,10 +80,6 @@ pub(crate) struct Args {
#[arg(long, conflicts_with = "publish")]
service_ports: bool,

/// Build image before starting container
// #[arg(long)]
// build: bool,

/// Remove containers for services not defined in the Compose file
#[arg(long)]
remove_orphans: bool,
Expand All @@ -109,7 +102,6 @@ async fn run_container(
service
.depends_on
.keys()
.chain(service.links.keys())
.filter_map(|service_name| {
file.services.get(service_name).map(|service| {
(1..=service
Expand Down Expand Up @@ -139,13 +131,7 @@ async fn run_container(
.into_iter()
.map(|label| format!("io.podman.compose.{}={}", label.0, label.1))
.collect::<Vec<_>>();
let pull_policy = service.pull_policy.as_ref().and_then(|pull_policy| {
if *pull_policy == compose::types::PullPolicy::Build {
None
} else {
Some(pull_policy.to_string())
}
});
let pull_policy = service.pull_policy.as_ref().map(ToString::to_string);

let networks = service
.networks
Expand Down Expand Up @@ -252,12 +238,7 @@ pub(crate) async fn run(
.services
.get(&args.service)
.ok_or_else(|| anyhow!("No such service: \"{}\"", args.service))?;
let services = service
.depends_on
.keys()
.chain(service.links.keys())
.cloned()
.collect::<Vec<_>>();
let services = service.depends_on.keys().cloned().collect::<Vec<_>>();

if !args.no_deps {
create::run(
Expand Down
8 changes: 1 addition & 7 deletions src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ async fn start_containers(
let mut dependencies = file
.services
.iter()
.flat_map(|(to, service)| {
service
.depends_on
.keys()
.chain(service.links.keys())
.map(move |from| (from, to, ()))
})
.flat_map(|(to, service)| service.depends_on.keys().map(move |from| (from, to, ())))
.collect::<DiGraphMap<_, _>>();

for service in file.services.keys() {
Expand Down
1 change: 0 additions & 1 deletion src/commands/stop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pub(crate) async fn stop_containers(
service
.depends_on
.keys()
.chain(service.links.keys())
.filter(|service| containers.keys().contains(service))
.map(move |to| (from, to, ()))
})
Expand Down
8 changes: 0 additions & 8 deletions src/commands/up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ pub(crate) struct Args {
#[arg(short, long, conflicts_with_all = ["attach", "attach_dependencies"])]
detach: bool,

/// Build images before starting containers
// #[arg(long, conflicts_with = "no_build")]
// build: bool,

/// Don't build an image, even if it's missing
// #[arg(long, conflicts_with = "build")]
// no_build: bool,

/// Pull image before running
#[arg(long, value_enum)]
pull: Option<PullPolicy>,
Expand Down
60 changes: 21 additions & 39 deletions src/compose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::{
use anyhow::{anyhow, bail, Context, Error, Result};
use indexmap::IndexSet;
use itertools::Itertools;
use path_absolutize::Absolutize;
use petgraph::{algo::tarjan_scc, graphmap::DiGraphMap};
use serde_yaml::Value;

Expand Down Expand Up @@ -244,30 +243,29 @@ pub(crate) fn parse(config: &Config, no_interpolate: bool) -> Result<Compose> {
false
});

let mut all_networks = IndexSet::new();
let mut all_volumes = IndexSet::new();
let mut all_secrets = IndexSet::new();

for service in combined_file.services.values_mut() {
if let Some(build) = &mut service.build {
build.dockerfile = build
.dockerfile
.absolutize_from(&build.context)?
.to_path_buf();
}

all_networks.extend(service.networks.keys());
all_volumes.extend(
let all_networks = combined_file
.services
.values()
.flat_map(|service| service.networks.keys())
.collect::<IndexSet<_>>();
let all_volumes = combined_file
.services
.values()
.flat_map(|service| {
service
.volumes
.iter()
.filter_map(|volume| match &volume.r#type {
ServiceVolumeType::Volume(source) => source.as_ref(),
_ => None,
}),
);
all_secrets.extend(service.secrets.iter().map(|secret| &secret.source));
}
})
})
.collect::<IndexSet<_>>();
let all_secrets = combined_file
.services
.values()
.flat_map(|service| service.secrets.iter().map(|secret| &secret.source))
.collect::<IndexSet<_>>();

combined_file
.networks
Expand Down Expand Up @@ -359,8 +357,8 @@ pub(crate) fn parse(config: &Config, no_interpolate: bool) -> Result<Compose> {
);
}

if service.build.is_none() && service.image.is_none() {
bail!("Service \"{name}\" has neither an image nor a build context specified");
if service.image.is_none() {
bail!("Service \"{name}\" does not have an image specified");
}

if service.network_mode.as_deref().unwrap_or_default() == "host"
Expand Down Expand Up @@ -389,17 +387,7 @@ pub(crate) fn parse(config: &Config, no_interpolate: bool) -> Result<Compose> {
}
}

if let Some(build) = &service.build {
for label in build.labels.keys() {
if label.starts_with("io.podman.compose") {
bail!(
"Service \"name\" cannot have labels starting with \"io.podman.compose\""
);
}
}
}

for dependency in service.depends_on.keys().chain(service.links.keys()) {
for dependency in service.depends_on.keys() {
if !combined_file.services.contains_key(dependency) {
bail!("Service \"{name}\" depends on undefined service \"{dependency}\"");
}
Expand Down Expand Up @@ -480,13 +468,7 @@ pub(crate) fn parse(config: &Config, no_interpolate: bool) -> Result<Compose> {
let dependencies = combined_file
.services
.iter()
.flat_map(|(to, service)| {
service
.depends_on
.keys()
.chain(service.links.keys())
.map(move |from| (from, to, ()))
})
.flat_map(|(to, service)| service.depends_on.keys().map(move |from| (from, to, ())))
.collect::<DiGraphMap<_, _>>();
let cycles = tarjan_scc(&dependencies)
.into_iter()
Expand Down
Loading

0 comments on commit b4207b5

Please sign in to comment.