-
Notifications
You must be signed in to change notification settings - Fork 340
Description
Problem Statement
As part of our devcontainer integration work at Coder, we make use of the customizations
section in devcontainer.json
and devcontainer-feature.json
. We have discovered a usability issue with referencing feature options inside of a customizations
section. We've had to create a layer of Coder specific magic around this for the moment.
Workaround
Given the following options
block for a feature to be published as ghcr.io/coder/devcontainer-features/code-server
1:
{
"options": {
"port": {
"type": "string",
"default": "8080"
}
}
}
We refer to this in the customizations
sections as 2:
{
"customizations": {
"coder": {
"apps": [{
"slug": "code-server",
"url": "http://example.com:${localEnv:FEATURE_CODE_SERVER_OPTION_PORT:8080}"
}]
}
}
}
Where we populate environment variables in the form FEATURE_<name>_OPTION_<option>
when calling devcontainer read-configuration
3. It is important to note that we do not have access to the default
value in this approach so it has to be specified twice.
Proposal
A new variable resolution approach named option
.
Variable | Properties | Description |
---|---|---|
${option:optionName} |
Any | The value of an option given to the feature. |
Example
Following the example provided before, it would look like this:
{
"options": {
"host": {
"type": "string",
"default": "0.0.0.0"
},
"port": {
"type": "string",
"default": "8080"
}
},
"customizations": {
"coder": {
"apps": [{
"slug": "code-server",
"url": "http://${option:host}:${option:port}"
}]
}
}
}
Footnotes
-
https://github.com/coder/devcontainer-features/blob/137955830d2510ca856c4b2a0375313a337c526a/src/code-server/devcontainer-feature.json#L113-L117 ↩
-
https://github.com/coder/devcontainer-features/blob/137955830d2510ca856c4b2a0375313a337c526a/src/code-server/devcontainer-feature.json#L174-L188 ↩