From e7c17880beeb459713c2f13e246b65e7d3243791 Mon Sep 17 00:00:00 2001 From: ewelinagr Date: Mon, 13 May 2024 12:30:53 +0200 Subject: [PATCH] Add github action to build and upload theme Docker images. --- ...build_and_upload_theme_on_push_to_dev.yaml | 69 +++++++++++++++++++ themes/VERSION | 1 + 2 files changed, 70 insertions(+) create mode 100644 .github/workflows/build_and_upload_theme_on_push_to_dev.yaml create mode 100644 themes/VERSION diff --git a/.github/workflows/build_and_upload_theme_on_push_to_dev.yaml b/.github/workflows/build_and_upload_theme_on_push_to_dev.yaml new file mode 100644 index 0000000..19534ba --- /dev/null +++ b/.github/workflows/build_and_upload_theme_on_push_to_dev.yaml @@ -0,0 +1,69 @@ +# Jobs to build and deploy a Docker image for Fairspace Keycloak theme on push to the dev or release branches + +name: Build & Upload Fairspace Keycloak Theme Docker image + +env: + DOCKER_REGISTRY: ghcr.io + +on: + push: + branches: + - dev + - release + +jobs: + # A job to generate one shared unique version tag per build cycle for all built artifacts + generate-version: + runs-on: ubuntu-latest + outputs: + output1: ${{ steps.version.outputs.keycloak_fairspace_theme_version }} + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - id: version + name: Generating version tag for artifacts + run: | + # EXTRACT VERSION + BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} + echo "Building theme image from the branch: $BRANCH" + VER=$(cat ./themes/VERSION) + echo "Building theme image of version: $VER" + + # DOCKER TAG TO BE ATTACHED (SHARED WITHIN OUTPUT): + if [ $BRANCH != "release" ] + then + VER=$VER-SNAPSHOT + fi + + echo "keycloak_fairspace_theme_version=$VER" >> "$GITHUB_OUTPUT" + echo "Docker tag to be attached to images: $VER" + + + build-and-upload-docker-image-for-keycloak-fairspace-theme: + needs: [generate-version] + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.DOCKER_REGISTRY }} + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.DOCKER_REGISTRY }}/${{ github.repository }}/keycloak-fairspace-theme + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: ./themes/ + push: true + tags: ${{ env.DOCKER_REGISTRY }}/${{ github.repository }}/keycloak-fairspace-theme:${{needs.generate-version.outputs.output1}} + labels: ${{ steps.meta.outputs.labels }} diff --git a/themes/VERSION b/themes/VERSION new file mode 100644 index 0000000..8acdd82 --- /dev/null +++ b/themes/VERSION @@ -0,0 +1 @@ +0.0.1