From bee3cdebf7bcc644d09b553ee61e8e160dc1ea3b Mon Sep 17 00:00:00 2001 From: Serge Logvinov Date: Mon, 9 Oct 2023 16:20:27 +0300 Subject: [PATCH] K8SPSMDB-948: Multi arch build An easy way to build PSMDB for different architectures. Signed-off-by: Serge Logvinov --- build/Dockerfile | 4 +++- e2e-tests/build | 13 ++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/build/Dockerfile b/build/Dockerfile index a3e31ea5a8..ac2e5b77cc 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -3,11 +3,13 @@ WORKDIR /go/src/github.com/percona/percona-server-mongodb-operator COPY . . +ARG TARGETARCH + ARG GIT_COMMIT ARG GIT_BRANCH ARG GO_LDFLAGS ARG GOOS=linux -ARG GOARCH=amd64 +ARG GOARCH=${TARGETARCH} ARG CGO_ENABLED=0 RUN go mod download \ diff --git a/e2e-tests/build b/e2e-tests/build index 06acdb1d85..c04a437da1 100755 --- a/e2e-tests/build +++ b/e2e-tests/build @@ -14,6 +14,11 @@ fi if [[ ${DOCKER_SQUASH:-1} == 1 ]]; then squash="--squash" fi +if [[ ${DOCKER_PUSH:-1} == 1 ]]; then + imgresult="--push=true" +else + imgresult="--output type=docker" +fi build_operator() { if [ "${RELEASE:-1}" = 0 ]; then @@ -24,18 +29,16 @@ build_operator() { export DOCKER_DEFAULT_PLATFORM=${DOCKER_DEFAULT_PLATFORM:-linux/amd64} export GO_LDFLAGS="-w -s -trimpath $GO_LDFLAGS" pushd ${src_dir} - docker build \ + docker buildx build \ + --platform $DOCKER_DEFAULT_PLATFORM \ --build-arg GIT_COMMIT=$GIT_COMMIT \ --build-arg GIT_BRANCH=$GIT_BRANCH \ --build-arg GO_LDFLAGS="$GO_LDFLAGS" \ $squash \ $no_cache \ + $imgresult \ -t "${IMAGE}" -f build/Dockerfile . popd - - if [ "${DOCKER_PUSH:-1}" = 1 ]; then - docker push ${IMAGE} - fi } until docker ps; do sleep 1; done