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