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

docker: build multi-platform container #1352

Merged
merged 3 commits into from
Mar 5, 2025
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
128 changes: 96 additions & 32 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@ on:
tags:
- '*'

env:
WORKFLOW_BUILD_DISTROLESS: false

jobs:
docker:
runs-on: ubuntu-latest
build:
name: build ${{ matrix.platform }} container
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
os: ubuntu-latest
- platform: linux/arm64
os: ubuntu-24.04-arm
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Prepare
run: |
echo "PLATFORM_PAIR=${PLATFORM//\//-}" >> "$GITHUB_ENV"
env:
PLATFORM: "${{ matrix.platform }}"

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand All @@ -35,16 +44,13 @@ jobs:
type=ref,event=branch,prefix=testing-
type=edge

- name: Set Docker metadata (Distroless variant)
id: meta-distroless
uses: docker/metadata-action@v5
if: ${{ env.WORKFLOW_BUILD_DISTROLESS == true }}
with:
images: ghcr.io/${{ github.repository }}/distroless
tags: |
type=ref,event=tag
type=ref,event=branch,prefix=testing-
type=edge
- name: Extract image names (Ubuntu & NVM variant)
id: name-ubuntu
run: |
{
echo -n "name="
jq -cr '.tags | map(split(":")[0]) | unique | join(",")' <<< "$DOCKER_METADATA_OUTPUT_JSON"
} >> "$GITHUB_OUTPUT"

- name: GitHub Container Registry Login
uses: docker/login-action@v3
Expand All @@ -62,27 +68,85 @@ jobs:

- name: Docker Build and Push (Ubuntu & NVM variant)
uses: docker/build-push-action@v6
id: build-ubuntu
with:
platforms: linux/amd64
platforms: ${{ matrix.platform }}
target: final-ubuntu
file: docker/Dockerfile
pull: true
push: true
tags: ${{ steps.meta-ubuntu.outputs.tags }}
outputs: type=image,"name=${{ steps.name-ubuntu.outputs.name }}",push-by-digest=true,push=true
labels: ${{ steps.meta-ubuntu.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Docker Build and Push (Distroless variant)
uses: docker/build-push-action@v6
if: ${{ env.WORKFLOW_BUILD_DISTROLESS == true }}
- name: Export digest
run: |
mkdir -p "$RUNNER_TEMP/digests/ubuntu"
touch "$RUNNER_TEMP/digests/ubuntu/${DIGEST_UBUNTU#sha256:}"
env:
DIGEST_UBUNTU: "${{ steps.build-ubuntu.outputs.digest }}"

- name: Upload digest
uses: actions/upload-artifact@v4
with:
platforms: linux/amd64
target: final-distroless
file: docker/Dockerfile
pull: true
push: true
tags: ${{ steps.meta-distroless.outputs.tags }}
labels: ${{ steps.meta-distroless.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
name: digests-${{ env.PLATFORM_PAIR }}
path: ${{ runner.temp }}/digests/*
if-no-files-found: error
retention-days: 1

merge:
name: merge containers
runs-on: ubuntu-latest
needs:
- build
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: ${{ runner.temp }}/digests
pattern: digests-*
merge-multiple: true

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

- name: Docker Hub Login
uses: docker/login-action@v3
if: github.repository == 'crytic/echidna'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}

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

- name: Set Docker metadata (Ubuntu & NVM variant)
id: meta-ubuntu
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository }}/echidna
name=trailofbits/echidna,enable=${{ github.repository == 'crytic/echidna' }}
tags: |
type=ref,event=tag
type=ref,event=branch,prefix=testing-
type=edge

- name: Create manifest list and push (Ubuntu & NVM variant)
working-directory: ${{ runner.temp }}/digests/ubuntu
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf "$IMAGE_NAME@sha256:%s " *)
env:
IMAGE_NAME: ghcr.io/${{ github.repository }}/echidna

- name: Inspect image (Ubuntu & NVM variant)
run: |
docker buildx imagetools inspect "$IMAGE_NAME:$VERSION"
env:
IMAGE_NAME: "ghcr.io/${{ github.repository }}/echidna"
VERSION: "${{ steps.meta-ubuntu.outputs.version }}"