Skip to content

[.gitpod.yml] Introduce top-level env #20339

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
merged 2 commits into from
Nov 5, 2024
Merged

Conversation

filiptronicek
Copy link
Member

@filiptronicek filiptronicek commented Nov 1, 2024

Description

The .gitpod.yml spec has not changed for more than 2 years! Let's break the streak.

This PR introduces the top-level env keyword to the .gitpod.yml file, defining key-value pairs of environment variables that ought to be available on workspaces created from it.

Here is an example:

image: gitpod/workspace-full

env:
  BOND: "007"

Simple enough. The funny part comes when you try to plug this approach into our existing approaches for setting environment variables.

graph TD
    A["Environment Variable Overriding in Gitpod Workspaces"] 
    A --> |"1 (Highest Priority)"| B[".gitpod.yml[tasks][n][env]"]
    B --> |"2"| C["Environment variables passed via the context URL"]
    C --> |"3"| D["Repository-specific environment variables"]
    D --> |"4"| E["User-specific environment variables"]
    E --> |"5 (this PR's addition)"| F[".gitpod.yml[env]"]
    F --> |"6 (Lowest Priority)"| G["Image's environment variables (e.g., ENV in Dockerfile)"]
    
    style A fill:#f9f9f9,stroke:#333,stroke-width:2px;
    style B fill:#f2f2f2,stroke:#3a86ff,stroke-width:2px;
    style C fill:#f2f2f2,stroke:#8338ec,stroke-width:2px;
    style D fill:#f2f2f2,stroke:#ff006e,stroke-width:2px;
    style E fill:#f2f2f2,stroke:#fb5607,stroke-width:2px;
    style F fill:#f2f2f2,stroke:#ffbe0b,stroke-width:2px;
    style G fill:#f2f2f2,stroke:#00a676,stroke-width:2px;
Loading

Related Issue(s)

Fixes CLC-874

How to test

  1. You can try starting a workspace in the preview environment based off of https://github.com/filiptronicek/test-foofies/blob/ft/envvars/.gitpod.yml.
  2. You should see $VAR populated with a value in the resulting workspace

This PR also updates tests

Documentation

Yes it does. Documentation in https://github.com/gitpod-io/website/pull/4942

@geropl
Copy link
Member

geropl commented Nov 4, 2024

Thank you @filiptronicek for the thoughtful change, the diagram and the superb description. ✨

I got the two questions above, and would love to quickly talk through it; happy to ✔️ right after.

Copy link
Member

@geropl geropl left a comment

Choose a reason for hiding this comment

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

Code LGTM, tests are green and works! ✔️

@filiptronicek
Copy link
Member Author

> gitpod /workspace/test-foofies (ft/envvars) $ echo $VAR
userr

It works!

@filiptronicek filiptronicek self-assigned this Nov 5, 2024
@roboquat roboquat merged commit 18b92d8 into main Nov 5, 2024
17 checks passed
@roboquat roboquat deleted the ft/gitpod-yml-env-field branch November 5, 2024 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants