coder / coder/internal

Devcontainers: option variable resolution specification proposal

Open
#746 1 comment 0 reactions 1 assignee Claimed by @DanielleMaywood View on GitHub
Dominant language
No language data
Stars
3
Forks
0
PR merge metrics
No merged PRs in 30d

Description

## Problem

Whilst implementing `coder_app`s in the `customization` block of a `devcontainer-feature.json`, we realized we were unable to reference `options`. This has required us to create a workaround that involves a bit of magic to get working.

## Workaround

If you had an options block like so for the feature `ghcr.io/coder/devcontainer-features/code-server`:
```json
"options": {
"port": {
"type": "string",
"default": "8080"
}
}
```

Referencing this in the `customizations` section is not possible using the devcontainer spec. We work around this by having Coder read the customizations with a range of environment variables [^features-pr]. We would expose the option above as `FEATURE_CODE_SERVER_OPTION_PORT` [^devcontainer-feature]. Making use of this looks like so:

```json
"customizations": {
"coder": {
"apps": [{
"slug": "code-server",
"url": "http://example.com:${localEnv:FEATURE_CODE_SERVER_OPTION_PORT:8080}"
}]
}
}
```

You can notice that we have to respecify our default value of `8080` as we are unable to grok that knowledge from calling `devcontainer read-configuration`.

## Proposal

We want to request a change to the devcontainer specification that introduces a new environment variable resolution option named `option`. This would be used in a `devcontainer-feature.json`.

Using our previous example, we'd expect the `customizations` block to look like:

```json
"customizations": {
"coder": {
"apps": [{
"slug": "code-server",
"url": "http://example.com:${option:PORT}"
}]
}
}
```

There might be a limitation with how option defaults are currently implemented, but a workaround could be still requiring a fallback value, which would require writing it as `${option:PORT:8080}`.

## Useful links

[^features-pr]: https://github.com/coder/coder/pull/18576

[^devcontainer-feature]: https://github.com/coder/devcontainer-features/blob/137955830d2510ca856c4b2a0375313a337c526a/src/code-server/devcontainer-feature.json#L174-L188

Contributing guide: https://github.com/devcontainers/spec/blob/main/contributing.md

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.