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

workflows: split into per-arch container builds #9876

Merged
merged 3 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
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
208 changes: 148 additions & 60 deletions .github/workflows/call-build-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ on:
registry:
description: The registry to push container images to.
type: string
required: true
required: false
default: ghcr.io
username:
description: The username for the registry.
type: string
Expand All @@ -33,11 +34,6 @@ on:
type: string
required: false
default: ""
platforms:
description: The platforms to build for
type: string
required: false
default: 'linux/amd64, linux/arm64, linux/arm/v7, linux/s390x'
secrets:
token:
description: The Github token or similar to authenticate with for the registry.
Expand Down Expand Up @@ -74,25 +70,34 @@ jobs:
replace-with: "$1"
flags: "g"

# This is the intended approach to multi-arch image and all the other checks scanning,
# signing, etc only trigger from this.
call-build-images:
needs:
- call-build-images-meta
name: Multiarch container images to GHCR
runs-on: ubuntu-latest-8-cores
environment: ${{ inputs.environment }}
# Taken from https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners
# We split this out to make it easier to restart just one of them if it fails and do all in parallel
call-build-single-arch-container-images:
# Allow us to continue to create a manifest if we want
continue-on-error: true
permissions:
contents: read
packages: write
outputs:
production-digest: ${{ steps.build_push.outputs.digest }}
debug-digest: ${{ steps.debug_build_push.outputs.digest }}
strategy:
fail-fast: false
matrix:
platform:
- amd64
- arm64
- arm/v7
- s390x
target:
- production
- debug
name: ${{ matrix.platform }}/${{ matrix.target }} container image build
# Use GitHub Actions ARM hosted runners
runs-on: ${{ (contains(matrix.platform, 'arm') && 'ubuntu-22.04-arm') || 'ubuntu-latest' }}
steps:
- name: Checkout code for modern style builds
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
token: ${{ secrets.token }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -104,37 +109,108 @@ jobs:
uses: docker/login-action@v3
with:
registry: ${{ inputs.registry }}
username: ${{ inputs.username }}
username: ${{ github.actor }}
password: ${{ secrets.token }}

- name: Extract metadata from Github
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ inputs.registry }}/${{ inputs.image }}
tags: |
raw,${{ inputs.version }}
raw,${{ needs.call-build-images-meta.outputs.major-version }}
raw,latest

- name: Build the production images
id: build_push
- name: Build and push by digest the standard ${{ matrix.target }} image
id: build
uses: docker/build-push-action@v6
with:
# Use path context rather than Git context as we want local files
file: ./dockerfiles/Dockerfile
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ inputs.platforms }}
target: production
target: ${{ matrix.target }}
outputs: type=image,name=${{ inputs.registry }}/${{ inputs.image }},push-by-digest=true,name-canonical=true,push=true
platforms: linux/${{ matrix.platform }}
# Must be disabled to provide legacy format images from the registry
provenance: false
push: true
load: false
build-args: |
FLB_NIGHTLY_BUILD=${{ inputs.unstable }}
RELEASE_VERSION=${{ inputs.version }}
WAMR_BUILD_TARGET=${{ (contains(matrix.platform, 'arm/v7') && 'ARMV7') || '' }}

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

- name: Upload ${{ matrix.target }} digest
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}-digests-${{ (contains(matrix.platform, 'arm/v7') && 'arm-v7') || matrix.platform }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

# Take the digests and produce a multi-arch manifest from them.
call-build-container-image-manifests:
permissions:
contents: read
packages: write
name: Upload multi-arch container image manifests
runs-on: ubuntu-latest
needs:
- call-build-images-meta
- call-build-single-arch-container-images
outputs:
version: ${{ steps.meta.outputs.version }}
steps:
- name: Extract metadata from Github
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ inputs.registry }}/${{ inputs.image }}
tags: |
raw,${{ inputs.version }}
raw,${{ needs.call-build-images-meta.outputs.major-version }}
raw,latest

- name: Download production digests
uses: actions/download-artifact@v4
with:
pattern: production-digests-*
path: /tmp/production-digests
merge-multiple: true

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

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ inputs.registry }}
username: ${{ github.actor }}
password: ${{ secrets.token }}

