Skip to content

Commit

Permalink
chore: support multi-container Dockerfile multiple architecture
Browse files Browse the repository at this point in the history
Signed-off-by: kahirokunn <okinakahiro@gmail.com>
  • Loading branch information
kahirokunn committed Aug 21, 2023
1 parent 5442985 commit 9a3b5b4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions code-samples/serving/multi-container/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ You can do this by copying the following code into the `servingcontainer.go` fil
# This is based on Debian and sets the GOPATH to /go.
# https://hub.docker.com/_/golang
FROM golang:1.15 as builder
ARG TARGETOS
ARG TARGETARCH
# Create and change to the app directory.
WORKDIR /app
# Retrieve application dependencies using go modules.
Expand All @@ -78,7 +82,7 @@ You can do this by copying the following code into the `servingcontainer.go` fil
COPY . ./
# Build the binary.
# -mod=readonly ensures immutable go.mod and go.sum in container builds.
RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -v -o servingcontainer
RUN CGO_ENABLED=0 GOOS=linux GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -mod=readonly -v -o servingcontainer
# Use the official Alpine image for a lean production container.
# https://hub.docker.com/_/alpine
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
Expand Down Expand Up @@ -125,6 +129,10 @@ You can do this by copying the following code into the `sidecarcontainer.go` fil
# This is based on Debian and sets the GOPATH to /go.
# https://hub.docker.com/_/golang
FROM golang:1.15 as builder
ARG TARGETOS
ARG TARGETARCH
# Create and change to the app directory.
WORKDIR /app
# Retrieve application dependencies using go modules.
Expand All @@ -135,7 +143,7 @@ You can do this by copying the following code into the `sidecarcontainer.go` fil
COPY . ./
# Build the binary.
# -mod=readonly ensures immutable go.mod and go.sum in container builds.
RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -v -o sidecarcontainer
RUN CGO_ENABLED=0 GOOS=linux GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -mod=readonly -v -o sidecarcontainer
# Use the official Alpine image for a lean production container.
# https://hub.docker.com/_/alpine
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
Expand Down

0 comments on commit 9a3b5b4

Please sign in to comment.