Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 67 additions & 9 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,30 @@ on:

env:
DOCKER_IMAGE: insprill/intellectual
DOCKER_PLATFORMS: linux/amd64,linux/arm64
DOCKER_TAG: ${{ startsWith(github.ref, 'refs/tags/v') && 'latest' || 'develop' }}

jobs:
build-docker:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
- platform: linux/arm64
runner: ubuntu-24.04-arm
runs-on: ${{ matrix.runner }}
outputs:
push: ${{ env.DOCKER_PUSH }}
steps:
- name: Checkout Repository
uses: actions/checkout@v7

- name: Set Docker push status
run: echo "DOCKER_PUSH=${{ !env.ACT && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')) && github.event_name != 'pull_request' }}" >> $GITHUB_ENV
run: |
echo "DOCKER_PUSH=${{ !env.ACT && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')) && github.event_name != 'pull_request' }}" >> $GITHUB_ENV
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV

- name: Setup act
run: "sudo chown runner:docker /var/run/docker.sock"
Expand Down Expand Up @@ -54,12 +67,57 @@ jobs:
echo "IN_GIT_TAGGED=$([[ -n $(git describe --tags --exact-match) ]] && echo true || echo false)" >> .env
echo "IN_GIT_REMOTE_URL=$(git remote get-url origin)" >> .env

- name: Build & Push
- name: Build & Push by digest
id: build
uses: docker/build-push-action@v7
with:
context: . # Required for running with act
push: ${{ env.DOCKER_PUSH == 'true' }}
tags: ${{ env.DOCKER_IMAGE }}:${{ startsWith(github.ref, 'refs/tags/v') && 'latest' || 'develop' }}
platforms: ${{ env.DOCKER_PLATFORMS }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ env.DOCKER_IMAGE }}
platforms: ${{ matrix.platform }}
outputs: type=image,push-by-digest=true,name-canonical=true,push=${{ env.DOCKER_PUSH }}
# Each platform needs its own scope, or the two builds overwrite each other's cache
cache-from: type=gha,scope=${{ env.PLATFORM_PAIR }}
cache-to: type=gha,mode=max,scope=${{ env.PLATFORM_PAIR }}

- name: Export digest
if: ${{ env.DOCKER_PUSH == 'true' }}
run: |
mkdir -p ${{ runner.temp }}/digests
digest="${{ steps.build.outputs.digest }}"
touch "${{ runner.temp }}/digests/${digest#sha256:}"

- name: Upload digest
if: ${{ env.DOCKER_PUSH == 'true' }}
uses: actions/upload-artifact@v7
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1

merge-docker:
runs-on: ubuntu-latest
needs: build-docker
if: ${{ needs.build-docker.outputs.push == 'true' }}
steps:
- name: Download digests
uses: actions/download-artifact@v8
with:
path: ${{ runner.temp }}/digests
pattern: digests-*
merge-multiple: true

- name: Login to DockerHub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4

- name: Create manifest list & Push
working-directory: ${{ runner.temp }}/digests
run: |
docker buildx imagetools create -t ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }} \
$(printf '${{ env.DOCKER_IMAGE }}@sha256:%s ' *)
Loading