Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Digest Export and Manifest Creation for Multi-Arch Docker Builds #521

Draft
wants to merge 20 commits into
base: develop
Choose a base branch
from
Draft
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
142 changes: 64 additions & 78 deletions .github/workflows/docker-hub-platform.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
name: Build and Push Docker Image for Multiple Architectures

on:
# To enable manual triggering of this workflow
workflow_dispatch:

# Trigger for pushes to master and tags
push:
branches:
- master
- develop # TODO: Remove this
- develop
tags:
- 'v*.*.*'

Expand Down Expand Up @@ -38,94 +35,83 @@ jobs:
fetch-depth: 0

- name: Define Platform
id: define-platform
run: |
PLATFORM=${{ matrix.platform }}
PLATFORM_SAFE=${PLATFORM//\//-} # Replace slashes with dashes
echo "METACALL_PLATFORM=${PLATFORM}" >> $GITHUB_ENV
echo "METACALL_PLATFORM_PAIR=${PLATFORM//\//-}" >> $GITHUB_ENV
echo "METACALL_PLATFORM_PAIR=${PLATFORM_SAFE}" >> $GITHUB_ENV

- name: Docker Metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

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

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
# - name: Login to DockerHub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKER_HUB_USERNAME }}
# password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

- name: Build MetaCall Docker Images
run: bash ./docker-compose.sh platform

# # TODO: Build with alpine and provide multiple tags (debian & alpine) once all tests pass
# - name: Push MetaCall Docker Image to DockerHub
# run: |
# if [[ "${{ github.ref == 'refs/heads/master' }}" = true ]]; then
# bash ./docker-compose.sh push
# elif [[ "${{ contains(github.ref, 'refs/tags/') }}" = true ]]; then
# bash ./docker-compose.sh version
# else
# echo "Failed to push the docker images"
# exit 1
# fi

# - name: Export Digest
# run: |
# mkdir -p /tmp/digests
# digest="${{ steps.build.outputs.digest }}"
# touch "/tmp/digests/${digest#sha256:}"

# - name: Upload Digest
# uses: actions/upload-artifact@v4
# with:
# name: digests-${{ env.METACALL_PLATFORM_PAIR }}
# path: /tmp/digests/*
# if-no-files-found: error
# retention-days: 1

- name: Logout from DockerHub
run: docker logout

# merge:
# runs-on: ubuntu-latest
# needs:
# - build
# steps:
# - name: Download Digests
# uses: actions/download-artifact@v4
# with:
# path: /tmp/digests
# pattern: digests-*
# merge-multiple: true

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

# - name: Docker Metadata
# id: meta
# uses: docker/metadata-action@v5
# with:
# images: ${{ env.IMAGE_NAME }}

# - name: Login to DockerHub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKER_HUB_USERNAME }}
# password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

# - name: Create manifest list and push
# working-directory: /tmp/digests
# run: |
# docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
# $(printf '${{ env.IMAGE_NAME }}@sha256:%s ' *)

# - name: Inspect image
# run: |
# docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
- name: Export Digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build_image.outputs.digest }}"
touch "/tmp/digests/${METACALL_PLATFORM_PAIR}_${digest#sha256:}"

- name: Upload Digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.METACALL_PLATFORM_PAIR }}
path: /tmp/digests/*
retention-days: 1

merge:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download all digests
uses: actions/download-artifact@v4
with:
pattern: digests-*
path: /tmp/digests
merge-multiple: true

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

- name: Docker Metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}

- name: Create Manifest List (without pushing)
run: |
platforms=("linux-amd64" "linux-arm64" "linux-arm-v6" "linux-arm-v7")
manifests=""
for platform in "${platforms[@]}"; do
digest=$(cat /tmp/digests/${platform}_*)
manifests="${manifests} ${IMAGE_NAME}@${digest}"
done
echo "Would create manifest list with: ${manifests}"
echo "Would tag as: ${IMAGE_NAME}:${{ steps.meta.outputs.version }} and ${IMAGE_NAME}:latest"

- name: Simulate Image Inspection
run: |
echo "Would inspect: ${IMAGE_NAME}:${{ steps.meta.outputs.version }}"
echo "Would inspect: ${IMAGE_NAME}:latest"

# - name: Logout from DockerHub
# if: always()
# run: docker logout
Loading