Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make Docker images ARM-friendly #1193

Merged
merged 3 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 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/gce-proxy:${_VERSION}-alpine'
- '--tag=us.gcr.io/$PROJECT_ID/gce-proxy:${_VERSION}-alpine'
- '--tag=eu.gcr.io/$PROJECT_ID/gce-proxy:${_VERSION}-alpine'
- '--tag=asia.gcr.io/$PROJECT_ID/gce-proxy:${_VERSION}-alpine'
- '-f=Dockerfile.alpine'
- '--push'
- '.'
images:
- 'gcr.io/$PROJECT_ID/gce-proxy:${_VERSION}-alpine'
- 'us.gcr.io/$PROJECT_ID/gce-proxy:${_VERSION}-alpine'
- 'eu.gcr.io/$PROJECT_ID/gce-proxy:${_VERSION}-alpine'
- 'asia.gcr.io/$PROJECT_ID/gce-proxy:${_VERSION}-alpine'
id: 'build-multi-architecture-container-image'
options:
env:
- DOCKER_CLI_EXPERIMENTAL=enabled
substitutions:
_DOCKER_BUILDX_PLATFORMS: 'linux/amd64,linux/arm64'
40 changes: 35 additions & 5 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/gce-proxy:${_VERSION}-buster'
- '--tag=us.gcr.io/$PROJECT_ID/gce-proxy:${_VERSION}-buster'
- '--tag=eu.gcr.io/$PROJECT_ID/gce-proxy:${_VERSION}-buster'
- '--tag=asia.gcr.io/$PROJECT_ID/gce-proxy:${_VERSION}-buster'
- '-f=Dockerfile.buster'
- '--push'
- '.'
images:
- 'gcr.io/$PROJECT_ID/gce-proxy:${_VERSION}-buster'
- 'us.gcr.io/$PROJECT_ID/gce-proxy:${_VERSION}-buster'
- 'eu.gcr.io/$PROJECT_ID/gce-proxy:${_VERSION}-buster'
- 'asia.gcr.io/$PROJECT_ID/gce-proxy:${_VERSION}-buster'
id: 'build-multi-architecture-container-image'
options:
env:
- DOCKER_CLI_EXPERIMENTAL=enabled
substitutions:
_DOCKER_BUILDX_PLATFORMS: 'linux/amd64,linux/arm64'
40 changes: 35 additions & 5 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/gce-proxy:${_VERSION}'
- '--tag=us.gcr.io/$PROJECT_ID/gce-proxy:${_VERSION}'
- '--tag=eu.gcr.io/$PROJECT_ID/gce-proxy:${_VERSION}'
- '--tag=asia.gcr.io/$PROJECT_ID/gce-proxy:${_VERSION}'
- '--push'
- '.'
images:
- 'gcr.io/$PROJECT_ID/gce-proxy:${_VERSION}'
- 'us.gcr.io/$PROJECT_ID/gce-proxy:${_VERSION}'
- 'eu.gcr.io/$PROJECT_ID/gce-proxy:${_VERSION}'
- 'asia.gcr.io/$PROJECT_ID/gce-proxy:${_VERSION}'
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/cloudsql-proxy
COPY . .

ARG TARGETOS
ARG TARGETARCH

RUN go get ./...
RUN CGO_ENABLED=0 go build -ldflags "-X main.metadataString=container" -o cloud_sql_proxy ./cmd/cloud_sql_proxy
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -ldflags "-X main.metadataString=container" -o cloud_sql_proxy ./cmd/cloud_sql_proxy

# 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/cloudsql-proxy
COPY . .

ARG TARGETOS
ARG TARGETARCH

RUN go get ./...
RUN go build -ldflags "-X main.metadataString=container.alpine" -o cloud_sql_proxy ./cmd/cloud_sql_proxy
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -ldflags "-X main.metadataString=container.alpine" -o cloud_sql_proxy ./cmd/cloud_sql_proxy

# 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/cloudsql-proxy
COPY . .

ARG TARGETOS
ARG TARGETARCH

RUN go get ./...
RUN go build -ldflags "-X main.metadataString=container.buster" -o cloud_sql_proxy ./cmd/cloud_sql_proxy
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -ldflags "-X main.metadataString=container.buster" -o cloud_sql_proxy ./cmd/cloud_sql_proxy

# Final stage
FROM debian:buster
Expand Down