|
| 1 | +# Part 1: Create a Zarf Package |
| 2 | + |
| 3 | +Zarf packages all the contents of your application into a single OCI artifact that can be deployed into an airgapped environment. In this part, you'll create a Zarf package for [ArgoCD](https://argo-cd.readthedocs.io/) from scratch. |
| 4 | + |
| 5 | +Create a working directory and navigate into it: |
| 6 | + |
| 7 | +```bash |
| 8 | +mkdir zarf-package && cd zarf-package |
| 9 | +``` |
| 10 | + |
| 11 | +## Step 1: Create the Package Definition |
| 12 | + |
| 13 | +The most important piece of a Zarf package is the `zarf.yaml` file. It follows the [Zarf package schema](https://github.com/zarf-dev/zarf/blob/main/zarf.schema.json) and defines both the package metadata and the components to deploy. |
| 14 | + |
| 15 | +Create a `zarf.yaml` file with the following content: |
| 16 | + |
| 17 | +```yaml |
| 18 | +kind: ZarfPackageConfig # ZarfPackageConfig is the package kind for most normal zarf packages |
| 19 | +metadata: |
| 20 | + name: argocd # specifies the name of our package; should be unique and stable across updates |
| 21 | + version: 9.4.4 # (optional) a version to track as you release updates or publish to a registry |
| 22 | + description: | # (optional) a human-readable description of the package |
| 23 | + "A Zarf Package that deploys the ArgoCD platform" |
| 24 | +``` |
| 25 | +
|
| 26 | +## Step 2: Add the ArgoCD Component |
| 27 | +
|
| 28 | +In a Zarf package, **components** are the units that define an application stack. They can include Kubernetes manifests, configuration files, Helm charts, and more. Components are defined under the `components` key in `zarf.yaml`. |
| 29 | + |
| 30 | +For more details, see [Understanding Zarf Components](https://docs.zarf.dev/ref/components/). |
| 31 | + |
| 32 | +Add the following to the bottom of your `zarf.yaml`: |
| 33 | + |
| 34 | +```yaml |
| 35 | +components: |
| 36 | + - name: argocd # specifies the name of our component; should be unique and stable across updates |
| 37 | + description: | # (optional) a human-readable description of the component |
| 38 | + "Deploys the ArgoCD packaged chart into the cluster" |
| 39 | + required: true # ensures this component is always deployed |
| 40 | + charts: |
| 41 | + - name: argo-cd |
| 42 | + version: 9.4.4 |
| 43 | + namespace: argocd |
| 44 | + url: https://argoproj.github.io/argo-helm |
| 45 | + releaseName: argocd-baseline |
| 46 | + valuesFiles: |
| 47 | + - baseline-values.yaml |
| 48 | +``` |
| 49 | + |
| 50 | +The `url` field points directly to the upstream ArgoCD Helm repository — the same source you'd use with `helm repo add`. When you build the package, Zarf fetches the chart from that URL and bundles it into the tarball, so the airgapped environment gets an unmodified copy of the upstream chart. Local chart directories are also supported if you need to package a custom or vendored chart. |
| 51 | + |
| 52 | +## Step 3: Create the Values File |
| 53 | + |
| 54 | +The `valuesFiles` entry above references a `baseline-values.yaml` file. Create it in the same directory with the following content: |
| 55 | + |
| 56 | +```yaml |
| 57 | +redis-ha: |
| 58 | + enabled: false |
| 59 | +
|
| 60 | +dex: |
| 61 | + enabled: false |
| 62 | +
|
| 63 | +notifications: |
| 64 | + enabled: false |
| 65 | +
|
| 66 | +redis: |
| 67 | + image: |
| 68 | + repository: docker.io/library/redis |
| 69 | +``` |
| 70 | + |
| 71 | +> [!NOTE] |
| 72 | +> These values are needed at package creation time because the `zarf dev find-images` command (used in the next step) templates the Helm chart to discover required images. Providing values now ensures that templating succeeds. |
| 73 | + |
| 74 | +## Step 4: Find the Images |
| 75 | + |
| 76 | +Zarf packages all required container images alongside your application so they're available in a disconnected environment. The `zarf dev find-images` command templates your Helm chart and identifies every image that will be needed. |
| 77 | + |
| 78 | +Run this in your `zarf-package` directory: |
| 79 | + |
| 80 | +```bash |
| 81 | +zarf dev find-images |
| 82 | +``` |
| 83 | + |
| 84 | +You should see output similar to: |
| 85 | + |
| 86 | +```yaml |
| 87 | +components: |
| 88 | + - name: argocd |
| 89 | + images: |
| 90 | + - docker.io/library/redis:8.2.3-alpine |
| 91 | + - quay.io/argoproj/argocd:v3.3.2 |
| 92 | + # Cosign artifacts for images - argocd |
| 93 | + - quay.io/argoproj/argocd:sha256-5882f28f7aaeaac397949c4511fdc1ad66c1260af44166ccf7e57aca3d7b9797.att |
| 94 | +``` |
| 95 | + |
| 96 | +Copy the full `images` list from your output into the `argocd` component in your `zarf.yaml`, replacing the two images you added in Step 2. |
| 97 | + |
| 98 | +## Step 5: Set Up a Zarf Connect Service |
| 99 | + |
| 100 | +Zarf Connect Services let you quickly connect to a deployed application by watching for specific Kubernetes service labels and annotations. After deployment, Zarf surfaces any discovered connect endpoints. |
| 101 | + |
| 102 | +Add the following to your `baseline-values.yaml` file: |
| 103 | + |
| 104 | +```yaml |
| 105 | +server: |
| 106 | + service: |
| 107 | + labels: |
| 108 | + zarf.dev/connect-name: argocd |
| 109 | + annotations: |
| 110 | + zarf.dev/connect-description: "The Argocd UI service" |
| 111 | +``` |
| 112 | + |
| 113 | +This adds a label/annotation to the argocd server service which zarf can discover once deployed to the cluster. |
| 114 | + |
| 115 | +## Step 6: Build the Package |
| 116 | + |
| 117 | +With your `zarf.yaml` and `baseline-values.yaml` in place, build the package: |
| 118 | + |
| 119 | +```bash |
| 120 | +zarf package create . |
| 121 | +``` |
| 122 | + |
| 123 | +Zarf will pull down all referenced resources and bundle them into a package tarball. When it completes, list the directory to confirm: |
| 124 | + |
| 125 | +```bash |
| 126 | +ls |
| 127 | +``` |
| 128 | + |
| 129 | +You should see a file named something like `zarf-package-argocd-amd64-9.4.4.tar.zst` (the architecture segment will match your system). Zarf also embeds a Software Bill of Materials (SBOM) into each package automatically. |
| 130 | + |
| 131 | +--- |
| 132 | + |
| 133 | +## Reference Solution |
| 134 | + |
| 135 | +If you get stuck, a complete working solution is available in the [`solution/`](./solution/) directory. |
| 136 | + |
| 137 | +--- |
| 138 | + |
| 139 | +**Next:** [Part 2: Deploy a Zarf Package](../02-deploy-zarf-package/README.md) |
0 commit comments