Skip to content

Instantly share code, notes, and snippets.

@nmagee
Last active September 16, 2022 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmagee/c09565f87ef208ea451935df12576a6b to your computer and use it in GitHub Desktop.
Save nmagee/c09565f87ef208ea451935df12576a6b to your computer and use it in GitHub Desktop.
A template snippet for GitHub action that triggers a K8S deployment via ArgoCD
name: Container Build CICD
on:
push:
branches:
- 'main'
env:
REGISTRY: ghcr.io
IMAGE_NAME: org/container-name
IMAGE_TAG: 1.${{ github.run_number }} # creates new version number 1. + GITHUB_RUN_NUMBER
SVC_NAME: idGenerator # used in finding YAML value to update
jobs:
build:
runs-on: ubuntu-latest
steps:
. . . Do things to build + push . . .
# Update a YAML value in remote repo so that ArgoCD deploys the new version.
# Requires a GHCR PAT that has appropriate permissions and stored as a SECRET for the repo.
- name: Remote Dispatch
run: |
curl -X POST https://api.github.com/repos/<ORG>/<REPO>/dispatches \
-H 'Accept: application/vnd.github.everest-preview+json' \
-H "Authorization: token ${{ secrets.GHCR_PAT }}" \
--data '{"event_type": "${{ env.IMAGE_NAME }} update to ${{ env.IMAGE_TAG }}", "client_payload": { "service": "${{ env.SVC_NAME }}", "version": "${{ env.IMAGE_TAG }}" }}'
@nmagee
Copy link
Author

nmagee commented Sep 16, 2022

The full JSON payload curled to the remote repository will contain a stanza like this:

{ 
  "client_payload": { 
    "service": "nginxService",
    "version": 1.14"
  }
}

The K8S deployment repository action looks up the service name in the appropriate YAML file, and sets the new version accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment