diff --git a/.github/workflows/images.yaml b/.github/workflows/images.yaml index 2b2d04c8..814b609f 100644 --- a/.github/workflows/images.yaml +++ b/.github/workflows/images.yaml @@ -8,6 +8,23 @@ on: - v* jobs: + helm-oci: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: azure/setup-helm@v4.3.0 + - name: Push artifacts + run: PUSH=true hack/push-artifacts.sh ghcr.io/stackitcloud/yawol/yawol-controller build: runs-on: ubuntu-latest permissions: diff --git a/.gitignore b/.gitignore index eb3b04c3..2b9ea8dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +artifacts + # Binaries for programs and plugins *.exe *.exe~ diff --git a/hack/push-artifacts.sh b/hack/push-artifacts.sh new file mode 100755 index 00000000..4cb7c784 --- /dev/null +++ b/hack/push-artifacts.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail + +chart_name=yawol-controller +helm_artifacts=artifacts/charts +rm -rf "$helm_artifacts" +mkdir -p "$helm_artifacts" + +function image_registry() { + echo "$1" | cut -d '/' -f -2 +} + +function image_repo() { + echo "$1" | cut -d ':' -f 1 +} + +function image_tag() { + git describe --tag --always --dirty +} + +## HELM +cp -r charts/${chart_name} "$helm_artifacts" +yq -i "\ + ( .image.repository = \"$(image_repo "$1")\" ) | \ + ( .image.tag = \"$(image_tag "$1")\" )\ +" "$helm_artifacts/${chart_name}/values.yaml" + +# push to registry +if [ "${PUSH:=}" != "true" ] ; then + echo "Skip pushing artifacts because PUSH is not set to 'true'" + exit 0 +fi + +helm package "$helm_artifacts/${chart_name}" --version "$(image_tag "$1")" -d "$helm_artifacts" > /dev/null 2>&1 +helm push "$helm_artifacts/${chart_name}-"* "oci://$(image_registry "$1")/charts"