From 78e7f7b3b799213fa74acf89c632f0f117d0b54f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Mon, 28 Oct 2024 14:19:53 +0100 Subject: [PATCH] feat: use checked in OCELOT_VERSION `workflow_dispatch` only works on the default branch which is inconvenient for development --- .env | 1 + .github/workflows/publish.yml | 34 +++++++------------ .gitignore | 1 - helmfile/environments/default.yaml.gotmpl | 4 +-- .../{image_tag.sh => branded_image_tag.sh} | 0 helmfile/scripts/ocelot_image_tag.sh | 6 ++++ 6 files changed, 21 insertions(+), 25 deletions(-) create mode 100644 .env delete mode 100644 .gitignore rename helmfile/scripts/{image_tag.sh => branded_image_tag.sh} (100%) create mode 100755 helmfile/scripts/ocelot_image_tag.sh diff --git a/.env b/.env new file mode 100644 index 0000000..76a9ce4 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +OCELOT_VERSION=sha-80ff4ef diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index cf2bde4..f67f8cb 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,16 +1,6 @@ name: publish -on: - workflow_dispatch: - inputs: - ocelot_version: - description: Ocelot build image version - required: true - type: string - deploy: - description: Deploy to cluster - required: true - type: boolean +on: push jobs: build-and-push-images: @@ -42,19 +32,21 @@ jobs: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Read $OCELOT_VERSION from file + run: cat .env >> $GITHUB_ENV - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@70b2cdc6480c1a8b86edf1777157f8f437de2166 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | - type=schedule,prefix=ocelot-${{ inputs.ocelot_version }}--branded- - type=semver,pattern={{version}},prefix=ocelot-${{ inputs.ocelot_version }}--branded- - type=semver,pattern={{major}}.{{minor}},prefix=ocelot-${{ inputs.ocelot_version }}--branded- - type=semver,pattern={{major}},prefix=ocelot-${{ inputs.ocelot_version }}--branded- - type=ref,event=branch,prefix=ocelot-${{ inputs.ocelot_version }}--branded- - type=ref,event=pr,prefix=ocelot-${{ inputs.ocelot_version }}--branded- - type=sha,prefix=ocelot-${{ inputs.ocelot_version }}--branded-sha- + type=schedule,prefix=ocelot-${{ env.OCELOT_VERSION }}--branded- + type=semver,pattern={{version}},prefix=ocelot-${{ env.OCELOT_VERSION }}--branded- + type=semver,pattern={{major}}.{{minor}},prefix=ocelot-${{ env.OCELOT_VERSION }}--branded- + type=semver,pattern={{major}},prefix=ocelot-${{ env.OCELOT_VERSION }}--branded- + type=ref,event=branch,prefix=ocelot-${{ env.OCELOT_VERSION }}--branded- + type=ref,event=pr,prefix=ocelot-${{ env.OCELOT_VERSION }}--branded- + type=sha,prefix=ocelot-${{ env.OCELOT_VERSION }}--branded-sha- - name: Build and push Docker images id: push uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 @@ -63,13 +55,13 @@ jobs: context: . push: true build-args: | - OCELOT_VERSION=${{ inputs.ocelot_version }} + OCELOT_VERSION=${{ env.OCELOT_VERSION }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} deploy-to-kubernetes: runs-on: ubuntu-latest - if: ${{ inputs.deploy }} + if: ${{ github.ref == 'refs/tags/staging' }} needs: build-and-push-images steps: - uses: mdgreenwald/mozilla-sops-action@d9714e521cbaecdae64a89d2fdd576dd2aa97056 # v1.6.0 @@ -84,8 +76,6 @@ jobs: sops decrypt ./helmfile/secrets/kubeconfig > ~/.kube/config chmod 600 ~/.kube/config - uses: helmfile/helmfile-action@80fbb6408b98822310f94d8d1321a2cacf87f78f #v1.9.2 - env: - OCELOT_IMAGE_TAG: ${{ inputs.ocelot_version }} with: helmfile-args: apply helmfile-workdirectory: ./helmfile diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 4c49bd7..0000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.env diff --git a/helmfile/environments/default.yaml.gotmpl b/helmfile/environments/default.yaml.gotmpl index 35beae5..ff14844 100644 --- a/helmfile/environments/default.yaml.gotmpl +++ b/helmfile/environments/default.yaml.gotmpl @@ -1,5 +1,5 @@ -{{ $branded_image_tag:= env "BRANDED_IMAGE_TAG" | default (exec "../scripts/image_tag.sh" (list) | trim) }} -{{ $ocelot_image_tag := env "OCELOT_IMAGE_TAG" | default "master" }} +{{ $branded_image_tag:= env "BRANDED_IMAGE_TAG" | default (exec "../scripts/branded_image_tag.sh" (list) | trim) }} +{{ $ocelot_image_tag := env "OCELOT_IMAGE_TAG" | default (exec "../scripts/ocelot_image_tag.sh" (list) | trim) }} domain: staging.ocelot-social.roschaefer.de namespace: ocelot-staging diff --git a/helmfile/scripts/image_tag.sh b/helmfile/scripts/branded_image_tag.sh similarity index 100% rename from helmfile/scripts/image_tag.sh rename to helmfile/scripts/branded_image_tag.sh diff --git a/helmfile/scripts/ocelot_image_tag.sh b/helmfile/scripts/ocelot_image_tag.sh new file mode 100755 index 0000000..6cc9baa --- /dev/null +++ b/helmfile/scripts/ocelot_image_tag.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +SCRIPT_PATH=$(realpath $0) +SCRIPT_DIR=$(dirname $SCRIPT_PATH) + +set -a; . ${SCRIPT_DIR}/../../.env; set +a; +echo $OCELOT_VERSION