|
| 1 | +--- |
| 2 | +title: Runtime Variables |
| 3 | +sidebar_label: ${runtime.variables} |
| 4 | +--- |
| 5 | + |
| 6 | +import Tabs from '@theme/Tabs'; |
| 7 | +import TabItem from '@theme/TabItem'; |
| 8 | + |
| 9 | +Runtime variables are special variables that are only available in certain config areas and are filled during runtime. Those variables are useful to access certain runtime information, such as hook output or image tags. |
| 10 | + |
| 11 | +<Tabs |
| 12 | +defaultValue="var1" |
| 13 | +values={[ |
| 14 | + { label: 'Separate Repo & Tag', value: 'var1', }, |
| 15 | + { label: 'Customize Helm Values', value: 'var2', }, |
| 16 | + { label: 'Customize Kubernetes Manifests', value: 'var3', }, |
| 17 | + { label: 'Dependency', value: 'var4', }, |
| 18 | +] |
| 19 | +}> |
| 20 | +<TabItem value="var1"> |
| 21 | + |
| 22 | +```yaml |
| 23 | +images: |
| 24 | + app: |
| 25 | + image: registry.url/repo/image |
| 26 | +deployments: |
| 27 | + backend: |
| 28 | + helm: |
| 29 | + chart: |
| 30 | + name: chart-name |
| 31 | + repo: https://my-charts.company.tld/ |
| 32 | + values: |
| 33 | + # If registry.url/repo/image was found under images as well, will be |
| 34 | + # rewritten to registry.url/repo/image:generated_tag |
| 35 | + imageWithTag: registry.url/repo/image |
| 36 | + # If registry.url/repo/image was found under images.app as well, will be |
| 37 | + # rewritten to registry.url/repo/image |
| 38 | + imageWithoutTag: ${runtime.images.app.image} |
| 39 | + # If registry.url/repo/image was found under images.app as well, will be |
| 40 | + # rewritten to generated_tag |
| 41 | + onlyTag: ${runtime.images.app.tag} |
| 42 | +``` |
| 43 | +
|
| 44 | +</TabItem> |
| 45 | +<TabItem value="var2"> |
| 46 | +
|
| 47 | +```yaml |
| 48 | +images: |
| 49 | + app: |
| 50 | + image: myuser/image |
| 51 | +hooks: |
| 52 | + - name: "image-digest" |
| 53 | + events: ["after:build:app"] |
| 54 | + command: | |
| 55 | + # This command prints the image digest |
| 56 | + echo $(docker inspect ${runtime.images.app.image}:${runtime.images.app.tag} --format='{{index .RepoDigests 0}}' | cut -d'@' -f2) |
| 57 | +deployments: |
| 58 | + checkout: |
| 59 | + helm: |
| 60 | + chart: |
| 61 | + name: ./kubernetes/helm/app |
| 62 | + values: |
| 63 | + app: |
| 64 | + image: |
| 65 | + digest: ${runtime.hooks.image-digest.stdout} |
| 66 | +``` |
| 67 | +
|
| 68 | +</TabItem> |
| 69 | +<TabItem value="var3"> |
| 70 | +
|
| 71 | +```yaml |
| 72 | + |
| 73 | +images: |
| 74 | + your-image: |
| 75 | + image: localhost:5000/my/customalpine |
| 76 | + kaniko: |
| 77 | + insecure: true |
| 78 | + skipPullSecretMount: true |
| 79 | + |
| 80 | +deployments: |
| 81 | + quickstart: |
| 82 | + kubectl: |
| 83 | + inlineManifest: |- |
| 84 | + kind: Deployment |
| 85 | + apiVersion: apps/v1 |
| 86 | + metadata: |
| 87 | + name: devspace |
| 88 | + spec: |
| 89 | + replicas: 1 |
| 90 | + selector: |
| 91 | + matchLabels: |
| 92 | + app.kubernetes.io/component: default |
| 93 | + app.kubernetes.io/name: devspace-app |
| 94 | + template: |
| 95 | + metadata: |
| 96 | + labels: |
| 97 | + app.kubernetes.io/component: default |
| 98 | + app.kubernetes.io/name: devspace-app |
| 99 | + spec: |
| 100 | + containers: |
| 101 | + - name: default |
| 102 | + # The correct image tag will be inserted during devspace dev / devspace deploy |
| 103 | + image: ${runtime.images.your-image} |
| 104 | +
|
| 105 | +``` |
| 106 | +
|
| 107 | +</TabItem> |
| 108 | +<TabItem value="var4"> |
| 109 | +
|
| 110 | +```yaml |
| 111 | +dependencies: |
| 112 | + dep1: |
| 113 | + source: |
| 114 | + path: dep1 |
| 115 | +dev: |
| 116 | + my-dev: |
| 117 | + imageSelector: ${runtime.dependencies.dep1.images.image1} |
| 118 | + terminal: {} |
| 119 | +``` |
| 120 | +
|
| 121 | +</TabItem> |
| 122 | +</Tabs> |
| 123 | + |
| 124 | +Runtime variables can be used in the following DevSpace config sections: |
| 125 | +
|
| 126 | +``` |
| 127 | +/images/*/build/custom/command |
| 128 | +/images/*/build/custom/commands/*/command |
| 129 | +/images/*/build/custom/args/** |
| 130 | +/images/*/build/custom/appendArgs/** |
| 131 | +/deployments/*/helm/values/** |
| 132 | +/deployments/*/kubectl/inlineManifest/** |
| 133 | +/hooks/*/command |
| 134 | +/hooks/*/args/* |
| 135 | +/hooks/*/container/imageSelector |
| 136 | +/dev/*/imageSelector |
| 137 | +/dev/*/replaceImage |
| 138 | +/dev/*/devImage |
| 139 | +/dev/*/containers/*/replaceImage |
| 140 | +/dev/*/containers/*/devImage |
| 141 | +/pipelines/* |
| 142 | +/pipelines/*/flags/** |
| 143 | +/pipelines/*/run |
| 144 | +/commands/* |
| 145 | +/commands/*/command |
| 146 | +/functions/** |
| 147 | +/imports/** |
| 148 | +``` |
| 149 | + |
| 150 | +:::info |
| 151 | +If you try to use a runtime variable in a different config section, DevSpace will print an error and fail. |
| 152 | +::: |
| 153 | + |
| 154 | +The following runtime variables exist: |
| 155 | + |
| 156 | +- **`runtime.images.IMAGE_NAME`**: Holds the image name (defined at `images.*.image`) and tag that was built by DevSpace (e.g. `my-repo.com/image:latest`) |
| 157 | +- **`runtime.images.IMAGE_NAME.tag`**: Holds the image tag that was built by DevSpace (e.g. `asdHTR` or `latest`) |
| 158 | +- **`runtime.images.IMAGE_NAME.image`**: Holds the image name (defined at `images.*.image`) that was used for building (e.g. `my-repo.com/image`) |
| 159 | + |
| 160 | +## Accessing runtime variables of dependencies |
| 161 | + |
| 162 | +You can also access runtime variables of an executed dependency by using `runtime.dependencies.DEPENDENCY_NAME...`. |
| 163 | + |
| 164 | +For example: |
| 165 | +```yaml |
| 166 | +dependencies: |
| 167 | + dep1: |
| 168 | + source: |
| 169 | + path: dep1 |
| 170 | +dev: |
| 171 | + my-dev: |
| 172 | + imageSelector: ${runtime.dependencies.dep1.images.image1} |
| 173 | + terminal: {} |
| 174 | +``` |
0 commit comments