### Zarf onCreate Action Example Source: https://docs.zarf.dev/ref/actions Demonstrates default settings and before/after actions for the onCreate lifecycle stage. Use this to define pre-creation tasks and post-creation verification or setup. ```yaml - 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 0.5 echo "in!" sleep 0.5 echo "realtime!" sleep 0.5 ``` -------------------------------- ### Download and Initialize Zarf Source: https://docs.zarf.dev/ref/init-package Run these commands after connecting to a cluster to download the init package and perform the initialization. This is the quickest way to get started with Zarf deployments. ```bash zarf tools download-init zarf init --confirm ``` -------------------------------- ### Install Zarf and Create Package in GitHub Action Source: https://docs.zarf.dev/ref/github-action This snippet shows how to use the setup-zarf action to install a specific Zarf version and then create a Zarf package. Ensure the Zarf version is valid. ```yaml jobs: create_package: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 1 - name: Install Zarf uses: zarf-dev/setup-zarf@main # use action's main branch with: version: v0.69.0 # any valid zarf version, leave blank to use latest - name: Create the package run: zarf package create --confirm ``` -------------------------------- ### Deploy Zarf Examples Service Source: https://docs.zarf.dev/tutorials/8-resource-adoption Applies the service manifest for the 'dos-games' example to the specified namespace. This exposes the deployed application. ```bash $ kubectl apply -f examples/dos-games/manifests/service.yaml -n dos-games service/doom created service/game created ``` -------------------------------- ### Install GolangCI-Lint Source: https://docs.zarf.dev/contribute/contributor-guide Installs golangci-lint, a Go linter used by the pre-commit hooks. Ensure your Go version matches the project's go.mod file. ```bash go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest ``` -------------------------------- ### Zarf Init Package Definition Example Source: https://docs.zarf.dev/tutorials/7-custom-init-packages This is an example of the Zarf init package definition that will be displayed when `zarf package create` is executed. It outlines the components, actions, and files included in the package. ```yaml **$zarf package create .** **kind**: ZarfInitConfig** ******metadata**:**** ** name**: init** ** ****description**: Used to establish a new Zarf cluster** ******components**: -** name**: k3s** ****description**: "*** REQUIRES ROOT *** Install K3s, certified Kubernetes distribution built for IoT & Edge computing. K3s provides the cluster need for Zarf running in Appliance Mode as well as can host a low-resource Gitops Service if not using an existing Kubernetes platform."****** only**:**** localOS**: linux** ****cluster**:**** architecture**: arm64** ****actions**:**** onDeploy**:**** defaults**:**** maxRetries**: 5** ****before**: -** maxRetries**: 0** ****cmd**: ./zarf internal is-valid-hostname** **-** cmd**: "[ -e /etc/redhat-release ] && systemctl disable firewalld --now || echo ''"****** after**: -** cmd**: systemctl daemon-reload** **-** cmd**: systemctl enable k3s** **-** cmd**: systemctl start k3s** ****files**: -** source**: packages/distros/k3s/common/zarf-clean-k3s.sh** ****target**: /opt/zarf/zarf-clean-k3s.sh** ****executable**: true** **-** source**: packages/distros/k3s/common/k3s.service** ****target**: /etc/systemd/system/k3s.service** ****symlinks**: - /etc/systemd/system/multi-user.target.wants/k3s.service** **-** source**: https://github.com/k3s-io/k3s/releases/download/v1.24.1+k3s1/k3s-arm64** ****shasum**: bd8b87d215f7a073d0139a0ab70e3fbeaa76e1b9ce6c00cd8d471cb44ba80687** ****target**: /usr/sbin/k3s** ****executable**: true** ****symlinks**: - /usr/sbin/kubectl** **-** /usr/sbin/ctr** **-** /usr/sbin/crictl** **-** source**: https://github.com/k3s-io/k3s/releases/download/v1.24.1+k3s1/k3s-airgap-images-arm64.tar.zst** ****shasum**: 12029e4bbfecfa16942345aeac798f4790e568a7202c2b85ee068d7b4756ba04** ****target**: /var/lib/rancher/k3s/agent/images/k3s.tar.zst** ****-** name**: zarf-injector** ****description**: | Bootstraps a Kubernetes cluster by cloning a running pod in the cluster and hosting the registry image. Removed and destroyed after the Zarf Registry is self-hosting the registry image.** ****required**: true** ****cosignKeyPath**: cosign.pub** ****files**: -** source**: sget://defenseunicorns/zarf-injector:arm64-2023-02-09** ``` -------------------------------- ### Zarf Package Configuration Template Example Source: https://docs.zarf.dev/ref/create This example demonstrates how to use package configuration templates to prompt for values during `zarf package create`. These templates are baked into the Zarf package and cannot be changed post-creation. ```yaml kind: ZarfPackageConfig metadata: name: 'pkg-variables' description: 'Prompt for a variables during package create' constants: - name: PROMPT_IMAGE value: '###ZARF_PKG_TMPL_PROMPT_ON_CREATE###' components: - name: zarf-prompt-image required: true images: - '###ZARF_PKG_TMPL_PROMPT_ON_CREATE###' ``` -------------------------------- ### Wait for Kubernetes Deployment Availability Source: https://docs.zarf.dev/commands/zarf_tools_wait-for This example demonstrates how to wait for a Kubernetes deployment to become 'available'. ```bash $ zarf tools wait-for deployment podinfo available -n podinfo # wait for deployment podinfo in namespace podinfo to be available ``` -------------------------------- ### Wait for Deployment to Exist Source: https://docs.zarf.dev/commands/zarf_tools_wait-for_resource This example demonstrates waiting for a specific deployment resource to exist in a given namespace. This is useful when a resource might not have been created yet. ```bash $ zarf tools wait-for resource deployment zarf-docker-registry exists -n zarf # wait for deployment zarf-docker-registry in namespace zarf to exist ``` -------------------------------- ### Example: Generate Zarf.yaml for Podinfo Chart Source: https://docs.zarf.dev/commands/zarf_dev_generate This example demonstrates how to use `zarf dev generate` to create a `zarf.yaml` for the podinfo Helm chart. It specifies the Git repository URL, the chart version, the relative path to the chart within the repository, and the desired output directory for the generated file. ```bash zarf dev generate podinfo --url https://github.com/stefanprodan/podinfo.git --version 6.4.0 --gitPath charts/podinfo --output-directory ./podinfo ``` -------------------------------- ### Deploy Zarf Examples Deployment Source: https://docs.zarf.dev/tutorials/8-resource-adoption Applies the deployment manifest for the 'dos-games' example to the specified namespace. Ensure you are in the Zarf repository's root directory. ```bash $ kubectl apply -f examples/dos-games/manifests/deployment.yaml -n dos-games deployment.apps/game created ``` -------------------------------- ### TOML Zarf Config File Example Source: https://docs.zarf.dev/ref/config-files This snippet demonstrates a Zarf configuration file in TOML format. It mirrors the YAML example with settings for package creation, deployment, and multiline variables. Use 'zarf prepare generate-config' to generate a new config file. ```toml # Example config file, use "zarf prepare generate-config" to generate a new one log_level = 'info' [package] [package.create] skip_sbom = false [package.create.set] zebra = 'stripes' leopard = 'spots' [package.deploy] components = 'lion' [package.deploy.set] scorpion = 'iridescent' camel_spider = 'matte' # dummy tls key showcasing multiline variables and autoindent tls_key = """-----BEGIN PRIVATE KEY----- MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDDvKUzWiZucm6/ 8D2Nx4KVe8t6uHtARpw112f4yGv7xKcOJkbxLbVtor8pj/HS5tRSZq2ziIQl9y98 8TVAOBezgzPPMDxOqDeyHl5gAtqzpK/eSPmueZIhR88BH2+SMYqa5kxmjn752Rf0 jVeCrVdQ5MD9rqA00oQi/zO+gQQoz6QSuiEQ2pSKYB3gv9oIoJorIU1n4qLYAezn TvFwjmKWPPhRdyslpcAi1rVO+mVX3Y2DKU/CfpWNFVVT+H788Srn4yP6iWUymfQU vHOXII1erMnES2H9BDffumrRf3m3IpgueQ3vPhB8ftjFZozURj2t/WSeaKsyQSoZ Wr99DWxpAgMBAAECggEAAW8ARsACSAzOgtlfmgo8Cpw9gUiYnn/l5P8O4+OT5uQp 1RCytFGBYqwuej9zpffK1k+qNgZp8V0+G8wod6/xfH8Zggr4ZhsVTVirmEhtEaPD Jf2i1oRNbbD48yknyApU2Y2WQaoJhArzAfeHDI34db83KqR8x+ZC0X7NAjgvr5zS b0OfY2tht4oxEWh2m67FzlFgF+cWyszRYyfvHfOFBqLesuCnSfMoOzmbT3SlnxHo 6GSa1e/kCJVzFJNb74BZTIH0w6Ar/a0QG829VXivqj8lRENU/1xUI2JhNz4RdH7F 6MeiwQbq4pWjHfh4djuzQFIwOgCnSNRnNuNywOVuAQKBgQDjleEI1XFQawXmHtHu 6GMhbgptRoSUyutDDdo2MHGvDbxDOIsczIBjxCuYAM47nmGMuWbDJUN+2VQAX32J WZagRxWikxnEqv3B7No7tLSQ42rRo/tDBrZPCCuS9u/ZJM4o7MCa/VzTtbicGOCh bTIoTeEtT2piIdkrjHFGGlYOLQKBgQDcLNFHrSJCkHfCoz75+zytfYan+2dIxuV/ MlnrT8XHt33cst4ZwoIQbsE6mv7J4CJqOgUYDvoJpioLV3InUACDxXd+bVY7RwxP j25pXzYL++RctVO3IEOCmFkwlq0fNFdrOn8Y/cnRTwd2e60n08rCKgJS8KhEAaO0 QvVmAHw4rQKBgQDL7hCAnunzuoLFqpZI8tlpKjaTpp3EynO3WSFQb2ZfCvrIbVFS U/kz7KN3iDlEeO5GcBeiA7EQaGN6FhbiTXHIWwoK7K8paGMMM1V2LL2kGvQruDm8 3LXd6Z9KCJXxSKanS0ZnW2KjnnE3Bp+6ZqOMNATzWfckydnUyPrza0PzXQKBgEYS 1YCUb8Tzqcn+nrp85XDp9INeFh8pfj0fT1L/DpljouEs5Fcaer60ITd/wPuLJCje 0mQ30AhmJBd7+07bvW4y2LcaIUm4cQiZQ7CxpsfloWaIJ16vHA1iY3B9ZBf8Vp4/ /dd8XlEJb/ybnB6C35MwP5EaGtOaGfnzHZsbKG35AoGAWm9tpqhuldQ3MCvoAr5Q b42JLSKqwpvVjQDiFZPI/0wZTo3WkWm9Rd7CAACheb8S70K1r/JIzsmIcnj0v4xs sfd+R35UE+m8MExbDP4lKFParmvi2/UZfb3VFNMmMPTV6AEIBl6N4PmhHMZOsIRs H4RxbE+FpmsMAUCpdrzvFkc= -----END PRIVATE KEY-----""" ``` -------------------------------- ### Run Upgrade Test with Pre-built Resources Source: https://docs.zarf.dev/contribute/testing Execute the upgrade test suite from the repository root if Zarf binary, init-package, and example packages are already built. ```go # or # If you are in the root folder of the repository and already have everything built (i.e., the binary, the init-package and the flux-test example package): go test ./src/test/upgrade/... ``` -------------------------------- ### Run External Test with Pre-built Resources Source: https://docs.zarf.dev/contribute/testing Execute the external test suite from the repository root if Zarf binary, init-package, and example packages are already built. ```go # or # If you are in the root folder of the repository and already have everything built (i.e., the binary, the init-package and the flux-test example package): go test ./src/test/external/... -v ``` -------------------------------- ### Create Zarf Package Source: https://docs.zarf.dev/tutorials/5-package-signing-and-verification Create a Zarf package from the Zarf examples directory. The path to the created package will be shown in the logs. ```bash zarf package create ./zarf/examples/wordpress ``` -------------------------------- ### Zsh Autocompletion Setup Source: https://docs.zarf.dev/commands/zarf_tools_yq_completion Load Zsh autocompletion for yq. Ensure shell completion is enabled and redirect the output to a directory in your fpath. ```zsh # If shell completion is not already enabled in your environment you will need # to enable it. You can execute the following once: $ echo “autoload -U compinit; compinit” >> ~/.zshrc # To load completions for each session, execute once: $ yq completion zsh > ”${fpath[1]}/_yq” # You will need to start a new shell for this setup to take effect. ``` -------------------------------- ### Enable Bash Completions Source: https://docs.zarf.dev/commands/zarf_completion_bash After setting up the completion script, start a new shell session for the changes to take effect. ```bash zarf completion bash ``` -------------------------------- ### Create a k3d Kubernetes Cluster Source: https://docs.zarf.dev/tutorials Use this command to create a local k3d Kubernetes cluster. Ensure Docker is installed and k3d is set up beforehand. ```bash k3d cluster create ``` -------------------------------- ### Cloning Zarf Repository Source: https://docs.zarf.dev/ref/init-package To reproduce or build the example, clone the Zarf repository locally and navigate into the directory. It's also recommended to back up the existing 'zarf.yaml' file. ```bash git clone https://github.com/zarf-dev/zarf.git cd zarf mv zarf.yaml zarf.yaml.bak ``` -------------------------------- ### Wait for Pods by Label Selector Source: https://docs.zarf.dev/commands/zarf_tools_wait-for_resource Use this example to wait for all pods matching a specific label selector in a given namespace to be reconciled. ```bash $ zarf tools wait-for resource pod app=podinfo -n podinfo # wait for pod(s) with label app=podinfo in namespace podinfo to be reconciled ``` -------------------------------- ### Fish Autocompletion Setup Source: https://docs.zarf.dev/commands/zarf_tools_yq_completion Load Fish autocompletion for yq. For persistent loading, redirect the output to the yq.fish file in your Fish completions directory. ```fish $ yq completion fish | source # To load completions for each session, execute once: $ yq completion fish > ~/.config/fish/completions/yq.fish ``` -------------------------------- ### Bash Autocompletion Setup Source: https://docs.zarf.dev/commands/zarf_tools_yq_completion Load Bash autocompletion for yq. For persistent loading, redirect the output to a system-wide or user-specific bash completion directory. ```bash # To load completions for each session, execute once: Linux: $ yq completion bash > /etc/bash_completion.d/yq MacOS: $ yq completion bash > /usr/local/etc/bash_completion.d/yq ``` -------------------------------- ### Wait for StatefulSet Available Replicas Source: https://docs.zarf.dev/commands/zarf_tools_wait-for_resource This example demonstrates waiting for a StatefulSet to reach a specific number of available replicas. It uses a JSONPath expression to check the status. ```bash $ zarf tools wait-for resource sts test-sts '{.status.availableReplicas}'=23 # wait for statefulset test-sts to have 23 available replicas ``` -------------------------------- ### Run Local Docker Registry Source: https://docs.zarf.dev/faq Use this command to start a local Docker registry. This is a prerequisite for speeding up the loading of large images during `zarf package create`. ```bash docker run -d -p 5000:5000 --restart=always --name registry registry:3 ``` -------------------------------- ### Wait for Pod Reconciliation (Alias 'po') Source: https://docs.zarf.dev/commands/zarf_tools_wait-for_resource This example demonstrates waiting for a pod to be reconciled using the 'po' alias for the resource kind. It specifies the pod name and namespace. ```bash $ zarf tools wait-for resource po cool-pod-name -n cool # wait for pod (using po alias) cool-pod-name in namespace cool to be reconciled ``` -------------------------------- ### Get Manifest for Internal Zarf Registry Source: https://docs.zarf.dev/commands/zarf_tools_registry_manifest Example of retrieving an image manifest from an internal Zarf registry. Ensure the registry is accessible. ```bash # Return an image manifest for an internal repo in Zarf $ zarf tools registry manifest 127.0.0.1:31999/stefanprodan/podinfo:6.4.0 ``` -------------------------------- ### Get Manifest from GitHub Container Registry Source: https://docs.zarf.dev/commands/zarf_tools_registry_manifest Example of retrieving an image manifest from a public registry like ghcr.io. This demonstrates fetching from external sources. ```bash # Return an image manifest from a repo hosted at ghcr.io $ zarf tools registry manifest ghcr.io/stefanprodan/podinfo:6.4.0 ``` -------------------------------- ### Specify Output Directory and Version Source: https://docs.zarf.dev/commands/zarf_tools_download-init Combine flags to specify both the output directory and the version of the init package to download. ```bash zarf tools download-init -o "./my-init-package" -v "v0.25.0" ``` -------------------------------- ### View Zarf Init Options Source: https://docs.zarf.dev/ref/init-package Use the --help flag with the 'zarf init' command to see all available configuration options for initializing your Zarf environment. ```bash zarf init --help ``` -------------------------------- ### Get Specific Zarf Credentials Source: https://docs.zarf.dev/commands/zarf_tools_get-creds Pass a service key as an argument to retrieve specific Zarf credentials. Examples include 'registry', 'registry-readonly', 'git', 'git-readonly', and 'artifact'. ```bash $ zarf tools get-creds registry ``` ```bash $ zarf tools get-creds registry-readonly ``` ```bash $ zarf tools get-creds git ``` ```bash $ zarf tools get-creds git-readonly ``` ```bash $ zarf tools get-creds artifact ``` -------------------------------- ### Wait for Any PVC in Namespace Source: https://docs.zarf.dev/commands/zarf_tools_wait-for_resource This example demonstrates waiting for any Persistent Volume Claim (PVC) resource to exist within a specified namespace. This is useful when you need to ensure storage is available. ```bash $ zarf tools wait-for resource pvc -n zarf # wait for any pvc in namespace zarf to exist ``` -------------------------------- ### Setup Zarf Completions for New Sessions (macOS) Source: https://docs.zarf.dev/commands/zarf_completion_zsh Execute this command on macOS to install the Zarf autocompletion script into the Zsh site-functions directory, enabling it for all future shell sessions. ```bash zarf completion zsh > $(brew --prefix)/share/zsh/site-functions/_zarf ``` -------------------------------- ### Download and Build Image with Zarf Action Source: https://docs.zarf.dev/ref/actions Use `onCreate.before` actions to download necessary files like .zim archives and build container images. This example downloads a Kiwix .zim file and builds a Docker image containing it. ```yaml - name: kiwix-serve required: true manifests: - name: kiwix-serve namespace: kiwix files: - manifests/deployment.yaml - manifests/service.yaml images: - ghcr.io/kiwix/kiwix-serve:3.5.0-2 imageArchives: - path: kiwix-data.tar images: # Using zarf.internal as our registry ensures our manifest will never pull from a squatted registry url even if mutation is never run. - zarf.internal/kiwix-data:local actions: onCreate: before: # Download a .zim file of a DevOps Stack Exchange snapshot so that it can placed in the image we're building - cmd: curl -fSL https://zarf-init-resources-dev.s3.us-east-1.amazonaws.com/devops.stackexchange.com_en_all_2026-02.zim -o zim-data/devops.stackexchange.com_en_all_2026-02.zim # Below are some more examples of *.zim files of available content: # https://library.kiwix.org/?lang=eng # NOTE: If `zarf package create`ing regularly you should mirror content to a web host you control to be a friendly neighbor # Build a container image containing the ZIM data file - cmd: docker build -t zarf.internal/kiwix-data:local . # Export the container image to a tar archive for use as an image archive - cmd: docker save zarf.internal/kiwix-data:local -o kiwix-data.tar documentation: readme: readme.md ``` -------------------------------- ### Check Zarf Installation Version Source: https://docs.zarf.dev/getting-started/install Verify that Zarf has been installed correctly by checking its version. This command should output the installed version number. ```bash $ zarf version vX.X.X # X.X.X is replaced with the version number of your specific installation ``` -------------------------------- ### Initialize Zarf and Deploy DOS Games (Non-Interactive) Source: https://docs.zarf.dev/getting-started This snippet demonstrates a non-interactive Zarf setup, downloading the init package, initializing Zarf with confirmation, and deploying the DOS Games package using the --confirm flag. ```bash # Startup a fresh kind cluster kind delete cluster && kind create cluster # Download the default init package and deploy it zarf tools download-init zarf init --confirm # Deploy the DOS Games package zarf package deploy oci://ghcr.io/zarf-dev/packages/dos-games:1.3.0 \ --key=https://zarf.dev/cosign.pub \ --confirm ``` -------------------------------- ### Initialize Zarf and Deploy DOS Games (Interactive) Source: https://docs.zarf.dev/getting-started This snippet shows the interactive steps to initialize Zarf, including confirming downloads and deployments, and then deploying the DOS Games package. ```bash # Startup a fresh kind cluster kind delete cluster && kind create cluster zarf init # (Select 'Y' to download the default init package) # (Select 'Y' to confirm deployment) # (Select optional components as desired) # Now you are ready to deploy any Zarf Package, try out our Retro Arcade!! zarf package deploy oci://ghcr.io/zarf-dev/packages/dos-games:1.3.0 --key=https://zarf.dev/cosign.pub # (Select 'Y' to confirm deployment) ``` -------------------------------- ### Install Zarf with Homebrew Source: https://docs.zarf.dev/getting-started/install Use Homebrew to install Zarf on macOS and Linux systems. This is the recommended method for ease of use. ```bash brew install defenseunicorns/tap/zarf ``` -------------------------------- ### Templating Manifest Files Source: https://docs.zarf.dev/ref/examples/values-templating Demonstrates how to enable go-templating within manifest files for dynamic configuration during deployment. ```yaml - name: values-with-nginx # Enables go-templating within the files. template: true files: - nginx-deployment.yaml - nginx-service.yaml - nginx-configmap.yaml ``` -------------------------------- ### Install Pre-Commit Hooks Source: https://docs.zarf.dev/contribute/contributor-guide Installs the Git pre-commit hooks to automatically lint and format code before each commit. This ensures code quality and consistency. ```bash pre-commit install ``` -------------------------------- ### Initialize Zarf with Components and Confirmation Source: https://docs.zarf.dev/tutorials/4-creating-a-k8s-cluster-with-zarf Automatically accept the k3s component and confirm the package deployment using the '--components' and '--confirm' flags. ```bash zarf init --components="k3s" --confirm ``` -------------------------------- ### Zarf Tools Get Credentials Source: https://docs.zarf.dev/commands/zarf_tools Displays a table of credentials for deployed Zarf services. Pass a service key to get a single credential. ```bash zarf tools get-creds ``` -------------------------------- ### List Installed Zarf Packages Source: https://docs.zarf.dev/tutorials/3-deploy-a-retro-arcade Use `zarf package list` to view all installed packages and their components. This helps identify the package name for removal. ```bash $ zarf package list Saving log file to /var/folders/bk/rz1xx2sd5zn134c0_j1s2n5r0000gp/T/zarf-2023-03-23-10-05-29-1632940529.log ********** Package ******** | ********Components ******** init ****** | **[zarf-injector zarf-seed-registry zarf-registry zarf-agent] dos-games****** | **[baseline] ``` -------------------------------- ### Download Init Package Source: https://docs.zarf.dev/commands/zarf_tools_download-init Use this command to download the Zarf init package. You can specify an output directory and a specific version. ```bash zarf tools download-init [flags] ``` -------------------------------- ### Zarf Tools SBOM Image Source Examples Source: https://docs.zarf.dev/commands/zarf_tools_sbom Illustrates how to scan container images from different sources, including local Docker daemons, OCI tarballs, SIF containers, and generic directories. ```bash zarf tools sbom scan yourrepo/yourimage:tag ``` ```bash zarf tools sbom scan path/to/a/file/or/dir ``` -------------------------------- ### Flux Installation with Container Images Source: https://docs.zarf.dev/ref/components Installs Flux CRDs and controllers, specifying multiple container images required for Flux-based deployments. Image discovery is supported. ```yaml - name: flux description: Installs the flux CRDs / controllers to use flux-based deployments in the cluster required: true manifests: - name: flux-install namespace: flux-system files: - https://github.com/fluxcd/flux2/releases/download/v2.4.0/install.yaml images: - ghcr.io/fluxcd/helm-controller:v1.1.0 - ghcr.io/fluxcd/image-automation-controller:v0.39.0 - ghcr.io/fluxcd/image-reflector-controller:v0.33.0 - ghcr.io/fluxcd/kustomize-controller:v1.4.0 - ghcr.io/fluxcd/notification-controller:v1.4.0 - ghcr.io/fluxcd/source-controller:v1.4.1 ``` -------------------------------- ### List Installed Zarf Packages Source: https://docs.zarf.dev/tutorials/2-deploying-zarf-packages Use `zarf package list` to view all installed Zarf packages and their components. This helps identify the correct package name for removal. ```bash $ zarf package list Saving log file to /var/folders/bk/rz1xx2sd5zn134c0_j1s2n5r0000gp/T/zarf-2023-03-23-10-05-29-1632940529.log ********** Package ******** | ********Components ******** init ****** | **[zarf-injector zarf-seed-registry zarf-registry zarf-agent] wordpress****** | **[wordpress] ``` -------------------------------- ### List Repositories for a Specific Registry Source: https://docs.zarf.dev/commands/zarf_tools_registry_catalog Use this command to list repositories in a custom registry. Replace 'reg.example.com' with the actual address of your registry. ```bash $ zarf tools registry catalog reg.example.com ``` -------------------------------- ### Zarf Tools SBOM Scan Examples Source: https://docs.zarf.dev/commands/zarf_tools_sbom Demonstrates various ways to scan an image (e.g., alpine:latest) and output the SBOM in different formats like JSON, CycloneDX, or SPDX. Also shows how to enable verbose logging. ```bash zarf tools sbom scan alpine:latest ``` ```bash zarf tools sbom scan alpine:latest -o json ``` ```bash zarf tools sbom scan alpine:latest -o cyclonedx ``` ```bash zarf tools sbom scan alpine:latest -o cyclonedx-json ``` ```bash zarf tools sbom scan alpine:latest -o spdx ``` ```bash zarf tools sbom scan alpine:latest -o spdx@2.2 ``` ```bash zarf tools sbom scan alpine:latest -o spdx-json ``` ```bash zarf tools sbom scan alpine:latest -o spdx-json@2.2 ``` ```bash zarf tools sbom scan alpine:latest -vv ``` ```bash zarf tools sbom scan alpine:latest -o template -t my_format.tmpl ``` -------------------------------- ### Zarf Package Definition Example Source: https://docs.zarf.dev/tutorials/0-creating-a-zarf-package This is an example of the `zarf.yaml` content that Zarf displays during the package creation confirmation prompt. It outlines the package's metadata, components, charts, images, and variables. ```yaml **$ zarf package create .** **Saving log file to /tmp/zarf-2023-05-06-21-02-22-601928677.log** **** **Using build directory .** **** ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ **kind**: **ZarfPackageConfig** ******metadata**:**** ** name**: **wordpress** ** ****description**: **A Zarf Package that deploys the WordPress blogging and content management platform** ** ****version**: **26.0.0** ******components**: -** name**: **wordpress** ** ****description**: **Deploys the Bitnami-packaged WordPress chart into the cluster** ** ****required**: **true** ** ****charts**: -** name**: **wordpress** ** ****url**: **oci://registry-1.docker.io/bitnamicharts/wordpress** ** ****version**: **26.0.0** ** ****namespace**: **wordpress** ** ****valuesFiles**: -** wordpress-values.yaml** ** ****manifests**: -** name**: **connect-services** ** ****namespace**: **wordpress** ** ****files**: -** connect-services.yaml** ** ****images**: -** docker.io/bitnamilegacy/apache-exporter:1.0.10-debian-12-r55** ** **-** docker.io/bitnamilegacy/mariadb:12.0.2-debian-12-r0** ** **-** docker.io/bitnamilegacy/wordpress:6.8.2-debian-12-r4** ******variables**: -** name**: **WORDPRESS_USERNAME** ** ****description**: **The username that is used to login to the WordPress admin account** ** ****default**: **zarf** ** ****prompt**: **true** ****-** name**: **WORDPRESS_PASSWORD** ** ****description**: **The password that is used to login to the WordPress admin account** ** ****prompt**: **true** ** ****sensitive**: **true** ****-** name**: **WORDPRESS_EMAIL** ** ****description**: **The email that is used for the WordPress admin account** ** ****default**: **hello@zarf-dev.com** ** ****prompt**: **true** ****-** name**: **WORDPRESS_FIRST_NAME** ** ****description**: **The first name that is used for the WordPress admin account** ** ****default**: **Zarf** ** ****prompt**: **true** ****-** name**: **WORDPRESS_LAST_NAME** ** ****description**: **The last name that is used for the WordPress admin account** ** ****default**: **The Axolotl** ** ****prompt**: **true** ****-** name**: **WORDPRESS_BLOG_NAME** ** ****description**: **The blog name that is used for the WordPress admin account** ** ****default**: **The Zarf Blog** ** ****prompt**: **true** **? ****Create this Zarf package? ****(y/N) **Yes ``` -------------------------------- ### Installing K3s with Zarf Component Source: https://docs.zarf.dev/ref/components This component installs K3s, a lightweight Kubernetes distribution, on Linux amd64 systems. It requires root privileges and configures systemd services. Ensure the host architecture matches the package architecture. ```yaml - name: k3s only: localOS: linux cluster: architecture: amd64 description: > *** REQUIRES ROOT (not sudo) *** Install K3s, a certified Kubernetes distribution built for IoT & Edge computing. K3s provides the cluster need for Zarf running in Appliance Mode as well as can host a low-resource Gitops Service if not using an existing Kubernetes platform. files: # K3s removal script - source: zarf-clean-k3s.sh target: /opt/zarf/zarf-clean-k3s.sh executable: true # The K3s systemd service definition - source: k3s.service target: /etc/systemd/system/k3s.service symlinks: - /etc/systemd/system/multi-user.target.wants/k3s.service # Include the actual K3s binary - source: https://github.com/k3s-io/k3s/releases/download/v1.34.3+k3s1/k3s shasum: f95350e3997165974d1d1406f01aabaf869aed7ca790cc2d83a92a82f26a06c5 target: /usr/sbin/k3s executable: true # K3s magic provides these tools when symlinking symlinks: - /usr/sbin/kubectl - /usr/sbin/ctr - /usr/sbin/crictl # Transfer the K3s images for containerd to pick them up - source: https://github.com/k3s-io/k3s/releases/download/v1.34.3+k3s1/k3s-airgap-images-amd64.tar.zst shasum: b8dff3265568e1be66ab72ac0ded68bd266fa37a32c010f1253dba6547a49ce8 target: /var/lib/rancher/k3s/agent/images/k3s.tar.zst actions: onDeploy: defaults: maxRetries: 5 before: - cmd: if [ "$(uname -m)" != "x86_64" ]; then echo "this package architecture is amd64, but the target system has a different architecture. These architectures must be the same" && exit 1; fi description: Check that the host architecture matches the package architecture maxRetries: 0 - cmd: ./zarf internal is-valid-hostname maxRetries: 0 description: Check if the current system has a, RFC1123 compliant hostname # If running RHEL variant, disable firewalld # https://rancher.com/docs/k3s/latest/en/advanced/#additional-preparation-for-red-hat-centos-enterprise-linux # NOTE: The empty echo prevents infinite retry loops on non-RHEL systems where the exit code would be an error - cmd: "[ -e /etc/redhat-release ] && systemctl disable firewalld --now || echo ''" description: If running a RHEL variant, disable 'firewalld' per k3s docs after: # Configure K3s systemd service - cmd: systemctl daemon-reload description: Reload the system services - cmd: systemctl enable k3s description: Enable 'k3s' to run at system boot - cmd: systemctl restart k3s description: Start the 'k3s' system service onRemove: before: - cmd: /opt/zarf/zarf-clean-k3s.sh description: Remove 'k3s' from the system - cmd: rm /opt/zarf/zarf-clean-k3s.sh description: Remove the cleanup script # ARM-64 version of the K3s stack ``` -------------------------------- ### Zarf Init Command Synopsis Source: https://docs.zarf.dev/commands/zarf_init The basic syntax for the `zarf init` command. ```bash zarf init [ PACKAGE_SOURCE ] [flags] ``` -------------------------------- ### Initialize Zarf Source: https://docs.zarf.dev/tutorials/4-creating-a-k8s-cluster-with-zarf Run the 'zarf init' command as root to begin the Zarf initialization process. ```bash # zarf init ``` -------------------------------- ### Clone Zarf Repository Source: https://docs.zarf.dev/tutorials/5-package-signing-and-verification Clone the Zarf source code repository to access example packages. ```bash git clone https://github.com/zarf-dev/zarf.git ``` -------------------------------- ### Initialize Zarf Source: https://docs.zarf.dev/getting-started/install Initialize Zarf to set up the necessary components. Zarf will prompt to download the default init package if none is detected, or you can use `--confirm` to bypass the prompt. ```bash # if no init package is detected, zarf will prompt you to download the default one on init $ zarf init # if you want to download the init package without being prompted $ zarf tools download-init $ zarf init --confirm ``` -------------------------------- ### Create YOLO Package Source: https://docs.zarf.dev/ref/examples/yolo Use this command to create the Zarf package for the YOLO mode example. ```bash zarf package create examples/yolo ``` -------------------------------- ### Specify Version Source: https://docs.zarf.dev/commands/zarf_tools_download-init Use the `-v` or `--version` flag to download a specific version of the init package. If not specified, it defaults to the current CLI version. ```bash zarf tools download-init -v "v0.25.0" ``` -------------------------------- ### Action Command Without Templating Source: https://docs.zarf.dev/ref/examples/values-templating An example of an action command where Go-template processing is disabled, passing the syntax through unchanged. ```bash echo "This {{ .wontBeProcessed }} stays as-is" ``` -------------------------------- ### Download Latest Zarf Init Package Source: https://docs.zarf.dev/best-practices/upgrading-zarf Fetches the latest Zarf init package to the current working directory. Use `--output-directory` to specify a different location. ```bash zarf tools download-init ``` -------------------------------- ### Create EKS Cluster using EKSCTL Action Source: https://docs.zarf.dev/ref/actions Use `onDeploy.before` actions to execute `eksctl` commands for creating an EKS cluster. This example includes a dry-run, a sleep for stability, the actual cluster creation, and writing the kubeconfig. ```yaml - name: deploy-eks-cluster description: Create an EKS cluster! actions: onDeploy: before: - cmd: ./binaries/eksctl_$(uname -s)_$(uname -m) create cluster --dry-run -f eks.yaml - cmd: sleep 15 - cmd: ./binaries/eksctl_$(uname -s)_$(uname -m) create cluster -f eks.yaml - cmd: ./binaries/eksctl_$(uname -s)_$(uname -m) utils write-kubeconfig -c ${ZARF_VAR_EKS_CLUSTER_NAME} ``` -------------------------------- ### Extract Documentation from Local Tarball Source: https://docs.zarf.dev/commands/zarf_package_inspect_documentation Example of extracting documentation from a Zarf package tarball stored locally on the filesystem. ```bash $ zarf package inspect documentation zarf-package-my-app-amd64-1.0.0.tar.zst ``` -------------------------------- ### Zarf Package Config: Before Data Injections Source: https://docs.zarf.dev/best-practices/data-injections-migration Example of a Zarf package configuration using the deprecated 'dataInjections' field. ```yaml kind: ZarfPackageConfig metadata: name: data-injections components: - name: my-app required: true images: - ghcr.io/my-app:1.0.0 - alpine:3.18 dataInjections: - source: my-folder target: namespace: my-app selector: app=my-app container: data-loader path: /data compress: true ``` -------------------------------- ### Print Zarf Archiver Version Source: https://docs.zarf.dev/commands/zarf_tools_archiver_version Use this command to display the current version of the Zarf archiver. No setup is required. ```bash zarf tools archiver version [flags] ``` -------------------------------- ### Move Zarf binary to PATH on Linux Source: https://docs.zarf.dev/getting-started/install Install the downloaded Zarf binary to your system's PATH by moving it to `/usr/local/bin`. ```bash sudo mv zarf /usr/local/bin/zarf ``` -------------------------------- ### Specify Output Directory Source: https://docs.zarf.dev/commands/zarf_tools_download-init Use the `-o` or `--output-directory` flag to specify where the init package should be saved. ```bash zarf tools download-init -o "./my-init-package" ``` -------------------------------- ### Action Command with Templating Enabled Source: https://docs.zarf.dev/ref/examples/values-templating An example of an action command where Go-template processing is explicitly enabled using `template: true`. ```bash echo "Organization: {{ .Values.site.organization }}" echo "Environment: {{ .Values.app.environment }}" ``` -------------------------------- ### Monitor with Screen Dump Directory Source: https://docs.zarf.dev/commands/zarf_tools_monitor Launches K9s and sets a directory for saving screen dumps, useful for capturing K9s output. ```bash zarf tools monitor --screen-dump-dir ``` -------------------------------- ### Pull Image from External Registry Source: https://docs.zarf.dev/commands/zarf_tools_registry_pull Example of pulling an image from a remote registry hosted at 'reg.example.com'. The image is saved to 'image.tar'. ```bash # Pull an image from a repo hosted at reg.example.com to a local tarball $ zarf tools registry pull reg.example.com/stefanprodan/podinfo:6.4.0 image.tar ``` -------------------------------- ### Wait for TCP Connection Source: https://docs.zarf.dev/commands/zarf_tools_wait-for_network This example demonstrates waiting for a TCP connection to be established on a specified address. It's useful for services that don't use HTTP but require a network port to be open. ```bash $ zarf tools wait-for network tcp localhost:8080 # wait for a connection to be established on localhost:8080 ``` -------------------------------- ### Wait for Custom Resource Definition (CRD) Existence Source: https://docs.zarf.dev/commands/zarf_tools_wait-for This example waits for a custom resource definition (CRD) to exist in the Kubernetes cluster. ```bash $ zarf tools wait-for crd addons.k3s.cattle.io # wait for crd addons.k3s.cattle.io to exist ``` -------------------------------- ### Login Options Source: https://docs.zarf.dev/commands/zarf_tools_sbom_login These are the specific options available for the 'login' subcommand, such as setting username, password, or using stdin for the password. ```bash -h, --help help for login -p, --password string Password --password-stdin Take the password from stdin -u, --username string Username ``` -------------------------------- ### Connect to Adopted Application Source: https://docs.zarf.dev/tutorials/8-resource-adoption Demonstrates using the 'zarf package connect' command to establish a connection to an application within an adopted namespace. ```bash $ zarf package connect games SAVING LOG FILE TO /var/folders/bk/rz1xx2sd5zn134c0_j1s2n5r0000gp/T/zarf-2023-05-10-12-02-03-3555041969.log • PREPARING A TUNNEL TO CONNECT TO GAMES HTTP://127.0.0.1:60064^C% ``` -------------------------------- ### Get Stored Digest of Deployed Package Source: https://docs.zarf.dev/commands/zarf_package_inspect_digest Fetch the previously stored SHA256 digest for a Zarf package that has already been deployed to your cluster. ```bash # Get the stored digest of a package already deployed to a cluster $ zarf package inspect digest my-package ``` -------------------------------- ### Get Digest of Local Package Tarball Source: https://docs.zarf.dev/commands/zarf_package_inspect_digest Use this command to obtain the SHA256 digest for a Zarf package that has been packaged into a local tarball. ```bash # Get the digest of a local package tarball $ zarf package inspect digest zarf-package-my-app-amd64-1.0.0.tar.zst ```