Skip to content

Instantly share code, notes, and snippets.

@hermannolafs
Created October 29, 2024 12:28
Show Gist options
  • Save hermannolafs/281c35a4826723c36ba60d1fb7560bfc to your computer and use it in GitHub Desktop.
Save hermannolafs/281c35a4826723c36ba60d1fb7560bfc to your computer and use it in GitHub Desktop.
GitHub action to build and push container and helm chart to ghcr.io
name: Example of building a container and it's relevant helm chart, and pushing to container registry
on:
release:
types: [ published ]
permissions:
contents: read
jobs:
container-build-and-push:
name: Build container and push
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
# ==================
# Container
# ==================
- name: Build and publish a Docker image for ${{ github.repository }}
uses: macbre/push-to-ghcr@master
with:
image_name: ${{ github.repository }} # it will be lowercased internally
github_token: ${{ secrets.GITHUB_TOKEN }}
# ==================
# Helm
# ==================
- name: Package Helm chart
working-directory: charts
run: |
helm package --dependency-update <INSERT CHART NAME> --version ${GITHUB_REF_NAME} --app-version ${GITHUB_REF_NAME} # Chart is code, thus chart is versioned with the code
- name: Login with ephemeral token to ghcr.io
working-directory: charts
run: |
echo ${{ secrets.GITHUB_TOKEN }} | helm registry login ghcr.io -u $ --password-stdin
- name: Push Helm chart to oci://ghcr.io
working-directory: charts
run: |
helm push <INSERT CHART NAME>-${GITHUB_REF_NAME}.tgz oci://ghcr.io/${GITHUB_REPOSITORY_OWNER}/charts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment