From 3a04a982189311ffceeb6cec8ff8016b2e089cb8 Mon Sep 17 00:00:00 2001 From: KevFan Date: Mon, 23 Oct 2023 10:45:32 +0100 Subject: [PATCH] fix: explicitly set targetplatform --- .github/workflows/build-image.yaml | 30 +++++++++++++++++------------- Dockerfile | 2 +- Dockerfile.aarch64 | 2 +- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build-image.yaml b/.github/workflows/build-image.yaml index b9898d8a..3aa6352e 100644 --- a/.github/workflows/build-image.yaml +++ b/.github/workflows/build-image.yaml @@ -20,11 +20,14 @@ jobs: fail-fast: false matrix: include: - - dockerfile: ./Dockerfile + - dockerfile: Dockerfile platform: linux/amd64 - - dockerfile: ./Dockerfile.aarch64 + - dockerfile: Dockerfile.aarch64 platform: linux/arm64 steps: + - name: Set image name + run: | + echo "IMG=${{ env.IMG_REGISTRY_HOST}}/${{ env.IMG_REGISTRY_ORG }}/limitador" >> "$GITHUB_ENV" - name: Check out code uses: actions/checkout@v4 - name: Set up Docker Buildx @@ -34,7 +37,7 @@ jobs: uses: docker/metadata-action@v5 with: images: | - ${{ env.IMG_REGISTRY_HOST}}/${{ env.IMG_REGISTRY_ORG }}/limitador + ${{ env.IMG }} - name: Login to container registry uses: docker/login-action@v2 with: @@ -47,17 +50,15 @@ jobs: with: context: . labels: ${{ steps.meta.outputs.labels }} -# build-args: | -# GITHUB_SHA=${{ github.sha }} + build-args: | + GITHUB_SHA=${{ github.sha }} cache-from: type=gha,scope=${{ matrix.platform == 'linux/amd64' && 'build-amd' || 'build-arm'}} cache-to: type=gha,mode=max,scope=${{ matrix.platform == 'linux/amd64' && 'build-amd' || 'build-arm'}} - outputs: type=image,name=${{ env.IMG_REGISTRY_HOST}}/${{ env.IMG_REGISTRY_ORG }}/limitador,push-by-digest=true,name-canonical=true,push=true + outputs: type=image,name=${{ env.IMG }},push-by-digest=true,name-canonical=true,push=true file: ${{ matrix.dockerfile }} platforms: | ${{ matrix.platform }} -# - name: Smoke Test -# run: | -# docker run --rm -t ${{ env.IMG_REGISTRY_HOST}}/${{ env.IMG_REGISTRY_ORG }}/limitador:${{ github.sha }} limitador-server --help + provenance: false - name: Export digest run: | mkdir -p /tmp/digests @@ -100,11 +101,11 @@ jobs: uses: docker/metadata-action@v5 with: images: | - ${{ env.IMG_REGISTRY_HOST}}/${{ env.IMG_REGISTRY_ORG }}/limitador + ${{ env.IMG }} tags: | # type=raw,value=${{ github.sha }} # set latest tag for main branch - # type=raw,value=latest,enable=${{ github.ref_name == env.MAIN_BRANCH_NAME }} + type=raw,value=latest,enable=${{ github.ref_name == env.MAIN_BRANCH_NAME }} # set branch name tag for non-main branches type=raw,value=${{ github.ref_name }},enable=${{ github.ref_name != env.MAIN_BRANCH_NAME }} - name: Login to container registry @@ -117,7 +118,10 @@ jobs: working-directory: /tmp/digests run: | docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ - $(printf '${{ env.IMG_REGISTRY_HOST}}/${{ env.IMG_REGISTRY_ORG }}/limitador@sha256:%s ' *) + $(printf '${{ env.IMG }}@sha256:%s ' *) - name: Inspect image run: | - docker buildx imagetools inspect ${{ env.IMG_REGISTRY_HOST}}/${{ env.IMG_REGISTRY_ORG }}/limitador:${{ steps.meta.outputs.version }} \ No newline at end of file + docker buildx imagetools inspect ${{ env.IMG }}:${{ steps.meta.outputs.version }} + - name: Smoke Test + run: | + docker run --rm -t ${{ env.IMG }}:${{ steps.meta.outputs.version }} limitador-server --help \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 853a113a..30a5ab82 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ # Build Stage # ------------------------------------------------------------------------------ -FROM --platform=${BUILDPLATFORM} registry.access.redhat.com/ubi8/ubi:8.7 as limitador-build +FROM registry.access.redhat.com/ubi8/ubi:8.7 as limitador-build ENV CARGO_NET_GIT_FETCH_WITH_CLI=true ARG RUSTC_VERSION=1.72.0 diff --git a/Dockerfile.aarch64 b/Dockerfile.aarch64 index 3a6d9f94..b03e8ebc 100644 --- a/Dockerfile.aarch64 +++ b/Dockerfile.aarch64 @@ -29,7 +29,7 @@ RUN cargo build --release --target aarch64-unknown-linux-gnu # Run Stage # ------------------------------------------------------------------------------ -FROM gcr.io/distroless/cc-debian12 +FROM --platform=$TARGETPLATFORM gcr.io/distroless/cc-debian12 WORKDIR /home/limitador/bin/ ENV PATH="/home/limitador/bin:${PATH}"