- name: Create production manifest
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ inputs.registry }}/${{ inputs.image }}@sha256:%s ' *)
shell: bash
working-directory: /tmp/production-digests

- name: Inspect image
run: |
docker buildx imagetools inspect ${{ inputs.registry }}/${{ inputs.image }}:${{ steps.meta.outputs.version }}
shell: bash

# Take the digests and produce a multi-arch manifest from them.
call-build-debug-container-image-manifests:
permissions:
contents: read
packages: write
name: Upload debug multi-arch container image manifests
runs-on: ubuntu-latest
needs:
- call-build-images-meta
- call-build-single-arch-container-images
outputs:
version: ${{ steps.debug-meta.outputs.version }}
steps:
- id: debug-meta
uses: docker/metadata-action@v5
with:
Expand All @@ -144,28 +220,39 @@ jobs:
raw,${{ needs.call-build-images-meta.outputs.major-version }}-debug
raw,latest-debug

- name: Build the debug multi-arch images
id: debug_build_push
uses: docker/build-push-action@v6
- name: Download debug digests
uses: actions/download-artifact@v4
with:
file: ./dockerfiles/Dockerfile
context: .
tags: ${{ steps.debug-meta.outputs.tags }}
labels: ${{ steps.debug-meta.outputs.labels }}
platforms: ${{ inputs.platforms }}
# Must be disabled to provide legacy format images from the registry
provenance: false
target: debug
push: true
load: false
build-args: |
FLB_NIGHTLY_BUILD=${{ inputs.unstable }}
RELEASE_VERSION=${{ inputs.version }}
pattern: production-digests-*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo here, should be debug prefix

path: /tmp/debug-digests
merge-multiple: true

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

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ inputs.registry }}
username: ${{ github.actor }}
password: ${{ secrets.token }}

- name: Create debug manifest
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ inputs.registry }}/${{ inputs.image }}@sha256:%s ' *)
shell: bash
working-directory: /tmp/debug-digests

- name: Inspect image
run: |
docker buildx imagetools inspect ${{ inputs.registry }}/${{ inputs.image }}:${{ steps.debug-meta.outputs.version }}
shell: bash

call-build-images-generate-schema:
needs:
- call-build-images-meta
- call-build-images
- call-build-container-image-manifests
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
permissions:
Expand Down Expand Up @@ -195,7 +282,7 @@ jobs:
call-build-images-scan:
needs:
- call-build-images-meta
- call-build-images
- call-build-container-image-manifests
name: Trivy + Dockle image scan
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
Expand Down Expand Up @@ -230,7 +317,8 @@ jobs:
call-build-images-sign:
needs:
- call-build-images-meta
- call-build-images
- call-build-container-image-manifests
- call-build-debug-container-image-manifests
name: Deploy and sign multi-arch container image manifests
permissions:
contents: read
Expand All @@ -251,13 +339,13 @@ jobs:
#
# We use recursive signing on the manifest to cover all the images.
run: |
cosign sign --recursive \
cosign sign --recursive --force \
-a "repo=${{ github.repository }}" \
-a "workflow=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
-a "ref=${{ github.sha }}" \
-a "release=${{ inputs.version }}" \
"${{ inputs.registry }}/${{ inputs.image }}@${{ needs.call-build-images.outputs.production-digest }}" \
"${{ inputs.registry }}/${{ inputs.image }}@${{ needs.call-build-images.outputs.debug-digest }}"
"${{ inputs.registry }}/${{ inputs.image }}@${{ needs.call-build-container-image-manifests.outputs.version }}" \
"${{ inputs.registry }}/${{ inputs.image }}@${{ needs.call-build-debug-container-image-manifests.outputs.version }}"
shell: bash
# Ensure we move on to key-based signing as well
continue-on-error: true
Expand All @@ -270,13 +358,13 @@ jobs:
# The key needs to cope with newlines
run: |
echo -e "${COSIGN_PRIVATE_KEY}" > /tmp/my_cosign.key
cosign sign --key /tmp/my_cosign.key --recursive \
cosign sign --key /tmp/my_cosign.key --recursive --force \
-a "repo=${{ github.repository }}" \
-a "workflow=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
-a "ref=${{ github.sha }}" \
-a "release=${{ inputs.version }}" \
"${{ inputs.registry }}/${{ inputs.image }}@${{ needs.call-build-images.outputs.production-digest }}" \
"${{ inputs.registry }}/${{ inputs.image }}@${{ needs.call-build-images.outputs.debug-digest }}"
"${{ inputs.registry }}/${{ inputs.image }}@${{ needs.call-build-container-image-manifests.outputs.version }}" \
"${{ inputs.registry }}/${{ inputs.image }}@${{ needs.call-build-debug-container-image-manifests.outputs.version }}"
rm -f /tmp/my_cosign.key
shell: bash
continue-on-error: true
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/pr-package-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ jobs:
- name: Debug event output
uses: hmarr/debug-action@v3

