Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(agent/agentcontainers): add feature options as envs #18576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

mafredri
Copy link
Member

@mafredri mafredri commented Jun 25, 2025

Since devcontainer-feature.json does not support referencing options anywhere outside the feature installation, especially within the JSON itself, this change implements a work-around by defining environment variables based on the feature options that we can use in our features.

This allows us to define a dynamic URL for e.g. the code-server feature.

@mafredri mafredri requested review from johnstcn and DanielleMaywood and removed request for johnstcn June 25, 2025 14:14
@mafredri mafredri marked this pull request as ready for review June 25, 2025 14:14
Comment on lines 41 to 52
// OptionsAsEnvs converts the DevcontainerFeatures into a list of
// environment variables that can be used to set feature options.
// The format is FEATURE_<FEATURE_NAME>_<OPTION_NAME>=<value>.
// For example, if the feature is:
//
// "ghcr.io/coder/devcontainer-features/code-server:1": {
// "port": 9090,
// }
//
// It will produce:
//
// FEATURE_CODE_SERVER_PORT=9090
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can foresee an issue potentially arising with this approach.

"go": {
  "server-port": 9090
},
"go-server": {
  "port": 9091
}

Would both produce FEATURE_GO_SERVER_PORT but they have different values

Copy link
Member

@johnstcn johnstcn Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah we might want something like FEATURE__GO_SERVER__PORT / FEATURE__GO__SERVER_PORT

edit: jinx 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call-out, not sure how we should fix though. Use __ as separator? Include the :1 as _1?

Copy link
Contributor

@DanielleMaywood DanielleMaywood Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think __ could work as a separator, it might still have the same issue if people want to double up on their - but I think that is unlikely.

Copy link
Member Author

@mafredri mafredri Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems we had the same idea @johnstcn, let's go with __ although using _OPTION_ might also work. Like FEATURE_GO_SERVER_OPTION_PORT. The risk of collision is so small that if it does happen, somebody can think about why they chose to call an option option.

Copy link
Member

@johnstcn johnstcn Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think double-underscore separator should work fine.

edit: jinx again, but I do like your OPTION_OPTION as well!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless you guys are greatly opposed I'd actually like to go with the _OPTION_ approach. Seems more human friendly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mafredri I prefer your suggestion, go with _OPTION_.

@mafredri mafredri enabled auto-merge (squash) June 25, 2025 14:39
@mafredri mafredri merged commit 3c4d920 into main Jun 25, 2025
38 checks passed
@mafredri mafredri deleted the mafredri/feat-agent-agentcontainers-add-feature-options-as-env branch June 25, 2025 14:41
@github-actions github-actions bot locked and limited conversation to collaborators Jun 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants