diff --git a/src/cmd/compose.rs b/src/cmd/compose.rs index 48ec6c9c..e2f70e9a 100644 --- a/src/cmd/compose.rs +++ b/src/cmd/compose.rs @@ -131,19 +131,19 @@ fn runs_docker_compose_on_all_pods() { assert_ran!(runner, { ["docker-compose", "-p", - "railshello", + "railshello_db", "-f", proj.output_dir().join("pods").join("db.yml"), "stop"], ["docker-compose", "-p", - "railshello", + "railshello_frontend", "-f", proj.output_dir().join("pods").join("frontend.yml"), "stop"], ["docker-compose", "-p", - "railshello", + "railshello_rake", "-f", proj.output_dir().join("pods").join("rake.yml"), "stop"] @@ -166,13 +166,13 @@ fn runs_docker_compose_on_named_pods_and_services() { assert_ran!(runner, { ["docker-compose", "-p", - "railshello", + "railshello_db", "-f", proj.output_dir().join("pods").join("db.yml"), "stop"], ["docker-compose", "-p", - "railshello", + "railshello_frontend", "-f", proj.output_dir().join("pods").join("frontend.yml"), "stop", diff --git a/src/cmd/exec.rs b/src/cmd/exec.rs index 382119a0..0ba40c8f 100644 --- a/src/cmd/exec.rs +++ b/src/cmd/exec.rs @@ -100,7 +100,7 @@ fn invokes_docker_exec() { [ "docker-compose", "-p", - "hello", + "hello_frontend", "-f", proj.output_dir().join("pods").join("frontend.yml"), "exec", @@ -127,7 +127,7 @@ fn runs_shells() { [ "docker-compose", "-p", - "hello", + "hello_frontend", "-f", proj.output_dir().join("pods").join("frontend.yml"), "exec", diff --git a/src/cmd/logs.rs b/src/cmd/logs.rs index fa9984d7..9474d3ae 100644 --- a/src/cmd/logs.rs +++ b/src/cmd/logs.rs @@ -59,7 +59,7 @@ fn runs_docker_compose_logs() { [ "docker-compose", "-p", - "railshello", + "railshello_frontend", "-f", proj.output_dir().join("pods").join("frontend.yml"), "logs", diff --git a/src/cmd/pull.rs b/src/cmd/pull.rs index 9d9cedbc..251885a6 100644 --- a/src/cmd/pull.rs +++ b/src/cmd/pull.rs @@ -46,7 +46,7 @@ fn runs_docker_compose_pull_on_all_pods() { .join("hello.hook")], ["docker-compose", "-p", - "hello", + "hello_frontend", "-f", proj.output_dir().join("pods").join("frontend.yml"), "pull"] diff --git a/src/cmd/run.rs b/src/cmd/run.rs index 1510fbda..64a7b66c 100644 --- a/src/cmd/run.rs +++ b/src/cmd/run.rs @@ -136,7 +136,7 @@ fn runs_a_single_service_pod() { [ "docker-compose", "-p", - "railshello", + "railshello_rake", "-f", proj.output_dir().join("pods").join("rake.yml"), "run", @@ -163,7 +163,7 @@ fn runs_tests() { [ "docker-compose", "-p", - "hellotest", + "hellotest_frontend", "-f", proj.output_pods_dir().join("frontend.yml"), "run", @@ -194,7 +194,7 @@ fn runs_tests_with_custom_command() { [ "docker-compose", "-p", - "hellotest", + "hellotest_frontend", "-f", proj.output_pods_dir().join("frontend.yml"), "run", diff --git a/src/cmd/run_script.rs b/src/cmd/run_script.rs index 5bbb37de..b10b1742 100644 --- a/src/cmd/run_script.rs +++ b/src/cmd/run_script.rs @@ -84,7 +84,7 @@ fn runs_scripts_on_all_services() { [ "docker-compose", "-p", - "railshello", + "railshello_rake", "-f", proj.output_dir().join("pods").join("rake.yml"), "run", diff --git a/src/cmd/up.rs b/src/cmd/up.rs index 8ddeee67..04b5e23e 100644 --- a/src/cmd/up.rs +++ b/src/cmd/up.rs @@ -141,7 +141,7 @@ fn runs_docker_compose_up_honors_enable_in_targets() { [ "docker-compose", "-p", - "railshello", + "railshello_frontend", "-f", proj.output_dir().join("pods").join("frontend.yml"), "up", diff --git a/src/pod.rs b/src/pod.rs index d95900e1..1705e6e4 100644 --- a/src/pod.rs +++ b/src/pod.rs @@ -417,7 +417,7 @@ impl Pod { pub fn compose_args(&self, proj: &Project) -> Result> { Ok(vec![ "-p".into(), - proj.compose_name().into(), + proj.compose_name(Some(&self)).into(), "-f".into(), proj.output_pods_dir().join(self.rel_path()).into(), ]) diff --git a/src/project.rs b/src/project.rs index 0e6dc909..5da2448f 100644 --- a/src/project.rs +++ b/src/project.rs @@ -362,8 +362,8 @@ impl Project { } /// Get that name that `docker_compose` would use for this project. - pub fn compose_name(&self) -> String { - self.current_target.compose_project_name(self) + pub fn compose_name(&self, pod: Option<&Pod>) -> String { + self.current_target.compose_project_name(self, pod) } /// The root directory of this project. diff --git a/src/runtime_state.rs b/src/runtime_state.rs index f0c81a13..2c150146 100644 --- a/src/runtime_state.rs +++ b/src/runtime_state.rs @@ -38,7 +38,7 @@ impl RuntimeState { .enable_all() .build()?; - let name = project.compose_name(); + let name = project.compose_name(None); let target = project.current_target().name().to_owned(); let docker = boondock::Docker::connect_with_defaults()?; @@ -51,17 +51,27 @@ impl RuntimeState { .chain_err(|| { format!("error looking up container {:?}", container.Id) })?; + let labels = &info.Config.Labels; - if labels.get("com.docker.compose.project") == Some(&name) - && labels.get("io.fdy.cage.target") == Some(&target) - { - if let Some(service) = labels.get("com.docker.compose.service") { - let our_info = ContainerInfo::new(&info)?; - services - .entry(service.to_owned()) - .or_insert_with(Vec::new) - .push(our_info); + + if let Some(project_name) = labels.get("com.docker.compose.project") { + if !project_name.starts_with(&name) { + break; } + } else { + break; + } + + if labels.get("io.fdy.cage.target") != Some(&target) { + break; + } + + if let Some(service) = labels.get("com.docker.compose.service") { + let our_info = ContainerInfo::new(&info)?; + services + .entry(service.to_owned()) + .or_insert_with(Vec::new) + .push(our_info); } } Ok(RuntimeState { services }) diff --git a/src/target.rs b/src/target.rs index f23cd3a3..fca76049 100644 --- a/src/target.rs +++ b/src/target.rs @@ -3,6 +3,7 @@ use regex::Regex; +use crate::pod::Pod; use crate::project::Project; /// An `Target` provides collection of extensions to a project's basic @@ -63,20 +64,32 @@ impl Target { } /// Get a value for `docker-compose`'s `-p` argument for a given project. - pub fn compose_project_name(&self, project: &Project) -> String { + pub fn compose_project_name( + &self, + project: &Project, + pod: Option<&Pod>, + ) -> String { let base_name: String = if self.name == "test" { format!("{}test", project.name()) } else { project.name().to_owned() }; + let pod_name = match pod { + Some(p) => p.name(), + None => "", + }; + // We strip out non-alphabetic characters and convert everything to // lowercase, which is what the `docker-compose` source code does. lazy_static! { static ref NON_ALNUM: Regex = Regex::new(r#"[^a-z0-9]"#).unwrap(); } - NON_ALNUM + + let base_name = NON_ALNUM .replace_all(&base_name.to_lowercase(), "") - .into_owned() + .into_owned(); + + format!("{}_{}", base_name, pod_name).to_owned() } }