From 094877a67c90364815f5e2cc60200bb92466fcd3 Mon Sep 17 00:00:00 2001 From: Neil Greatorex Date: Sat, 21 Oct 2023 17:58:28 +0100 Subject: [PATCH] Fix configured build (#19) --- .github/workflows/build-docker-image.yml | 28 +++++++++---- .github/workflows/docker.yml | 52 ++++++++++-------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index d4178b1..132d670 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -38,16 +38,26 @@ on: outputs: tag: description: 'The first tag generated by Docker for this build' - value: ${{ jobs.build-image.outputs.tag }} + value: ${{ jobs.merge.outputs.tag }} secrets: DOCKERHUB_TOKEN: description: 'The token used to access Docker hub' required: false jobs: + generate-id: + name: Generate unique ID for this run + runs-on: ubuntu-latest + steps: + - name: Generate ID + id: id + run: 'printf "id=%s\n" `uuidgen` >> ${GITHUB_OUTPUT}' + outputs: + id: ${{ steps.id.outputs.id }} build: name: Build Docker image runs-on: ubuntu-latest + needs: generate-id strategy: fail-fast: false matrix: @@ -62,10 +72,6 @@ jobs: uses: docker/metadata-action@v5 with: images: ${{ inputs.image }} - - name: Get first tag - id: first-tag - run: | - echo -e ${{ toJson(steps.meta.outputs.tags) }} | { mapfile -t; echo "tag=${MAPFILE[0]}" >> $GITHUB_OUTPUT; echo "First tag: ${MAPFILE[0]}"; } - name: Login to Docker Hub uses: docker/login-action@v3 if: "!contains( inputs.image, 'ghcr.io' )" @@ -107,22 +113,21 @@ jobs: - name: Upload digest uses: actions/upload-artifact@v3 with: - name: digests + name: digests-${{ needs.generate-id.outputs.id }} path: /tmp/digests/* if-no-files-found: error retention-days: 1 - outputs: - tag: ${{ steps.first-tag.outputs.tag }} merge: name: Merge manifests runs-on: ubuntu-latest needs: + - generate-id - build steps: - name: Download digests uses: actions/download-artifact@v3 with: - name: digests + name: digests-${{ needs.generate-id.outputs.id }} path: /tmp/digests - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -133,6 +138,9 @@ jobs: images: ${{ inputs.image }} tags: ${{ inputs.tags }} flavor: ${{ inputs.flavor }} + - name: Get first tag + id: first-tag + run: 'echo -e ${{ toJson(steps.meta.outputs.tags) }} | { mapfile -t; echo "tag=${MAPFILE[0]}" >> $GITHUB_OUTPUT; echo "First tag: ${MAPFILE[0]}"; }' - name: Login to Docker Hub uses: docker/login-action@v3 if: "!contains( inputs.image, 'ghcr.io' )" @@ -154,3 +162,5 @@ jobs: - name: Inspect image run: | docker buildx imagetools inspect ${{ inputs.image }}:${{ steps.meta.outputs.version }} + outputs: + tag: ${{ steps.first-tag.outputs.tag }} diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 32213b6..ea14c29 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -11,44 +11,35 @@ on: jobs: - enumerate-configs: - name: Enumerate configs + configure-jobs: + name: Configure jobs runs-on: ubuntu-latest + env: + docker.io-image: ngreatorex/homie-streamdeck + ghcr-image: ghcr.io/ngreatorex/homie-streamdeck steps: - name: Checkout uses: actions/checkout@v4 - id: set-matrix - name: Generate matrix with all configured Dockerfiles + name: Enumerate all configured Dockerfiles run: | echo "matrix=$(ls -l config/Dockerfile.* | grep '^-' | awk -F ' ' '{print $9}' | { read x; echo "${x##*.}"; } | jq -R -s -c 'split("\n") | map(select(length > 0))')" >> $GITHUB_OUTPUT + - id: set-image + name: Choose repository for Docker image + run: | + [ "${{ github.event_name == 'pull_request' }}" = "true" ] && echo "image=${{ env.ghcr-image }}" >> $GITHUB_OUTPUT || true + [ "${{ github.event_name != 'pull_request' }}" = "true" ] && echo "image=${{ env.docker.io-image }}" >> $GITHUB_OUTPUT || true outputs: matrix: ${{ steps.set-matrix.outputs.matrix }} + image: ${{ steps.set-image.outputs.image }} - build-base-image-docker-hub: - name: Build base image for Docker hub - needs: enumerate-configs - uses: ./.github/workflows/build-docker-image.yml - if: ${{ github.event_name != 'pull_request' }} - with: - platforms: ${{ vars.DOCKER_PLATFORMS }} - image: ngreatorex/homie-streamdeck - tags: | - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=semver,pattern={{major}} - type=sha - secrets: inherit - - build-base-image-ghcr: - name: Build base image for GitHub Container Registry - needs: enumerate-configs + build-base-image: + name: Build base image + needs: configure-jobs uses: ./.github/workflows/build-docker-image.yml - if: ${{ github.event_name == 'pull_request' }} with: platforms: ${{ vars.DOCKER_PLATFORMS }} - image: ghcr.io/${{ github.actor }}/homie-streamdeck + image: ${{ needs.configure-jobs.outputs.image }} tags: | type=ref,event=branch type=ref,event=pr @@ -60,19 +51,18 @@ jobs: build-configured-images: name: Build configured images - if: "github.event_name != 'pull_request' && ${{ always() }}" + #if: "github.event_name != 'pull_request'" needs: - - enumerate-configs - - build-base-image-docker-hub - - build-base-image-ghcr + - configure-jobs + - build-base-image strategy: fail-fast: false matrix: - config-name: ${{ fromJson(needs.enumerate-configs.outputs.matrix) }} + config-name: ${{ fromJson(needs.configure-jobs.outputs.matrix) }} uses: ./.github/workflows/build-docker-image.yml with: build-args: | - FROM_IMAGE=${{ needs.build-base-image-docker-hub.outputs.tag || needs.build-base-image-ghcr.outputs.tag }} + FROM_IMAGE=${{ needs.build-base-image.outputs.tag }} image: ghcr.io/${{ github.actor }}/homie-streamdeck-configured flavor: | suffix=_${{ matrix.config-name }}