Skip to content

Commit

Permalink
enable multi-arch build
Browse files Browse the repository at this point in the history
  • Loading branch information
lilyLuLiu committed Oct 21, 2024
1 parent 8d5f496 commit 3c41b2c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 17 deletions.
17 changes: 13 additions & 4 deletions .github/workflows/build-oci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 20 additions & 11 deletions oci/Containerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@

# 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
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"

Expand All @@ -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
Expand All @@ -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 \
Expand Down

0 comments on commit 3c41b2c

Please sign in to comment.