devcontainers / spec

Development Containers: Use a container as a full-featured development environment.
https://containers.dev
Creative Commons Attribution 4.0 International
3.36k stars 206 forks source link

Duplication while merging lifecycle commands? #268

Open avidal opened 1 year ago

avidal commented 1 year ago

While I'm going deep on config merge logic, I realized that there may be an opportunity to clarify what should happen in a merge where lifecycle commands are stored in image metadata that are duplicates of lifecycle commands defined in the devcontainer.json or devcontainer-feature.json.

Consider the following:

// devcontainer.json

{ "onCreateCommand": {"db": "script/migrate"}}

// devcontainer-feature.json

{ "onCreateCommand": ["/usr/share/devcontainer/features/statics/build-static"] }

If you prebuild the container, you'll end up with the following stored in the devcontainer.metadata image label:

{ "onCreateCommand": [
    {"db": "script/migrate"},
    ["/usr/share/devcontainer/features/statics/build-static"]
]}

Later, you want to create a devcontainer using this prebuild (and using the same devcontainer.json). According to the spec, I believe you'd end up duplicating onCreateCommand and ending up with four entries.

EDIT: Maybe it's sufficient to expand on the metadata in image labels section to suggest avoiding using the same devcontainer.json as the one used to make the prebuild.

bamurtaugh commented 1 year ago

Thanks for opening @avidal!

@joshspicer it'd be great to get your insights on this one.