From 3c41b2c54769ab079fc8ba5a2cfbdc67ea0bc324 Mon Sep 17 00:00:00 2001 From: lilyLuLiu Date: Mon, 21 Oct 2024 11:20:35 +0800 Subject: [PATCH] enable multi-arch build --- .github/workflows/build-oci.yaml | 17 +++++++++++++---- Makefile | 8 ++++++-- oci/Containerfile | 31 ++++++++++++++++++++----------- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build-oci.yaml b/.github/workflows/build-oci.yaml index f3b0b248..d2ec692b 100644 --- a/.github/workflows/build-oci.yaml +++ b/.github/workflows/build-oci.yaml @@ -12,6 +12,13 @@ jobs: build-mapt: name: build-mapt runs-on: ubuntu-24.04 + strategy: + fail-fast: false + matrix: + go: + - '1.21' + os: ['linux'] + arch: ['amd64', 'arm64'] steps: - name: Checkout code uses: actions/checkout@v4 @@ -20,16 +27,18 @@ jobs: if: ${{ github.event_name == 'pull_request' }} shell: bash run: | - IMG=ghcr.io/redhat-developer/mapt:pr-${{ github.event.number }} make oci-build - podman save -o mapt.tar ghcr.io/redhat-developer/mapt:pr-${{ github.event.number }} - echo "ghcr.io/redhat-developer/mapt:pr-${{ github.event.number }}" > mapt-image + IMG=ghcr.io/redhat-developer/mapt:pr-${{ github.event.number }}-${{matrix.arch}} ARCH=${{matrix.arch}} make oci-build + IMG=ghcr.io/redhat-developer/mapt:pr-${{ github.event.number }}-${{matrix.arch}} ARCH=${{matrix.arch}} make oci-save + echo "ghcr.io/redhat-developer/mapt:pr-${{ github.event.number }}" > mapt-image + - name: Save image for PR uses: actions/upload-artifact@v4 with: - name: mapt + name: mapt-pr-${{ github.event.number }} path: mapt* + - name: Build image if: ${{ github.event_name != 'pull_request' }} shell: bash diff --git a/Makefile b/Makefile index 971348e8..bf853589 100644 --- a/Makefile +++ b/Makefile @@ -76,12 +76,16 @@ lint: $(TOOLS_BINDIR)/golangci-lint # Build the container image .PHONY: oci-build oci-build: clean - ${CONTAINER_MANAGER} build -t ${IMG} -f oci/Containerfile . + ${CONTAINER_MANAGER} build --build-arg=ARCH=${ARCH} -t $(IMG)-${ARCH} -f oci/Containerfile . + +.PHONY: oci-save +oci-save: + ${CONTAINER_MANAGER} save -o $(IMG)-${ARCH}.tar $(IMG)-${ARCH} # Push the docker image .PHONY: oci-push oci-push: - ${CONTAINER_MANAGER} push ${IMG} + ${CONTAINER_MANAGER} push $(IMG)-${ARCH} # Update tekton with new version .PHONY: tkn-update diff --git a/oci/Containerfile b/oci/Containerfile index 297baf45..3ff4904f 100644 --- a/oci/Containerfile +++ b/oci/Containerfile @@ -1,6 +1,6 @@ - -# go 1.21.11-2 -FROM registry.access.redhat.com/ubi9/go-toolset@sha256:b6d157c56a7348a2790fb94fe44eb336027c1e2bb722c7901b30d2e7c38d9554 as builder +ARG ARCH +# go toolset 1.21.13-2.1727893526 +FROM --platform=linux/${ARCH} registry.access.redhat.com/ubi9/go-toolset@sha256:fd41c001abc243076cc28b63c409ae6d9cbcad401c8124fb67d20fe57a2aa63a as builder USER root WORKDIR /workspace @@ -8,14 +8,18 @@ COPY . . # renovate: datasource=github-releases depName=pulumi/pulumi ENV PULUMI_VERSION 3.135.0 -ENV PULUMI_URL https://github.com/pulumi/pulumi/releases/download/v${PULUMI_VERSION}/pulumi-v${PULUMI_VERSION}-linux-x64.tar.gz - RUN make build \ + && if [ "$ARCH" = "amd64" ]; then \ + export PULUMI_URL="https://github.com/pulumi/pulumi/releases/download/v${PULUMI_VERSION}/pulumi-v${PULUMI_VERSION}-linux-x64.tar.gz"; \ + else \ + export PULUMI_URL="https://github.com/pulumi/pulumi/releases/download/v${PULUMI_VERSION}/pulumi-v${PULUMI_VERSION}-linux-arm64.tar.gz"; \ + fi \ + && echo ${PULUMI_URL} \ && curl -L ${PULUMI_URL} -o pulumicli.tar.gz \ && tar -xzvf pulumicli.tar.gz -# ubi 9.4-1123.1719560047 -FROM registry.access.redhat.com/ubi9@sha256:081c96d1b1c7cd1855722d01f1ca53360510443737b1eb33284c6c4c330e537c +# ubi 9.4-1214.1726694543 +FROM --platform=linux/${ARCH} registry.access.redhat.com/ubi9/ubi@sha256:b00d5990a00937bd1ef7f44547af6c7fd36e3fd410e2c89b5d2dfc1aff69fe99 LABEL org.opencontainers.image.authors="Redhat Developer" @@ -28,10 +32,7 @@ ENV INTERNAL_OUTPUT=/tmp/mapt \ VOLUME [ "${INTERNAL_OUTPUT}" ] ENV AWS_CLI_VERSION 2.16.7 -ENV AWS_CLI_URL https://awscli.amazonaws.com/awscli-exe-linux-x86_64-${AWS_CLI_VERSION}.zip - ENV AZ_CLI_VERSION 2.61.0 -ENV AZ_CLI_RPM https://packages.microsoft.com/rhel/9.0/prod/Packages/a/azure-cli-${AZ_CLI_VERSION}-1.el9.x86_64.rpm # Pulumi plugins # renovate: datasource=github-releases depName=pulumi/pulumi-aws @@ -47,7 +48,15 @@ ARG PULUMI_TLS_VERSION=v5.0.3 # renovate: datasource=github-releases depName=pulumi/pulumi-random ARG PULUMI_RANDOM_VERSION=v4.16.2 -RUN curl ${AWS_CLI_URL} -o awscliv2.zip \ +RUN if [ "$ARCH" = "amd64" ]; then \ + export ARCH_N=x86_64; \ + else \ + export ARCH_N=aarch64; \ + fi \ + && export AWS_CLI_URL="https://awscli.amazonaws.com/awscli-exe-linux-${ARCH_N}-${AWS_CLI_VERSION}.zip" \ + && export AZ_CLI_RPM="https://packages.microsoft.com/rhel/9.0/prod/Packages/a/azure-cli-${AZ_CLI_VERSION}-1.el9.${ARCH_N}.rpm" \ + && echo ${AWS_CLI_URL} ${AZ_CLI_RPM} \ + && curl ${AWS_CLI_URL} -o awscliv2.zip \ && dnf install -y unzip \ && unzip awscliv2.zip \ && ./aws/install \