wide-nest-40830
02/20/2023, 7:29 PMbright-policeman-43626
02/21/2023, 5:25 AMtemplate
for CI environments, so imagine you have a pipeline that do 3 steps:
- garden deploy --env=ci
- garden run task migrations-up
- garden run test unit
So instead of having to do those 3 steps in your CI steps you can setup a simple workflow called run-ci
for example:
kind: Workflow
name: run-ci
steps:
- command: [deploy --env=ci]
- command: [run, task, migrations-up]
- command: [run, test, unit]
And now because you have that workflow defined, in your CI you can just simply run the workflow, saving a couple of lines and making your CI configuration even more clear.
garden run workflow run-ci
You can basically see them as wrappers for running multiple commands with Garden easily?
2.* Can 1 Garden workflow depend on another workflow (so I can sequence the workflows one after another, if I were running certain tests)*
No, unfortunately Workflows are outside of the "Stack Graph" so they cannot currently depend on a different workflow.
3. Are Garden workflows idempotent?
It depends in the tasks you are running, Garden will always execute all the tasks in the workflow but it depends on the inside tasks to be idempotent, for example if you have a migration that can only be ran once, your workflow is not going to be idempotent because the second time you run the workflow it's going to fail.
4. If my development or testing workflow required me to manipulate my...
Would you mind extending this point a little bit to get more context and give an appropriate answer? ❤️quaint-dress-831
02/21/2023, 7:42 AMyaml
image: gardendev/garden:0.12.51
run-garden:
stage: build
script:
- git config --global --add safe.directory $CI_PROJECT_DIR
- garden run workflow my-workflow --env=ci
Here's my Workflows file that's kicked off by GitLab CI:
yaml
kind: Workflow
name: my-workflow
steps:
- description: Source Terraform Cloud credentials and install Nixpacks
script: |-
cat >~/.terraformrc <<EOL
credentials "app.terraform.io" {
token = "${local.env.TF_CLOUD_TOKEN}"
}
EOL
if [[ "$OSTYPE" == "darwin"* ]]; then
command -v nixpacks || brew install railwayapp/tap/nixpacks
else
command -v nixpacks || curl -sSL https://nixpacks.com/install.sh | bash
fi
- description: Deploy app to Kubernetes cluster
command: [deploy]
- description: Run tests on app
command: [test]
- description: Delete namespace to clean up only in CI
name: cleanup
command: [delete, environment]
skip: "${environment.name != 'ci'}"
I have a pre-init script that sets up enough of an environment for deploy
to run. It tests my app, then using a conditional, cleans up that environment namespace created just for CI, and runs that cleanup step only when the environment is my CI pipeline i. e. running inside GitLab.
Pretty cool, right?