skip to Main Content

I’m currently using container environment variables (exported by my docker-entrypoint.sh) to configure Visual Studio Code settings and it works perfectly with string values:

{
    "intelephense.environment.phpVersion": "${containerEnv:PHP_VERSION}",
}

However, when the values must be of type number or boolean, an issue arises (DB_ASK_PASSWORD contains either true or false). In fact, I’m forced to wrap the value into double quotes, producing an invalid number or boolean:

{
    "sqltools.connections": [
        {
          "port": "${containerEnv:DB_HOST}",
          "askForPassword": "${containerEnv:DB_ASK_PASSWORD}"
        }
    ]
}

Even if, in this specific case, port could work (for internal type conversion), askForPassword cannot. Being wrapped by double quotes, the "false" text is interpreted as as truthy value.

Is there any way to accomplish what I’m asking? Removing the quotes does not help either:

{
    "sqltools.connections": [
        {
          "askForPassword": ${containerEnv:DB_ASK_PASSWORD}
        }
    ]
}

2

Answers


  1. Settings do not support variables automatically, the extension using the setting has to implement variables.

    Most likely intelephense does support the ${containerEnv} variable and sqltools does not.

    Login or Signup to reply.
  2. You can create a file called devcontainer.env in your .devcontainer folder, and put your variables there:

    DB_HOST=3306
    DB_ASK_PASSWORD=false
    

    Then, in your devcontainer.json file, you can add this line:

    "envFile": ".devcontainer/devcontainer.env"
    

    To learn more about this, see https://code.visualstudio.com/remote/advancedcontainers/environment-variables

    I hope this helps you configure your Visual Studio Code settings.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search