Last active
September 16, 2022 13:41
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }}" }}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The full JSON payload curled to the remote repository will contain a stanza like this:
The K8S deployment repository action looks up the service name in the appropriate YAML file, and sets the new version accordingly.