How to Drive GitOps With Webhooks
Webhook-driven GitOps keeps Git as the source of truth: a build dispatches an event that bumps a manifest, and the reconciler syncs it.
On a successful build, POST a repository_dispatch to the environment repo. A workflow there updates the image tag in a manifest and commits, and the GitOps controller reconciles the cluster.
Steps
- Build and push the image with an immutable tag.
- Dispatch an event to the environment repo with the new tag.
- A workflow updates the manifest and commits; the controller reconciles.
Bump workflow
.github/workflows/bump.yml
on:
repository_dispatch:
types: [image-pushed]
jobs:
bump:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
yq -i '.image.tag = "${{ github.event.client_payload.tag }}"' deploy/values.yaml
git config user.name ci-bot
git commit -am "bump image to ${{ github.event.client_payload.tag }}"
git pushGotchas
- Use immutable tags (a digest or build id), not
latest, so the reconciler detects the change. - Scope the dispatch token to the environment repo only.
Related guides
How to Trigger CI From a Webhook With repository_dispatchTrigger a GitHub Actions workflow from an external system by POSTing a repository_dispatch event to the REST…
How to Send a Webhook on DeployNotify downstream systems on a successful deploy by POSTing a webhook from the final workflow step with the v…