Skip to content
Latchkey

How to Generate Preview Environments With an Argo CD ApplicationSet in GitHub Actions

The ApplicationSet pull request generator watches open PRs and materializes one Argo CD Application per PR, tearing it down on close.

Instead of deploying from CI, let Argo CD own preview lifecycle. The pullRequest generator lists open PRs and templates an Application per PR. GitHub Actions only builds and pushes the per-PR image tag the generator references.

Steps

  • Add a pullRequest generator scoped to your repo.
  • Template an Application using {{number}} and {{head_sha}}.
  • Have CI push an image tagged with the PR head SHA.

ApplicationSet

applicationset.yaml
apiVersion: argoproj.io/v1alpha1
kind: ApplicationSet
metadata:
  name: previews
spec:
  generators:
    - pullRequest:
        github:
          owner: my-org
          repo: my-app
        requeueAfterSeconds: 60
  template:
    metadata:
      name: preview-{{number}}
    spec:
      project: default
      source:
        repoURL: https://github.com/my-org/my-app
        targetRevision: '{{head_sha}}'
        path: chart
      destination:
        server: https://kubernetes.default.svc
        namespace: pr-{{number}}
      syncPolicy:
        automated: {}
        syncOptions: [CreateNamespace=true]

Gotchas

  • The generator creates and deletes Applications as PRs open and close, so no teardown workflow is needed.
  • CI must push the image before Argo CD syncs, or the pod stays in ImagePullBackOff.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →