Skip to content

Commit c763054

Browse files
authored
Merge pull request #1808 from lizardruss/profile-expressions
feat: allow variables and expression in profiles
2 parents ba2fc6c + 13f9dab commit c763054

File tree

34 files changed

+2299
-212
lines changed

34 files changed

+2299
-212
lines changed

docs/pages/configuration/expressions.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,17 @@ Expressions are run in a golang shell that is syntax compatible to a regular POS
129129
Variables are resolved before and after applying expressions, which means that you can load a section from file within an expression that contains a variable which will still be resolved afterwards.
130130
:::
131131

132+
:::warning Unsupported Config Expressions
133+
Expressions are not supported in these configuration properties:
134+
- `vars`
135+
- `profiles[*].name`
136+
- `profiles[*].parent`
137+
- `profiles[*].parents`
138+
- `profiles[*].activations`
139+
- `profiles[*].patches[*].op`
140+
- `profiles[*].patches[*].path`
141+
:::
142+
132143
### Testing Config Expressions
133144

134145
The command `devspace print` can be used to test your config expressions and shows the config after all profiles, variables and expressions were applied.

docs/pages/configuration/profiles/activation.mdx

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,27 @@ title: "Profiles: Activation"
33
sidebar_label: activation
44
---
55

6-
The `activation` option is optional and allows you to activate a profile using regular expression matching of environment variables. An activation is configured with the profile it activates in `devspace.yaml`.
6+
The `activation` option is optional and allows you to activate a profile using regular expression matching of either Devspace or environment variables. An activation is configured with the profile it activates in `devspace.yaml`.
77

8-
#### Example: Defining a Profile Activation
8+
9+
#### Example: Defining a Profile Activation using `vars`
10+
```yaml {1-3,7-8}
11+
vars:
12+
- name: ENV
13+
default: development
14+
profiles:
15+
- name: production
16+
activation:
17+
- vars:
18+
ENV: production
19+
patches:
20+
- op: replace
21+
path: images.backend.image
22+
value: john/prodbackend
23+
```
24+
The `production` profile would be activated when the Devspace variable `ENV` has value `production`. In this example, it has a default value of `development`, so it is not activated unless you override the value using `--var ENV=production`
25+
26+
#### Example: Defining a Profile Activation using Environment Variables
927
```yaml {3-5}
1028
profiles:
1129
- name: production
@@ -33,30 +51,35 @@ profiles:
3351
```
3452
The profile `production` would be activated when the environment variable `ENV` matches the regular expression `prod-\d+`. This can be useful for matching environment variables that have dynamic values. Regular expressions will have start of string (`^`) and end of string (`$`) anchors added automatically to avoid unexpected substring matching.
3553

36-
#### Example: Matching All Environment Variables
37-
When multiple `env` name/expression pairs are specified in the same activation, all environment variables values must match the expression to activate the profile. For example, the `production` profile is activated when both environment variables match their expressions:
38-
```yaml {3-6}
54+
#### Example: Matching All
55+
When multiple `env` or `vars` name/expression pairs are specified in the same activation, all expressions must match to activate the profile. For example, the `production` profile is activated when the environment variable `CI` is `true` and the Devspace variable `ENV` is `development`:
56+
```yaml {3-7}
3957
profiles:
4058
- name: production
4159
activation:
4260
- env:
4361
CI: "true"
62+
vars:
4463
ENV: "development"
4564
patches:
4665
- op: replace
4766
path: images.backend.image
4867
value: john/devbackend
4968
```
5069

51-
#### Example: Matching Any Environment Variables
52-
When environment variables are used in multiple activations, the profile is activated when any environment variable matches. In this example, the `production` profile is activated when either environment variables match their expressions:
70+
:::note Combining `env` and `vars`
71+
While possible to activate profiles using environment variables and Devspace variables, `vars` can also be populated through environment variables. In the above example, we could have also defined `CI` as a Devspace variable with `source: env` and only used `vars` in the activation.
72+
:::
73+
74+
#### Example: Matching Any
75+
When `env` or `vars` are used in multiple activations, the profile is activated when any expression matches. In this example, the `production` profile is activated when either match their expressions:
5376
```yaml {3-7}
5477
profiles:
5578
- name: production
5679
activation:
5780
- env:
5881
CI: "true"
59-
- env:
82+
- vars:
6083
ENV: "development"
6184
patches:
6285
- op: replace

0 commit comments

Comments
 (0)