cli icon indicating copy to clipboard operation
cli copied to clipboard

`features` and Dockerfile `ARG` values should be able to share arguments through the config

Open joshspicer opened this issue 3 years ago • 5 comments

@samruddhikhandale has run into a problem where she wants to be able to share configuration arguments in both the build's Dockerfile, and inside of a feature's install script.

One idea I have for this, is that we automatically expose the build.arg arguments in the devcontainer.json to all feature script.

Eg:

{
   "build": {
      {
        "dockerfile": "./Dockerfile"
        "args": {
           "MY_USERNAME": "josh"
         }
   },
    "features": {
       "/features/go": "latest",
       "/features/java": "latest"
     }
}

/features/go/install.sh

#!/bin/bash
...
echo $MY_USERNAME
...

/features/java/install.sh

#!/bin/bash
...
echo $MY_USERNAME
...

./Dockerfile

ARG MY_USERNAME=adam
RUN echo ${MY_USERNAME}

Another idea is moving the "args" property to the top-level, to indicate they arguments should be shared with other customizations, etc that come along.

joshspicer avatar May 11 '22 19:05 joshspicer

Could you link to the relevant code? My initial thought is that features should be self-contained and not access build arguments provided for the user's Dockerfile. Could the feature add an option for itself?

chrmarti avatar May 20 '22 13:05 chrmarti

USERNAME was the main argument needed, while building the image with multiple features. Adding that as an option to the feature could work, we are already doing that for the common feature.

@joshspicer any other thoughts?

samruddhikhandale avatar May 20 '22 16:05 samruddhikhandale

Yea, this is something @samruddhikhandale has found a need for (in some way or another). I imagine this could be useful for an organization where they have n features that all need certain options available in all their features.

joshspicer avatar May 20 '22 18:05 joshspicer

Not sure what you need the USERNAME for, but it might make sense to just loop over all regular users and apply it for all. Oftentimes there will be only one, but that approach has the nice side-effect of also working with multiple user accounts.

chrmarti avatar May 23 '22 08:05 chrmarti

For this particular one we could standarize on adding environment variables before features are built that represent containerUser and remoteUser.

If this case ends up being commong it could be useful for all features.

edgonmsft avatar May 23 '22 16:05 edgonmsft

We added _REMOTE_USER.

chrmarti avatar Dec 14 '23 16:12 chrmarti