From a87b618d4b7879e99ea53bc3d4ea9ac272f27214 Mon Sep 17 00:00:00 2001 From: Jacobus Geluk Date: Tue, 27 Aug 2024 15:39:20 +0100 Subject: [PATCH] feat(build): adding multi-platform support --- .github/workflows/build.yml | 39 +++++++++++++++++++++++++------------ Dockerfile | 5 ++++- localbuild.sh | 17 ++++++++++------ 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 79bdbc8..063430d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,26 +4,41 @@ on: push: branches: [ master ] +permissions: read-all + jobs: build: runs-on: ubuntu-latest - permissions: - packages: write + permissions: write-all steps: - - - name: Checkout ekgf/gloud-terraform + - + name: Checkout ekgf/gloud-terraform uses: actions/checkout@v4 - - - name: set-env + - + name: set-env run: | echo "FQ_IMAGE_NAME=${{ vars.FQ_IMAGE_NAME }}" >> $GITHUB_ENV echo "VERSION=$(< ./VERSION)" >> $GITHUB_ENV - - - name: Build and push Docker images - uses: docker/build-push-action@v3 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + 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: Build and push Docker images + uses: docker/build-push-action@v6 with: - # - # TODO: Get the version number from a file (for instance localbuild.sh) or "/VERSION" - # tags: ${{ env.FQ_IMAGE_NAME }}:latest, ${{ env.FQ_IMAGE_NAME }}:${{ env.VERSION }} pull: true + push: true + platforms: linux/amd64,linux/arm64 diff --git a/Dockerfile b/Dockerfile index bbdcf31..d83b7ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM debian:12-slim as downloader +FROM debian:12-slim AS downloader LABEL maintainer="EKGF " ARG TERRAFORM_VERSION="1.9.5" @@ -25,6 +25,9 @@ RUN name="terraform-provider-sops_${TERRAFORM_SOPS_VERSION}" && \ # FROM gcr.io/cloud-builders/gcloud:latest LABEL maintainer="EKGF " +LABEL org.opencontainers.image.source="https://github.com/EKGF/gcloud-terraform" +LABEL org.opencontainers.image.description="Terraform Cloud Builder. This builder can be used to run the terraform tool in the GCE environment." +LABEL org.opencontainers.image.licenses=MIT # # Current user is root with home /root diff --git a/localbuild.sh b/localbuild.sh index 4c3ecbc..9687c8e 100755 --- a/localbuild.sh +++ b/localbuild.sh @@ -1,13 +1,18 @@ #!/usr/bin/env bash SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)" -_IMAGE_NAME="ghcr.io/ekgf/gcloud-terraform" -_IMAGE_VERSION="latest" -_MANUALLY_INCREMENTED_IMAGE_VERSION="0.0.7" +_IMAGE_NAME="$(< IMAGE_NAME)" +_IMAGE_VERSION="$(< VERSION)" cd "${SCRIPT_DIR}" || exit 1 -docker build . \ +# Create a parallel multi-platform builder +docker buildx create --name mybuilder --use +# Make "buildx" the default +docker buildx install +# Build for multiple platforms +docker build \ --iidfile=.image-id \ - "--tag=${_IMAGE_NAME}:${_IMAGE_VERSION}" \ - "--tag=${_IMAGE_NAME}:${_MANUALLY_INCREMENTED_IMAGE_VERSION}" + --platform linux/amd64,linux/arm64 \ + "--tag=${_IMAGE_NAME}:latest" \ + "--tag=${_IMAGE_NAME}:${_IMAGE_VERSION}" . exit $?