From 68f3b2c10510cbba54915476affeae3560c7da5a Mon Sep 17 00:00:00 2001 From: "Brian L. Troutwine" Date: Wed, 6 Nov 2024 15:32:00 -0800 Subject: [PATCH] Use native ARM builders for container builds This commit replaces #1088 and attempts to build a lading multi-platform image by use of organization provided ARM native builders. Unsure if this'll work but I figure it's worth a shot. Signed-off-by: Brian L. Troutwine --- .github/workflows/container.yml | 60 +++++++++++++++++++++++++++++---- Dockerfile | 4 +-- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index 2b6cd6f21..63526e0aa 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -8,8 +8,15 @@ env: IMAGE_NAME: ${{ github.repository }} jobs: - container: - runs-on: ubuntu-20.04 + build: + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - arch: amd64 + runner: ubuntu-20.04 + - arch: arm64 + runner: arm-4core-linux-ubuntu24.04 permissions: contents: read packages: write @@ -47,9 +54,50 @@ jobs: with: file: Dockerfile builder: ${{ steps.buildx.outputs.name }} + platforms: linux/${{ matrix.arch }} + tags: | + ${{ steps.meta.outputs.tags }} + ${{ steps.meta.outputs.tags }}-${{ matrix.arch }} push: true - platforms: linux/amd64, linux/arm64 - tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha, scope=${{ github.workflow }} - cache-to: type=gha, scope=${{ github.workflow }} + cache-from: type=registry,ref=ghcr.io/datadog/lading:latest + cache-to: type=registry,ref=ghcr.io/datadog/lading:latest,mode=max + + manifest: + name: Create Multi-Arch Manifest + needs: build + runs-on: ubuntu-20.04 + permissions: + contents: read + packages: write + + steps: + - name: Log in to Container Registry + uses: docker/login-action@v3.3.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.7.1 + + - name: Extract Docker Metadata + uses: docker/metadata-action@v5.5.1 + id: meta + with: + tags: | + type=sha,format=long + type=ref,prefix=pr-,event=pr + type=semver,pattern={{version}},event=tag + type=semver,pattern={{major}}.{{minor}},event=tag + type=semver,pattern={{major}},event=tag + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Create and Push Multi-Arch Manifest + run: | + docker manifest create ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.tags }} \ + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.tags }}-amd64 \ + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.tags }}-arm64 + + docker manifest push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.tags }} diff --git a/Dockerfile b/Dockerfile index f3b14bc1e..3bd5c0085 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Update the rust version in-sync with the version in rust-toolchain.toml -FROM docker.io/rust:1.81.0-bullseye AS builder +FROM --platform=$BUILDPLATFORM docker.io/rust:1.81.0-bullseye AS builder RUN apt-get update && apt-get install -y \ protobuf-compiler fuse3 libfuse3-dev \ @@ -9,7 +9,7 @@ WORKDIR /app COPY . /app RUN cargo build --release --locked --bin lading -FROM docker.io/debian:bullseye-20240701-slim +FROM --platform=$BUILDPLATFORM docker.io/debian:bullseye-20240701-slim RUN apt-get update && apt-get install -y libfuse3-dev=3.10.3-2 fuse3=3.10.3-2 && rm -rf /var/lib/apt/lists/* COPY --from=builder /app/target/release/lading /usr/bin/lading