|
| 1 | +--- |
| 2 | +title: "Profiles: Activation" |
| 3 | +sidebar_label: activation |
| 4 | +--- |
| 5 | + |
| 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`. |
| 7 | + |
| 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 |
| 27 | +```yaml {3-5} |
| 28 | +profiles: |
| 29 | +- name: production |
| 30 | + activation: |
| 31 | + - env: |
| 32 | + ENV: "production" |
| 33 | + patches: |
| 34 | + - op: replace |
| 35 | + path: images.backend.image |
| 36 | + value: john/prodbackend |
| 37 | +``` |
| 38 | +The `production` profile would be activated when the environment variable `ENV` has value `production`: |
| 39 | + |
| 40 | +#### Example: Regular Expression Activation |
| 41 | +```yaml {3-5} |
| 42 | +profiles: |
| 43 | +- name: production |
| 44 | + activation: |
| 45 | + - env: |
| 46 | + ENV: "prod-\d+" |
| 47 | + patches: |
| 48 | + - op: replace |
| 49 | + path: images.backend.image |
| 50 | + value: john/prodbackend |
| 51 | +``` |
| 52 | +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. |
| 53 | + |
| 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} |
| 57 | +profiles: |
| 58 | +- name: production |
| 59 | + activation: |
| 60 | + - env: |
| 61 | + CI: "true" |
| 62 | + vars: |
| 63 | + ENV: "development" |
| 64 | + patches: |
| 65 | + - op: replace |
| 66 | + path: images.backend.image |
| 67 | + value: john/devbackend |
| 68 | +``` |
| 69 | + |
| 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: |
| 76 | +```yaml {3-7} |
| 77 | +profiles: |
| 78 | +- name: production |
| 79 | + activation: |
| 80 | + - env: |
| 81 | + CI: "true" |
| 82 | + - vars: |
| 83 | + ENV: "development" |
| 84 | + patches: |
| 85 | + - op: replace |
| 86 | + path: images.backend.image |
| 87 | + value: john/devbackend |
| 88 | +``` |
| 89 | + |
| 90 | +### Dependency Activations |
| 91 | +When `dependencies` are referenced from a `devspace.yaml`, the dependency's profile activations will also be evaluated. In this example, any profile activations in `./component-1/devspace.yaml` or `./component-2/devspace.yaml` would be evaluated. |
| 92 | + |
| 93 | +```yaml |
| 94 | +dependencies: |
| 95 | +- name: component-1 |
| 96 | + source: |
| 97 | + path: ./component-1 |
| 98 | +- name: component-2 |
| 99 | + source: |
| 100 | + path: ./component-2 |
| 101 | +``` |
| 102 | + |
| 103 | +#### Example: Disable Activations by Dependency |
| 104 | +The `disableProfileActivation` option can be used to disable profile activations for specific dependencies. In the following example, the activations for `./component-1/devspace.yaml` would be ignored, while the activations in `./component-2/devspace.yaml` would be evaluated: |
| 105 | +```yaml {5} |
| 106 | +dependencies: |
| 107 | +- name: component-1 |
| 108 | + source: |
| 109 | + path: ./component-1 |
| 110 | + disableProfileActivation: true |
| 111 | +- name: component-2 |
| 112 | + source: |
| 113 | + path: ./component-2 |
| 114 | +``` |
| 115 | + |
| 116 | +### Disable Activations Globally |
| 117 | +The `--disable-profile-activation` flag can be used to disable all profile activations, including those specifed within each dependency's `devspace.yaml`. |
0 commit comments