diff --git a/.build/alpine.yaml b/.build/alpine.yaml index 35b3c7b62b..2958fbfb72 100644 --- a/.build/alpine.yaml +++ b/.build/alpine.yaml @@ -13,17 +13,47 @@ # limitations under the License. steps: +- name: gcr.io/cloud-builders/docker + args: + - run + - '--privileged' + - 'linuxkit/binfmt:v0.7' + id: 'initialize-qemu' +- name: gcr.io/cloud-builders/docker + args: + - buildx + - create + - '--name' + - multiarch-builder + id: 'create-builder' +- name: gcr.io/cloud-builders/docker + args: + - buildx + - use + - multiarch-builder + id: 'select-builder' +- name: gcr.io/cloud-builders/docker + args: + - buildx + - inspect + - '--bootstrap' + id: 'show-target-build-platforms' - name: 'gcr.io/cloud-builders/docker' args: + - 'buildx' - 'build' + - '--platform' + - $_DOCKER_BUILDX_PLATFORMS - '--tag=gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-alpine' - '--tag=us.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-alpine' - '--tag=eu.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-alpine' - '--tag=asia.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-alpine' - '-f=Dockerfile.alpine' - - '.' -images: - - 'gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-alpine' - - 'us.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-alpine' - - 'eu.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-alpine' - - 'asia.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-alpine' + - '--push' + - '.' + id: 'build-multi-architecture-container-image' +options: + env: + - DOCKER_CLI_EXPERIMENTAL=enabled +substitutions: + _DOCKER_BUILDX_PLATFORMS: 'linux/amd64,linux/arm64' diff --git a/.build/buster.yaml b/.build/buster.yaml index bcba7547d9..8b329dd388 100644 --- a/.build/buster.yaml +++ b/.build/buster.yaml @@ -13,17 +13,47 @@ # limitations under the License. steps: +- name: gcr.io/cloud-builders/docker + args: + - run + - '--privileged' + - 'linuxkit/binfmt:v0.7' + id: 'initialize-qemu' +- name: gcr.io/cloud-builders/docker + args: + - buildx + - create + - '--name' + - multiarch-builder + id: 'create-builder' +- name: gcr.io/cloud-builders/docker + args: + - buildx + - use + - multiarch-builder + id: 'select-builder' +- name: gcr.io/cloud-builders/docker + args: + - buildx + - inspect + - '--bootstrap' + id: 'show-target-build-platforms' - name: 'gcr.io/cloud-builders/docker' args: + - 'buildx' - 'build' + - '--platform' + - $_DOCKER_BUILDX_PLATFORMS - '--tag=gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-buster' - '--tag=us.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-buster' - '--tag=eu.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-buster' - '--tag=asia.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-buster' - '-f=Dockerfile.buster' - - '.' -images: - - 'gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-buster' - - 'us.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-buster' - - 'eu.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-buster' - - 'asia.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}-buster' + - '--push' + - '.' + id: 'build-multi-architecture-container-image' +options: + env: + - DOCKER_CLI_EXPERIMENTAL=enabled +substitutions: + _DOCKER_BUILDX_PLATFORMS: 'linux/amd64,linux/arm64' diff --git a/.build/default.yaml b/.build/default.yaml index 7a36d807aa..f72f2a5c7b 100644 --- a/.build/default.yaml +++ b/.build/default.yaml @@ -13,16 +13,46 @@ # limitations under the License. steps: +- name: gcr.io/cloud-builders/docker + args: + - run + - '--privileged' + - 'linuxkit/binfmt:v0.7' + id: 'initialize-qemu' +- name: gcr.io/cloud-builders/docker + args: + - buildx + - create + - '--name' + - multiarch-builder + id: 'create-builder' +- name: gcr.io/cloud-builders/docker + args: + - buildx + - use + - multiarch-builder + id: 'select-builder' +- name: gcr.io/cloud-builders/docker + args: + - buildx + - inspect + - '--bootstrap' + id: 'show-target-build-platforms' - name: 'gcr.io/cloud-builders/docker' args: + - 'buildx' - 'build' + - '--platform' + - $_DOCKER_BUILDX_PLATFORMS - '--tag=gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}' - '--tag=us.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}' - '--tag=eu.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}' - '--tag=asia.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}' - - '.' -images: - - 'gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}' - - 'us.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}' - - 'eu.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}' - - 'asia.gcr.io/$PROJECT_ID/alloydb-auth-proxy:${_VERSION}' + - '--push' + - '.' + id: 'build-multi-architecture-container-image' +options: + env: + - DOCKER_CLI_EXPERIMENTAL=enabled +substitutions: + _DOCKER_BUILDX_PLATFORMS: 'linux/amd64,linux/arm64' diff --git a/Dockerfile b/Dockerfile index 01184f824b..a9f2330cfb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,13 +13,17 @@ # limitations under the License. # Use the latest stable golang 1.x to compile to a binary -FROM golang:1 as build +FROM --platform=$BUILDPLATFORM golang:1 as build WORKDIR /go/src/alloydb-auth-proxy COPY . . +ARG TARGETOS +ARG TARGETARCH + RUN go get ./... -RUN CGO_ENABLED=0 go build -ldflags "-X main.metadataString=container" +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ + go build -ldflags "-X main.metadataString=container" # Final Stage FROM gcr.io/distroless/static:nonroot diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 75856cc407..9511fa9f6b 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -13,13 +13,17 @@ # limitations under the License. # Use the latest stable golang 1.x to compile to a binary -FROM golang:1 as build +FROM --platform=$BUILDPLATFORM golang:1 as build WORKDIR /go/src/alloydb-auth-proxy COPY . . +ARG TARGETOS +ARG TARGETARCH + RUN go get ./... -RUN go build -ldflags "-X main.metadataString=container.alpine" +RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ + go build -ldflags "-X main.metadataString=container.alpine" # Final stage FROM alpine:3 diff --git a/Dockerfile.buster b/Dockerfile.buster index d95d135f87..c20d9fc1f2 100644 --- a/Dockerfile.buster +++ b/Dockerfile.buster @@ -13,13 +13,17 @@ # limitations under the License. # Use the latest stable golang 1.x to compile to a binary -FROM golang:1 as build +FROM --platform=$BUILDPLATFORM golang:1 as build WORKDIR /go/src/alloydb-auth-proxy COPY . . +ARG TARGETOS +ARG TARGETARCH + RUN go get ./... -RUN go build -ldflags "-X main.metadataString=container.buster" +RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ + go build -ldflags "-X main.metadataString=container.buster" # Final stage FROM debian:buster