devcontainers / devcontainers/spec

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

Aperta
#602 1 commento 8 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Nessun dato sulla lingua
Stelle
5.7k
Fork
496
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

## 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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia con gli esempi di devcontainer.json e devcontainer-feature.json, quindi esamina il comportamento di risoluzione delle variabili utilizzato da `devcontainer read-configuration`. Il lavoro è completato quando `${option:optionName}` viene risolto nel valore dell'opzione della feature, incluso il suo valore predefinito, all'interno della sezione customizations di una feature.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Ambito
devops
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.