Skip to content

Commit

Permalink
Refactor GitHub Actions workflow for multi-architecture Docker builds
Browse files Browse the repository at this point in the history
- Streamlined the Docker build process by organizing steps and removing redundant configurations.
- Enhanced artifact preparation by ensuring executable permissions for architecture-specific binaries.
- Maintained support for multi-architecture builds (amd64 and arm64) while improving clarity and efficiency in the workflow.

These changes optimize the CI/CD pipeline, facilitating seamless builds across different architectures.
  • Loading branch information
Joachim Rosskopf committed Dec 28, 2024
1 parent 0925175 commit 8fbf56f
Showing 1 changed file with 53 additions and 71 deletions.
124 changes: 53 additions & 71 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,77 +67,59 @@ jobs:
# Docker Build and Push Multi-Arch
# -------------------------------------------------------------------------------------------------
docker-build:
needs: [linux-build]
runs-on: ubuntu-24.04
strategy:
matrix:
platform: [linux/amd64, linux/arm64]
steps:
- uses: actions/checkout@v4

- name: Prepare
run: echo "REPO_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64,amd64

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ env.REPO_OWNER }}/flapi
tags: |
type=raw,value=latest
type=sha,format=long
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts

- name: Prepare artifacts
run: |
mkdir -p binaries/amd64 binaries/arm64
cp artifacts/flapi-linux-amd64/flapi binaries/amd64/
cp artifacts/flapi-linux-arm64/flapi binaries/arm64/
# Verify binaries
file binaries/amd64/flapi
file binaries/arm64/flapi
chmod +x binaries/amd64/flapi binaries/arm64/flapi
- name: Build and push multi-arch image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}-${{ contains(matrix.platform, 'arm64') && 'arm64' || 'amd64' }}
labels: ${{ steps.meta.outputs.labels }}
build-contexts: |
build=binaries/${{ contains(matrix.platform, 'arm64') && 'arm64' || 'amd64' }}
- name: Create and push multi-arch manifest
# Only run this step once after all architectures are built
if: matrix.platform == 'linux/amd64'
run: |
docker buildx imagetools create -t ${{ steps.meta.outputs.tags }} \
${{ steps.meta.outputs.tags }}-amd64 \
${{ steps.meta.outputs.tags }}-arm64
needs: [linux-build]
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4

- name: Prepare
run: echo "REPO_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV

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

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

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ env.REPO_OWNER }}/flapi
tags: |
type=raw,value=latest
type=sha,format=long
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts

- name: Prepare artifacts
run: |
mkdir -p binaries/amd64 binaries/arm64
cp artifacts/flapi-linux-amd64/flapi binaries/amd64/
cp artifacts/flapi-linux-arm64/flapi binaries/arm64/
chmod +x binaries/amd64/flapi binaries/arm64/flapi
- name: Build and push multi-arch image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-contexts: |
build=binaries
# -------------------------------------------------------------------------------------------------
# macOS Universal
Expand Down

0 comments on commit 8fbf56f

Please sign in to comment.