Skip to content

Commit

Permalink
Fix configured build (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngreatorex authored Oct 21, 2023
1 parent 01c4c40 commit 094877a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 40 deletions.
28 changes: 19 additions & 9 deletions .github/workflows/build-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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' )"
Expand Down Expand Up @@ -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
Expand All @@ -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' )"
Expand All @@ -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 }}
52 changes: 21 additions & 31 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
Expand Down

0 comments on commit 094877a

Please sign in to comment.