microsoft / microsoft/vscode-remote-release

devcontainer.json cannot use exported vars from initializeCommand

Open
#6,983 3 comments 13 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

containers feature-request
Dominant language
Dockerfile
Stars
4.2k
Forks
470
Avg merge
1d 1h
Merged PRs (30d)
1

Description

Version: 1.69.2 (user setup)
Commit: 3b889b090b5ad5793f524b5d1d39fda662b96a2a
Date: 2022-07-18T16:12:52.460Z
Electron: 18.3.5
Chromium: 100.0.4896.160
Node.js: 16.13.2
V8: 10.0.139.17-electron.0
OS: Windows_NT x64 10.0.19044

The initializeCommand is advertised to run as the very first step, but it cannot be used to have any meaningful effect on the devcontainer.json itself. For example none of the following is possible:

  • setting the "name" property from initializeCommand
  • setting the FROM argument of a Dockerfile by passing a build-arg that's exported by initializeCommand
  • changing proxy settings on a user by user basis via initializeCommand
  • changing any setting in the devcontainer.json
  • rolling out docker image version updates without having to tinker with the vscode devcontainer settings

We use several docker images in production and we use them locally by inheriting from them and building a new image with all the user specific things, and run them in a user specific way (proxy, extensions, CCACHE settings, etc).
It'd be nice to keep the devcontainer.json as a generic template and have initializeCommand do whatever it wants and to use these effects in the devcontainer.json. This way we could use scripts to extract image versions, parse various untracked user files for CCACHE configs, etc, so that each user can fine tune the environment without having a dirty working tree.

Steps to Reproduce:

  "name": "${env:DEV_IMAGE_NAME}",
  "build": {
    "dockerfile": "Dockerfile",
    "args": {
      "IMAGE_URL": "${localEnv:DEV_IMAGE_URL}",
      "DOCKER_REGISTRY_URL": "${localEnv:DOCKER_REGISTRY_URL",
      "USERNAME": "${localEnv:USER}",
      "USER_UID": "${localEnv:USER_UID}",
      "USER_GID": "${localEnv:USER_GID}"
    }
  },
  "initializeCommand": "${localWorkspaceFolder}/.devcontainer/initialize-command.sh",

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied devcontainer.json and .devcontainer/initialize-command.sh reproduction, then trace when initializeCommand runs relative to ${env:...} and ${localEnv:...} substitutions and Dockerfile build args. Done means determining whether exported values can affect the name, build arguments, and other devcontainer settings described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, dockerfile, vscode
Domain
developer-experience, devops
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.