Skip to content

Commit 777aaec

Browse files
authored
build: Containerfile for multi-platform builds (#46)
use the `BUILDPLATFORM` argument to build the image for the target platform use the `TARGETOS` and `TARGETARCH` build arguments to build the binary for the target platform use the `TARGETPLATFORM` argument to package the image for the target platform --------- Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
1 parent 3f447ea commit 777aaec

5 files changed

Lines changed: 32 additions & 13 deletions

File tree

.github/workflows/cd.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
image: codeready-toolchain/argocd-mcp-server
2323
tags: latest ${{ env.COMMIT_SHORT_SHA }}
2424
containerfiles: Containerfile
25+
platforms: linux/amd64
2526

2627
- name: Log into quay.io
2728
uses: redhat-actions/podman-login@v1

.github/workflows/ci.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ jobs:
2929
run: |
3030
task test
3131
32-
3332
- name: Install Podman
3433
uses: redhat-actions/podman-install@main
3534

@@ -44,6 +43,23 @@ jobs:
4443
export PATH="$GOPATH/bin:$PATH"
4544
task test-e2e
4645
46+
build-image:
47+
# verifying the image can be built (real build and push is done in the `cd` workflow)
48+
name: Build Image
49+
runs-on: ubuntu-24.04
50+
steps:
51+
- name: Checkout code
52+
uses: actions/checkout@v6
53+
54+
- name: Build image
55+
id: build-image
56+
uses: redhat-actions/buildah-build@v2
57+
with:
58+
image: codeready-toolchain/argocd-mcp-server
59+
tags: latest # we won't push the image to a registry in this workflow, so we're good with just the `latest` tag
60+
containerfiles: Containerfile
61+
platforms: linux/amd64
62+
4763
lint:
4864
name: Lint
4965
runs-on: ubuntu-24.04

Containerfile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,28 @@
22
# Builder image
33
# See https://hub.docker.com/_/golang/
44
################################################################################################
5-
FROM golang:1.24 as builder
6-
7-
ARG OS=linux
8-
ARG ARCH=amd64
5+
FROM --platform=$BUILDPLATFORM golang:1.24 AS builder
96

107
WORKDIR /usr/src/app
118

9+
ARG TARGETOS
10+
ARG TARGETARCH
11+
12+
RUN echo "Building the 'argocd-mcp-server' binary for $TARGETOS/$TARGETARCH"
13+
1214
# pre-copy/cache parent go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
1315
COPY go.mod go.sum ./
1416
RUN go mod download && go mod verify
1517

1618
COPY . .
1719

18-
RUN go build -o /usr/src/app/argocd-mcp-server main.go
20+
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /usr/src/app/argocd-mcp-server main.go
1921
RUN ls -la /usr/src/app/argocd-mcp-server
2022

2123
################################################################################################
22-
# image to be run by the GitHub Action job
24+
# image to be deployed to the target platform
2325
################################################################################################
24-
FROM registry.access.redhat.com/ubi9/ubi-minimal:latest as argocd-mcp-server
26+
FROM --platform=$TARGETPLATFORM registry.access.redhat.com/ubi10/ubi-micro:latest AS argocd-mcp-server
2527

2628
# Copy the generated binary into the $PATH so it can be invoked
2729
COPY --from=builder /usr/src/app/argocd-mcp-server /usr/local/bin/

taskfile.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ tasks:
3838
# The idiomatic way to disable test caching explicitly is to use -count=1
3939
- go test github.com/codeready-toolchain/argocd-mcp-server/test/e2e/... -count=1 -v -failfast
4040

41-
# Continuous Deployment
4241
build-image:
4342
cmds:
44-
- podman build --platform linux/amd64 --no-cache -t argocd-mcp-server:latest . -f Containerfile
43+
- podman build --no-cache -t argocd-mcp-server:latest . -f Containerfile
44+
45+
build-image-linux-amd64:
46+
cmds:
47+
- podman build --platform linux/amd64 --no-cache -t argocd-mcp-server:amd64 . -f Containerfile

test/e2e/argocd-server-mock/Containerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
################################################################################################
55
FROM golang:1.24 as argocd-mock-server-builder
66

7-
ARG OS=linux
8-
ARG ARCH=amd64
9-
107
WORKDIR /usr/src/app
118

129
# pre-copy/cache parent go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change

0 commit comments

Comments
 (0)