devcontainers / devcontainers/spec

Proposal: `option` variable referencing `${option:optionName}`

Open
#602 1 comment 8 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
5.7k
Forks
496
PR merge metrics
No merged PRs in 30d

Description

## Problem Statement

As part of our devcontainer integration work at [Coder](https://coder.com), 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` [^code-server-options]:

```json
{
"options": {
"port": {
"type": "string",
"default": "8080"
}
}
}
```

We refer to this in the `customizations` sections as [^code-server-customization]:

```json
{
"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__OPTION_` when calling `devcontainer read-configuration` [^feature-envs]. 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}"
}]
}
}
}
```

[^code-server-options]: https://github.com/coder/devcontainer-features/blob/137955830d2510ca856c4b2a0375313a337c526a/src/code-server/devcontainer-feature.json#L113-L117
[^code-server-customization]: https://github.com/coder/devcontainer-features/blob/137955830d2510ca856c4b2a0375313a337c526a/src/code-server/devcontainer-feature.json#L174-L188
[^feature-envs]: https://github.com/coder/coder/pull/18576

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.