From ea090cdc675e9ab010bffd55e6806e499a49f2cf Mon Sep 17 00:00:00 2001 From: Qi Feng Huo Date: Thu, 14 Sep 2023 09:37:29 +0800 Subject: [PATCH] operator: build multi-arch images for peerpod-ctl Fixes: #1432 Signed-off-by: Qi Feng Huo --- .github/workflows/peerpod-ctrl_image.yaml | 8 +++++++- peerpod-ctrl/Dockerfile | 9 +++++---- peerpod-ctrl/Makefile | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/peerpod-ctrl_image.yaml b/.github/workflows/peerpod-ctrl_image.yaml index 426479ddb..314fa70ca 100644 --- a/.github/workflows/peerpod-ctrl_image.yaml +++ b/.github/workflows/peerpod-ctrl_image.yaml @@ -9,6 +9,7 @@ on: push: branches: - main + - huoqifeng/peerpod-ctl-img paths: - 'peerpod-ctrl/**' @@ -25,6 +26,10 @@ jobs: uses: actions/checkout@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 + - name: Install build dependencies + run: | + sudo apt-get update -y + sudo apt-get install -y libvirt-dev - name: Login to Quay container Registry uses: docker/login-action@v2 with: @@ -43,6 +48,7 @@ jobs: quay.io/confidential-containers/peerpod-ctrl:${{ github.sha }} push: true context: peerpod-ctrl + platforms: linux/amd64, linux/s390x build-args: | - "$(make list-build-args)" + GOFLAGS=-tags=aws,azure,ibmcloud,vsphere,libvirt diff --git a/peerpod-ctrl/Dockerfile b/peerpod-ctrl/Dockerfile index 7675b7f51..9e8542e82 100644 --- a/peerpod-ctrl/Dockerfile +++ b/peerpod-ctrl/Dockerfile @@ -1,12 +1,12 @@ # Build the manager binary -FROM quay.io/confidential-containers/golang-fedora:1.20.7-36 as builder +FROM --platform=$TARGETPLATFORM quay.io/confidential-containers/golang-fedora:1.20.8-36 as builder ARG TARGETOS ARG TARGETARCH ARG CGO_ENABLED=1 ARG GOFLAGS WORKDIR /workspace -RUN if [ "$CGO_ENABLED" = 1 ] ; then dnf install -y libvirt-devel; fi +RUN if [ "$CGO_ENABLED" = 1 ] ; then dnf install -y libvirt-devel && dnf clean all; fi # Copy the Go Modules manifests COPY go.mod go.mod COPY go.sum go.sum @@ -19,6 +19,8 @@ COPY main.go main.go COPY api/ api/ COPY controllers/ controllers/ +RUN if [ "$TARGETARCH" = s390x ] ; then ln /usr/bin/gcc /usr/bin/s390x-linux-gnu-gcc; fi + # Build # the GOARCH has not a default value to allow the binary be built according to the host where the command # was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO @@ -26,9 +28,8 @@ COPY controllers/ controllers/ # by leaving it empty we can ensure that the container and binary shipped on it will have the same platform. RUN CGO_ENABLED=${CGO_ENABLED} GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build ${GOFLAGS} -a -o manager main.go -FROM fedora:36 +FROM --platform=$TARGETPLATFORM fedora:36 RUN if [ "$CGO_ENABLED" = 1 ] ; then dnf install -y libvirt-libs /usr/bin/ssh && dnf clean all; fi -RUN dnf install -y libvirt-libs /usr/bin/ssh WORKDIR / COPY --from=builder /workspace/manager . diff --git a/peerpod-ctrl/Makefile b/peerpod-ctrl/Makefile index 860895681..82bc15a08 100644 --- a/peerpod-ctrl/Makefile +++ b/peerpod-ctrl/Makefile @@ -63,7 +63,7 @@ endif SHELL = /usr/bin/env bash -o pipefail .SHELLFLAGS = -ec -BUILTIN_CLOUD_PROVIDERS ?= aws azure ibmcloud libvirt +BUILTIN_CLOUD_PROVIDERS ?= aws azure ibmcloud vsphere libvirt # Build tags required to build cloud-api-adaptor are derived from BUILTIN_CLOUD_PROVIDERS. # When libvirt is specified, CGO_ENABLED is set to 1. space := $() $()