Skip to content

Update values in devcontainer.json are not respected after the container is created #252

Closed

Description

Version 0.74.0

Updated values, such as remoteEnv in devcontainer.json after the container is created are not respected since the values from the container metadata are taking precedence.

This breaks flows where this values are updated, like secrets, to keep environments working.

The issue appears to be coming from here:

const copy = { ...config };
replaceProperties.forEach(property => delete (copy as any)[property]);
const merged: MergedDevContainerConfig = {
...copy,
init: imageMetadata.some(entry => entry.init),
privileged: imageMetadata.some(entry => entry.privileged),
capAdd: unionOrUndefined(imageMetadata.map(entry => entry.capAdd)),
securityOpt: unionOrUndefined(imageMetadata.map(entry => entry.securityOpt)),
entrypoints: collectOrUndefined(imageMetadata, 'entrypoint'),
mounts: mergeMounts(imageMetadata),
customizations: Object.keys(customizations).length ? customizations : undefined,
onCreateCommands: collectOrUndefined(imageMetadata, 'onCreateCommand'),
updateContentCommands: collectOrUndefined(imageMetadata, 'updateContentCommand'),
postCreateCommands: collectOrUndefined(imageMetadata, 'postCreateCommand'),
postStartCommands: collectOrUndefined(imageMetadata, 'postStartCommand'),
postAttachCommands: collectOrUndefined(imageMetadata, 'postAttachCommand'),
waitFor: reversed.find(entry => entry.waitFor)?.waitFor,
remoteUser: reversed.find(entry => entry.remoteUser)?.remoteUser,
containerUser: reversed.find(entry => entry.containerUser)?.containerUser,
userEnvProbe: reversed.find(entry => entry.userEnvProbe)?.userEnvProbe,
remoteEnv: Object.assign({}, ...imageMetadata.map(entry => entry.remoteEnv)),
containerEnv: Object.assign({}, ...imageMetadata.map(entry => entry.containerEnv)),
overrideCommand: reversed.find(entry => typeof entry.overrideCommand === 'boolean')?.overrideCommand,
portsAttributes: Object.assign({}, ...imageMetadata.map(entry => entry.portsAttributes)),
otherPortsAttributes: reversed.find(entry => entry.otherPortsAttributes)?.otherPortsAttributes,
forwardPorts: mergeForwardPorts(imageMetadata),
shutdownAction: reversed.find(entry => entry.shutdownAction)?.shutdownAction,
updateRemoteUserUID: reversed.find(entry => typeof entry.updateRemoteUserUID === 'boolean')?.updateRemoteUserUID,
hostRequirements: mergeHostRequirements(imageMetadata),
};
return merged;

Activity

  1. added
    candidate
    on Oct 31, 2022
  2. added
    bug
    on Oct 31, 2022
  3. chrmarti commented on Oct 31, 2022

    @chrmarti
    Contributor

    The difficulty here is that imageMetadata has the properties from the initial devcontainer.json as its last entry if our CLI created the container as a dev container (e.g., a non-dev container in Compose could still have metadata entries, other tools might do something different).

    To make sure we don't replace the wrong metadata entry, I suggest we update only the properties that are straight-forward to merge: remoteEnv, remoteUser and userEnvProbe.

    Alternatively we could surface the option --remote-env to allow for adding / overwriting environment variables.

  4. chrmarti commented on Oct 31, 2022

    @chrmarti
    Contributor

    Fixed in 0.262.1-pre-release. To verify in the Dev Containers extension:

    • Create a dev container with a variable in "remoteEnv".
    • Change the variable's value and add another variable.
    • Reload the window.
    • Verify the environment variables are updated in a new terminal (restored terminals won't update their environment).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugcandidateverified

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions