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
pullRequestgenerator 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
How to Deploy a Preview to a Per-PR Kubernetes Namespace in GitHub ActionsDeploy an isolated preview onto Kubernetes for each pull request in GitHub Actions by creating a per-PR names…
How to Deploy a Multi-Service Preview Environment in GitHub ActionsBuild and deploy several services into one per-PR preview environment in GitHub Actions using a matrix to bui…