Duplication while merging lifecycle commands?
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.
Thanks for opening @avidal!
@joshspicer it'd be great to get your insights on this one.
I know I'm late to the party here, but I'll chime in and mention that I'm seeing this as well. It's especially bad in my case because I've got pre-built devcontainer images based on other pre-built images multiple times on top of features that dependOn other features.
This lack of feature label deduplication in prebuilding devcontainer images kind of makes using dependsOn in features not really feasible... you end up in situations like this upon opening a downstream, prebuilt devcontainer image + using features that dependOn other features:
Running the postCreateCommand from Feature 'ghcr.io/devopsbuildingblocks/devcontainer-features/common-utils:0'...
[14801 ms] Start: Run in container: /bin/sh -c common-utils-postCreateCommand.sh
What's next:
Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug 5752880cb1e3c7d0ec97c5c4bac52a61dc21f164bbc08ba698d3dda802747d88
Learn more at https://docs.docker.com/go/debug-cli/
Running the postCreateCommand from Feature 'ghcr.io/devopsbuildingblocks/devcontainer-features/common-utils:0'...
[15105 ms] Start: Run in container: /bin/sh -c common-utils-postCreateCommand.sh
What's next:
Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug 5752880cb1e3c7d0ec97c5c4bac52a61dc21f164bbc08ba698d3dda802747d88
Learn more at https://docs.docker.com/go/debug-cli/
Running the postCreateCommand from Feature 'ghcr.io/devopsbuildingblocks/devcontainer-features/devbox:0'...
[15249 ms] Start: Run in container: /bin/sh -c devbox-postCreateCommand.sh
Found existing devbox.json, running devbox install...
Finished installing packages.
What's next:
Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug 5752880cb1e3c7d0ec97c5c4bac52a61dc21f164bbc08ba698d3dda802747d88
Learn more at https://docs.docker.com/go/debug-cli/
Running the postCreateCommand from Feature 'ghcr.io/devopsbuildingblocks/devcontainer-features/common-utils:0'...
[15486 ms] Start: Run in container: /bin/sh -c common-utils-postCreateCommand.sh
What's next:
Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug 5752880cb1e3c7d0ec97c5c4bac52a61dc21f164bbc08ba698d3dda802747d88
Learn more at https://docs.docker.com/go/debug-cli/
Running the postCreateCommand from Feature 'ghcr.io/devopsbuildingblocks/devcontainer-features/devbox:0'...
[15661 ms] Start: Run in container: /bin/sh -c devbox-postCreateCommand.sh
Found existing devbox.json, running devbox install...
Finished installing packages.
What's next:
Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug 5752880cb1e3c7d0ec97c5c4bac52a61dc21f164bbc08ba698d3dda802747d88
Learn more at https://docs.docker.com/go/debug-cli/
Running the postCreateCommand from Feature 'ghcr.io/devopsbuildingblocks/devcontainer-features/common-utils:0'...
[15896 ms] Start: Run in container: /bin/sh -c common-utils-postCreateCommand.sh
What's next:
Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug 5752880cb1e3c7d0ec97c5c4bac52a61dc21f164bbc08ba698d3dda802747d88
Learn more at https://docs.docker.com/go/debug-cli/
Running the postCreateCommand from Feature 'ghcr.io/devopsbuildingblocks/devcontainer-features/devbox:0'...
[16065 ms] Start: Run in container: /bin/sh -c devbox-postCreateCommand.sh
Found existing devbox.json, running devbox install...
Finished installing packages.
What's next:
Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug 5752880cb1e3c7d0ec97c5c4bac52a61dc21f164bbc08ba698d3dda802747d88
Learn more at https://docs.docker.com/go/debug-cli/
Running the postCreateCommand from Feature 'ghcr.io/devopsbuildingblocks/devcontainer-features/claude:0'...
[16324 ms] Start: Run in container: /bin/sh -c claude-postCreateCommand.sh
I'll describe how the above happens:
| Images | Features |
|---|---|
| ubuntu-base | common-utils -dependsOn-> lib |
| ubuntu-devbox -based on-> ubuntu-base | devbox -> common-utils -> lib |
| ubuntu-toolbox -> ubuntu-devbox | claude -> devbox -> common-utils -> lib |
So what does all of this mean for anyone that wants to maintain even a remotely complex library of features/pre-built devcontainer images? Shy away from using dependsOn in favor of using installsAfter; however, this is unfortunate for anyone that simply wants to drop in a downstream feature to their existing devcontainer.json without needing to worry about it's entire dependency graph. In the situation I described above... to remove the deduplication in my ubuntu-toolbox devcontainer image, I have to remove the dependsOn from all of the features listed in that row... but doing so means that if a user simply wants to add my claude feature to their own image (that doesn't bake the upstream features into), they now have to know that they also need the devbox (and nix, but I didn't share that), common-utils, and lib features.