Skip to content

Commit 29bf48a

Browse files
committed
docs: add back runtime variables page from 5.x. Fix ENG-878
Signed-off-by: Luca Di Maio <luca.dimaio1@gmail.com>
1 parent 567e7aa commit 29bf48a

7 files changed

Lines changed: 191 additions & 14 deletions

File tree

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
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+
```

docs/sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ module.exports = {
171171
'configuration/localRegistry/README',
172172
'configuration/require/README',
173173
'configuration/variables',
174+
'configuration/runtime-variables',
174175
'configuration/expressions',
175176
],
176177
},

pkg/devspace/analyze/analyze_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ type createReportTestCase struct {
6464
expectedReport []*ReportItem
6565
}
6666

67-
/*Part of this function is untestable right now because the helper function events uses the RestClient of the KubeClient.
68-
The fake client returns nil. Therefore it's not possible to let events return problems.*/
67+
/*
68+
Part of this function is untestable right now because the helper function events uses the RestClient of the KubeClient.
69+
The fake client returns nil. Therefore it's not possible to let events return problems.
70+
*/
6971
func TestCreateReport(t *testing.T) {
7072
testCases := []createReportTestCase{
7173
{

pkg/devspace/config/loader/variable/runtime/runtime_variable.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var Locations = []string{
1717
"/images/*/build/custom/args/**",
1818
"/images/*/build/custom/appendArgs/**",
1919
"/deployments/*/helm/values/**",
20+
"/deployments/*/kubectl/inlineManifest/**",
2021
"/hooks/*/command",
2122
"/hooks/*/args/*",
2223
"/hooks/*/container/imageSelector",

pkg/devspace/config/versions/v1beta11/schema.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ type ChartConfig struct {
671671
Git *GitSource `yaml:"git,omitempty" json:"git,omitempty"`
672672
}
673673

674-
//GitSource defines the git repository options
674+
// GitSource defines the git repository options
675675
type GitSource struct {
676676
URL string `yaml:"url,omitempty" json:"url,omitempty"`
677677
CloneArgs []string `yaml:"cloneArgs,omitempty" json:"cloneArgs,omitempty"`

pkg/devspace/kubectl/portforward/portforward.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ type ForwardedPort struct {
6565
}
6666

6767
/*
68-
valid port specifications:
68+
valid port specifications:
6969
70-
5000
71-
- forwards from localhost:5000 to pod:5000
70+
5000
71+
- forwards from localhost:5000 to pod:5000
7272
73-
8888:5000
74-
- forwards from localhost:8888 to pod:5000
73+
8888:5000
74+
- forwards from localhost:8888 to pod:5000
7575
76-
0:5000
77-
:5000
78-
- selects a random available local port,
79-
forwards from localhost:<random port> to pod:5000
76+
0:5000
77+
:5000
78+
- selects a random available local port,
79+
forwards from localhost:<random port> to pod:5000
8080
*/
8181
func ParsePorts(ports []string) ([]ForwardedPort, error) {
8282
var forwards []ForwardedPort

pkg/util/tomb/tomb.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@
5858
//
5959
// For background and a detailed example, see the following blog post:
6060
//
61-
// http://blog.labix.org/2011/10/09/death-of-goroutines-under-control
62-
//
61+
// http://blog.labix.org/2011/10/09/death-of-goroutines-under-control
6362
package tomb
6463

6564
import (

0 commit comments

Comments
 (0)