pr-container-builds:
name: PR - container builds
needs:
- pr-package-test-build-get-meta
- pr-package-test-build-generate-matrix
uses: ./.github/workflows/call-build-images.yaml
with:
version: pr-${{ github.event.number }}
ref: ${{ github.ref }}
registry: ghcr.io
username: ${{ github.actor }}
image: ${{ github.repository }}/pr
unstable: ${{ needs.pr-package-test-build-get-meta.outputs.date }}
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
cosign_private_key: ${{ secrets.COSIGN_PRIVATE_KEY }}
cosign_private_key_password: ${{ secrets.COSIGN_PASSWORD }}

pr-package-test-build-generate-matrix:
name: PR - packages build matrix
needs:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/staging-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ jobs:
username: ${{ github.actor }}
image: ${{ github.repository }}/staging
environment: staging
platforms: 'linux/amd64, linux/arm64'
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
cosign_private_key: ${{ secrets.COSIGN_PRIVATE_KEY }}
Expand Down
17 changes: 15 additions & 2 deletions dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# docker buildx build --platform "linux/amd64,linux/arm64,linux/arm/v7,linux/s390x" -f ./dockerfiles/Dockerfile.multiarch --build-arg FLB_TARBALL=https://github.com/fluent/fluent-bit/archive/v1.8.11.tar.gz ./dockerfiles/

# Set this to the current release version: it gets done so as part of the release.
ARG RELEASE_VERSION=3.2.5
ARG RELEASE_VERSION=3.2.4

# For multi-arch builds - assumption is running on an AMD64 host
FROM multiarch/qemu-user-static:x86_64-arm AS qemu-arm32
Expand Down Expand Up @@ -66,7 +66,16 @@ COPY . ./
# We split the builder setup out so people can target it or use as a base image without doing a full build.
FROM builder-base AS builder
WORKDIR /src/fluent-bit/build/
RUN cmake -DFLB_RELEASE=On \

# Required to be set to ARMV7 for that target
ARG WAMR_BUILD_TARGET
ARG EXTRA_CMAKE_FLAGS
ENV EXTRA_CMAKE_FLAGS=${EXTRA_CMAKE_FLAGS}

# We do not want word splitting for EXTRA_CMAKE_FLAGS in case multiple are defined
# hadolint ignore=SC2086
RUN [ -n "${WAMR_BUILD_TARGET:-}" ] && EXTRA_CMAKE_FLAGS="$EXTRA_CMAKE_FLAGS -DWAMR_BUILD_TARGET=$WAMR_BUILD_TARGET"; \
cmake -DFLB_RELEASE=On \
-DFLB_JEMALLOC=On \
-DFLB_TLS=On \
-DFLB_SHARED_LIB=Off \
Expand All @@ -79,8 +88,12 @@ RUN cmake -DFLB_RELEASE=On \
-DFLB_NIGHTLY_BUILD="$FLB_NIGHTLY_BUILD" \
-DFLB_LOG_NO_CONTROL_CHARS=On \
-DFLB_CHUNK_TRACE="$FLB_CHUNK_TRACE" \
$EXTRA_CMAKE_FLAGS \
..

ARG CFLAGS="-v"
ENV CFLAGS=${CFLAGS}

RUN make -j "$(getconf _NPROCESSORS_ONLN)"
RUN install bin/fluent-bit /fluent-bit/bin/

Expand Down
Loading
Loading