Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: feat: Build multi-arch #316

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 40 additions & 34 deletions .github/workflows/build-oci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,44 @@ jobs:
name: build-mapt
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Build image for PR
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

- name: Save image for PR
uses: actions/upload-artifact@v4
with:
name: mapt
path: mapt*

- name: Build image
if: ${{ github.event_name != 'pull_request' }}
shell: bash
run: make oci-build

- name: Log in to quay.io Registry
if: ${{ github.event_name != 'pull_request' }}
uses: redhat-actions/podman-login@v1
with:
registry: quay.io
username: ${{ secrets.QUAY_IO_USERNAME }}
password: ${{ secrets.QUAY_IO_PASSWORD }}

- name: Push image
if: ${{ github.event_name != 'pull_request' }}
shell: bash
run: make oci-push
# Allow emulation for building multi arch images
- name: Prepare runner
shell: bash
run: |
sudo apt-get install -y qemu-user-static

- name: Checkout code
uses: actions/checkout@v4

- name: Build image for PR
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

- name: Save image for PR
uses: actions/upload-artifact@v4
with:
name: mapt
path: mapt*

- name: Build image
if: ${{ github.event_name != 'pull_request' }}
shell: bash
run: make oci-build

- name: Log in to quay.io Registry
if: ${{ github.event_name != 'pull_request' }}
uses: redhat-actions/podman-login@v1
with:
registry: quay.io
username: ${{ secrets.QUAY_IO_USERNAME }}
password: ${{ secrets.QUAY_IO_PASSWORD }}

- name: Push image
if: ${{ github.event_name != 'pull_request' }}
shell: bash
run: make oci-push

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ install: $(SOURCES)
go install -ldflags="$(LDFLAGS)" $(GO_EXTRA_BUILDFLAGS) ./cmd/mapt

$(BUILD_DIR)/mapt: $(SOURCES)
GOOS="$(GOOS)" GOARCH=$(GOARCH) go build -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/mapt $(GO_EXTRA_BUILDFLAGS) ./cmd/mapt
GOOS="$(GOOS)" GOARCH=$(GOARCH) go build -x -o $(BUILD_DIR)/mapt $(GO_EXTRA_BUILDFLAGS) ./cmd/mapt

.PHONY: build
build: $(BUILD_DIR)/mapt
Expand All @@ -76,7 +76,7 @@ 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 --platform linux/arm64 --build-arg=SARCH=arm64 --build-arg=LARCH=aarch64 -t ${IMG} -f oci/Containerfile .

# Push the docker image
.PHONY: oci-push
Expand Down
19 changes: 14 additions & 5 deletions oci/Containerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@

# go 1.21.11-2
FROM registry.access.redhat.com/ubi9/go-toolset@sha256:b6d157c56a7348a2790fb94fe44eb336027c1e2bb722c7901b30d2e7c38d9554 as builder
FROM registry.access.redhat.com/ubi9/go-toolset@sha256:fd41c001abc243076cc28b63c409ae6d9cbcad401c8124fb67d20fe57a2aa63a as builder
# FROM registry.access.redhat.com/ubi9/go-toolset@sha256:b03f78d00ca116ffc0e025028ee063305d0f92a1cfcff3ba9e14e4a680cdcb35 as builder
# FROM registry.access.redhat.com/ubi9/go-toolset:1.21.13 as builder

ARG SARCH \
LARCH

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
ENV PULUMI_URL https://github.com/pulumi/pulumi/releases/download/v${PULUMI_VERSION}/pulumi-v${PULUMI_VERSION}-linux-${SARCH}.tar.gz

RUN make build \
&& 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
# FROM registry.access.redhat.com/ubi9@sha256:081c96d1b1c7cd1855722d01f1ca53360510443737b1eb33284c6c4c330e537c
FROM registry.access.redhat.com/ubi9/ubi@sha256:b00d5990a00937bd1ef7f44547af6c7fd36e3fd410e2c89b5d2dfc1aff69fe99

ARG SARCH \
LARCH

LABEL org.opencontainers.image.authors="Redhat Developer"

Expand All @@ -28,10 +37,10 @@ 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 AWS_CLI_URL https://awscli.amazonaws.com/awscli-exe-linux-${LARCH}-${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
ENV AZ_CLI_RPM https://packages.microsoft.com/rhel/9.0/prod/Packages/a/azure-cli-${AZ_CLI_VERSION}-1.el9.${LARCH}.rpm

# Pulumi plugins
# renovate: datasource=github-releases depName=pulumi/pulumi-aws
Expand Down