-
Notifications
You must be signed in to change notification settings - Fork 167
/
zarf.yaml
236 lines (218 loc) · 9.46 KB
/
zarf.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
kind: ZarfPackageConfig
metadata:
name: component-actions
description: Component actions examples
variables:
- name: DOG_SOUND
default: ruff
# See the example README.md in this folder or /adrs/0010-scripts-actions.md for more info.
components:
- name: on-create
actions:
# runs during "zarf package create"
onCreate:
# defaults are applied to all actions in this action set - below are the default defaults
defaults:
dir: ""
env: []
maxRetries: 0
maxTotalSeconds: 300
mute: false
shell:
darwin: sh
linux: sh
windows: powershell
# runs before the component is created
before:
# on Windows with `pwsh` or `powershell`, `touch` is replaced with New-Item
- cmd: touch test-create-before.txt
# description shows a more user friendly message when waiting for the command
description: Create a test file
# dir is the directory to run the command in
dir: ""
# env sets environment variables for this action only
env:
- thing=stuff
# maxRetries is the number of times to retry the action if it fails
maxRetries: 0
# maxTotalSeconds is the maximum amount of times the action can run before it is killed, over all retries
maxTotalSeconds: 30
# mute determine if actions output should be printed to the console
mute: false
# shell sets the preferred shell across operating systems, in this case "pwsh" instead of "powershell" on Windows
shell:
windows: pwsh
# runs after the component is created
after:
# actions in a list run in order
- cmd: touch test-create-after.txt
- cmd: sleep 0.5
- cmd: echo "I can print!"
- cmd: sleep 0.5
# cmd actions can also specify a multiline string to run like a script
- cmd: |
echo "multiline!"
sleep 0.5
echo "updates!"
sleep 1
echo "in!"
sleep 0.5
echo "realtime!"
sleep 0.5
- name: on-deploy-and-remove
actions:
# runs during "zarf package deploy"
onDeploy:
# runs before the component is deployed
before:
- cmd: touch test-deploy-before.txt
# runs after the component is deployed
after:
- cmd: touch test-deploy-after.txt
# runs during "zarf package remove"
onRemove:
# runs before anything else from the component is removed
before:
- cmd: rm test-deploy-before.txt
# runs after everything else from the component is removed
after:
- cmd: rm test-deploy-after.txt
- name: on-deploy-with-variable
actions:
# runs during "zarf package deploy"
onDeploy:
# runs before the component is deployed
before:
- cmd: echo "the dog says ${ZARF_VAR_DOG_SOUND}"
- name: on-deploy-with-dynamic-variable
actions:
# runs during "zarf package deploy"
onDeploy:
# runs before the component is deployed
before:
# setVariables can be used to set a variable for use in other actions or components
- cmd: echo "meow"
# the name of the variable to set with the output of the action (only useable onDeploy)
setVariables:
- name: CAT_SOUND
# this action will have access to the variable set in the previous action
- cmd: echo "the cat says ${ZARF_VAR_CAT_SOUND}"
- name: on-deploy-with-multiple-variables
actions:
# runs during "zarf package deploy"
onDeploy:
# runs before the component is deployed
before:
# setting this variable will allow it to be used in other actions with additional variables
# set in other actions or components
- cmd: echo "hiss"
# setVariables defines a list of variables to set from the `cmd` standard out.
setVariables:
- name: SNAKE_SOUND
# marks this variable as sensitive to prevent it from being output in the Zarf log
sensitive: true
# autoIndent tells Zarf to maintain spacing for any newlines when templating into a yaml file
autoIndent: true
# onSuccess will only run if steps in this component are successful
onSuccess:
# this action will print the CAT_SOUND variable that was set in a previous component
- cmd: echo "the cat says ${ZARF_VAR_CAT_SOUND}"
# this action will print the DOG_SOUND variable set at the top of the zarf.yaml file
- cmd: echo "the dog says ${ZARF_VAR_DOG_SOUND}"
# this action will print the SNAKE_SOUND variable set within this component
# > NOTE: when including a variable in a command output this will be written to the log regardless of the sensitive setting
# - use `mute` if you want to silence the command output for sensitive variables
- cmd: echo "the snake says ${ZARF_VAR_SNAKE_SOUND}"
# variables are also exposed as TF_VAR_name for terraform, note the lowercase variable name
- cmd: echo "with a TF_VAR, the snake also says ${TF_VAR_snake_sound}"
- name: on-deploy-with-template-use-of-variable
files:
# this file will be copied to the target location and the cat, dog, and snake sounds will be replaced with their values
# requires the on-deploy-with-dynamic-variable and on-deploy-with-multiple-variables components
- source: test.txt
target: test-templated.txt
shasum: 3c0404e0c767ace905c361fadded6c4b91fdb88aa07d5c42d2a220a87564836d
- name: on-deploy-with-timeout
description: This component will fail after 1 second
actions:
# runs during "zarf package deploy"
onDeploy:
# defaults allow you to specify default values for the actions in that actionSet
defaults:
# maxTotalSeconds is the maximum amount of time the action can run before it is killed, over all retries
maxTotalSeconds: 1
before:
# this action will fail after 1 second
- cmd: sleep 10
onFailure:
- cmd: echo "😭😭😭 this action failed because it took too long to run 😭😭😭"
- name: on-remove
# A manifest that we expect to be removed by Zarf
manifests:
- name: test-configmap
files:
- test-configmap.yaml
actions:
# runs during "zarf package remove"
onRemove:
before:
# because this runs before the manifest is removed this should return our manifest
- cmd: ./zarf tools kubectl get configmap -n zarf remove-test-configmap || echo "Not Found"
after:
# because this runs after the manifest is removed this should no longer be found
- cmd: ./zarf tools kubectl get configmap -n zarf remove-test-configmap || echo "Not Found"
- name: on-deploy-with-env-var
actions:
onDeploy:
before:
- cmd: touch $ZARF_VAR_TEST_FILENAME
env:
# this will set the env var ZARF_VAR_TEST_FILENAME - useful for passing information into scripts
- ZARF_VAR_TEST_FILENAME=test-filename-from-env.txt
- name: on-create-with-network-wait-action
description: This component will wait for 15 seconds for a network resource to be available
actions:
onCreate:
after:
- description: Github.com to be available
maxTotalSeconds: 15
wait:
# wait for a network address to return a 200 OK response
network:
protocol: https
address: github.com
code: 200
- name: on-deploy-with-wait-action
description: This component will wait for 5 seconds for the test-configmap to be exist
manifests:
- name: test-configmap
files:
- test-configmap.yaml
actions:
onDeploy:
after:
- description: The simple-configmap to exist
maxTotalSeconds: 5
wait:
# wait for the configmap to be available in the cluster
cluster:
kind: configmap
name: simple-configmap
namespace: zarf
- name: on-deploy-immediate-failure
description: This component will fail on the first error instead of continuing execution
# the default for multi-line commands is set -e
actions:
onDeploy:
after:
- cmd: |
bad_cmd
echo "this text shouldn't be printed"
# YAML keys starting with `x-` are custom keys that are ignored by the Zarf CLI
# The `x-mdx` key is used to render the markdown content for https://docs.zarf.dev/ref/examples
x-mdx: |
:::caution
Component Actions have replaced Component Scripts. Zarf will still read `scripts` entries, but will convert them to `actions`. Component Scripts will be removed in a future release. Please update your package configurations to use Component Actions instead.
:::
This example demonstrates how to define actions within your package that can run either on `zarf package create`, `zarf package deploy` or `zarf package remove`. These actions will be executed with the context that the Zarf binary is executed with.
For more details on component actions, see the [component actions](/ref/actions/) documentation.