Skip to content

Commit

Permalink
feat: make Docker images ARM-friendly (GoogleCloudPlatform#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
shubha-rajan authored May 11, 2022
1 parent 08d88d6 commit bc56066
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 24 deletions.
42 changes: 36 additions & 6 deletions .build/alpine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
42 changes: 36 additions & 6 deletions .build/buster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
42 changes: 36 additions & 6 deletions .build/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions Dockerfile.buster
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bc56066

Please sign in to comment.