Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
dev_containers: Preserve Compose entrypoints by default (#61897)
Alan P Johnb7de76402cdf
diff --git a/crates/dev_container/src/devcontainer_json.rs b/crates/dev_container/src/devcontainer_json.rsindex 38588241bdf..81c512486f0 100644--- a/crates/dev_container/src/devcontainer_json.rs+++ b/crates/dev_container/src/devcontainer_json.rs@@ -278,6 +278,13 @@ impl DevContainer {}}+ pub(crate) fn override_command(&self) -> bool {+ self.override_command.unwrap_or(!matches!(+ self.build_type(),+ DevContainerBuildType::DockerCompose+ ))+ }+pub(crate) fn validate_devcontainer_contents(&self) -> Result<(), DevContainerError> {match self.build_type() {DevContainerBuildType::Image(_) => Ok(()),@@ -634,6 +641,39 @@ mod test {},};+ #[test]+ fn override_command_defaults_depend_on_build_type() {+ let image = deserialize_devcontainer_json(r#"{"image":"ubuntu"}"#).expect("image config");+ assert!(image.override_command());++ let dockerfile = deserialize_devcontainer_json(r#"{"build":{"dockerfile":"Dockerfile"}}"#)+ .expect("Dockerfile config");+ assert!(dockerfile.override_command());++ let compose = deserialize_devcontainer_json(+ r#"{"dockerComposeFile":"compose.yaml","service":"app"}"#,+ )+ .expect("Compose config");+ assert!(!compose.override_command());+ }++ #[test]+ fn explicit_override_command_takes_precedence_over_build_type_default() {+ let image = deserialize_devcontainer_json(r#"{"image":"ubuntu","overrideCommand":false}"#)+ .expect("image config");+ assert!(!image.override_command());++ let compose = deserialize_devcontainer_json(+ r#"{+ "dockerComposeFile":"compose.yaml",+ "service":"app",+ "overrideCommand":true+ }"#,+ )+ .expect("Compose config");+ assert!(compose.override_command());+ }+#[test]fn should_deserialize_customizations_with_unknown_keys() {let json_with_other_customizations = r#"diff --git a/crates/dev_container/src/devcontainer_manifest.rs b/crates/dev_container/src/devcontainer_manifest.rsindex d3ee79cf888..c8a5bce1f8f 100644--- a/crates/dev_container/src/devcontainer_manifest.rs+++ b/crates/dev_container/src/devcontainer_manifest.rs@@ -877,9 +877,7 @@ RUN sed -i -E 's/((^|\s)PATH=)([^\$]*)$/\1\${{PATH:-\3}}/g' /etc/profile || truepush_unique_string(&mut security_opt, &opt);}- let entrypoint_script = if dev_container.override_command == Some(false) {- None- } else {+ let entrypoint_script = if dev_container.override_command() {let mut entrypoint_script_lines = vec!["echo Container started".to_string(),"trap \"exit 0\" 15".to_string(),@@ -894,6 +892,8 @@ RUN sed -i -E 's/((^|\s)PATH=)([^\$]*)$/\1\${{PATH:-\3}}/g' /etc/profile || true]);Some(entrypoint_script_lines.join("\n").trim().to_string())+ } else {+ None};let mut container_env = HashMap::new();@@ -5150,7 +5150,7 @@ ENV DOCKER_BUILDKIT=1Some(vec!["seccomp=unconfined".to_string()]));assert_eq!(app_service.privileged, Some(true));- assert!(app_service.entrypoint.is_some());+ assert!(app_service.entrypoint.is_none());let labels = app_service.labels.as_ref().unwrap();assert_eq!(