Skip to content

Commit

Permalink
chore: support all Dockerfile multiple architecture
Browse files Browse the repository at this point in the history
Signed-off-by: kahirokunn <[email protected]>
  • Loading branch information
kahirokunn committed Aug 21, 2023
1 parent d5110e1 commit 768d24e
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 15 deletions.
5 changes: 4 additions & 1 deletion code-samples/community/serving/helloworld-r/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
# https://hub.docker.com/_/golang
FROM golang:1.12 as builder

ARG TARGETOS
ARG TARGETARCH

# Copy local code to the container image.
WORKDIR /go/src/github.com/knative/docs/helloworld-r
COPY invoke.go .

# Build the command inside the container.
# (You may fetch or manage dependencies here,
# either manually or with a tool like "godep".)
RUN CGO_ENABLED=0 GOOS=linux go build -v -o invoke
RUN CGO_ENABLED=0 GOOS=linux GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -v -o invoke

# The official R base image
# https://hub.docker.com/_/r-base
Expand Down
5 changes: 4 additions & 1 deletion code-samples/community/serving/helloworld-r/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,17 @@ cd knative-docs/code-samples/community/serving/hello-world/helloworld-r
# https://hub.docker.com/_/golang
FROM golang:1.12 as builder
ARG TARGETOS
ARG TARGETARCH
# Copy local code to the container image.
WORKDIR /go/src/github.com/knative/docs/helloworld-r
COPY invoke.go .
# Build the command inside the container.
# (You may fetch or manage dependencies here,
# either manually or with a tool like "godep".)
RUN CGO_ENABLED=0 GOOS=linux go build -v -o invoke
RUN CGO_ENABLED=0 GOOS=linux GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -v -o invoke
# The official R base image
# https://hub.docker.com/_/r-base
Expand Down
5 changes: 4 additions & 1 deletion code-samples/community/serving/helloworld-r/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,17 @@ cd knative-docs/code-samples/community/serving/hello-world/helloworld-r
# https://hub.docker.com/_/golang
FROM golang:1.12 as builder
ARG TARGETOS
ARG TARGETARCH
# Copy local code to the container image.
WORKDIR /go/src/github.com/knative/docs/helloworld-r
COPY invoke.go .
# Build the command inside the container.
# (You may fetch or manage dependencies here,
# either manually or with a tool like "godep".)
RUN CGO_ENABLED=0 GOOS=linux go build -v -o invoke
RUN CGO_ENABLED=0 GOOS=linux GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -v -o invoke
# The official R base image
# https://hub.docker.com/_/r-base
Expand Down
5 changes: 4 additions & 1 deletion code-samples/eventing/helloworld/helloworld-go/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# https://hub.docker.com/_/golang
FROM golang:1.14 as builder

ARG TARGETOS
ARG TARGETARCH

# Copy local code to the container image.
WORKDIR /app

Expand All @@ -16,7 +19,7 @@ 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 helloworld
RUN CGO_ENABLED=0 GOOS=linux GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -mod=readonly -v -o helloworld

# Use a Docker multi-stage build to create a lean production image.
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
Expand Down
5 changes: 4 additions & 1 deletion code-samples/eventing/helloworld/helloworld-go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ cd knative-docs/code-samples/eventing/helloworld/helloworld-go
# https://hub.docker.com/_/golang
FROM golang:1.14 as builder
ARG TARGETOS
ARG TARGETARCH
# Copy local code to the container image.
WORKDIR /app
Expand All @@ -121,7 +124,7 @@ cd knative-docs/code-samples/eventing/helloworld/helloworld-go
# 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 helloworld
RUN CGO_ENABLED=0 GOOS=linux GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -mod=readonly -v -o helloworld
# Use a Docker multi-stage build to create a lean production image.
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
Expand Down
5 changes: 4 additions & 1 deletion code-samples/serving/cloudevents/cloudevents-go/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# https://hub.docker.com/_/golang
FROM golang:1.13 as builder

ARG TARGETOS
ARG TARGETARCH

# Create and change to the app directory.
WORKDIR /app

Expand All @@ -13,7 +16,7 @@ COPY . ./
# Also builds the binary
ENV GO111MODULE=on
RUN go mod init cloudevents.go \
&& CGO_ENABLED=0 GOOS=linux go build -v -o server
&& CGO_ENABLED=0 GOOS=linux GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -v -o server

# Allows the container builds to reuse downloaded dependencies.
RUN go mod download
Expand Down
5 changes: 4 additions & 1 deletion code-samples/serving/gitwebhook-go/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

FROM golang AS builder

ARG TARGETOS
ARG TARGETARCH

# copy the source
ADD . /go/src/github.com/knative/docs/code-samples/serving/gitwebhook-go
WORKDIR /go/src/github.com/knative/docs/code-samples/serving/gitwebhook-go
Expand All @@ -25,7 +28,7 @@ RUN go get gopkg.in/go-playground/webhooks.v3
RUN go get gopkg.in/go-playground/webhooks.v3/github

# build the sample
RUN CGO_ENABLED=0 go build -o /go/bin/webhook-sample .
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /go/bin/webhook-sample .

FROM golang:alpine

Expand Down
5 changes: 4 additions & 1 deletion code-samples/serving/knative-routing-go/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@

FROM golang AS builder

ARG TARGETOS
ARG TARGETARCH

WORKDIR /go/src/github.com/knative/docs/
ADD . /go/src/github.com/knative/docs/

RUN CGO_ENABLED=0 go build ./code-samples/serving/knative-routing-go/
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build ./code-samples/serving/knative-routing-go/

FROM gcr.io/distroless/base

Expand Down
5 changes: 4 additions & 1 deletion code-samples/serving/kong-routing-go/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@

FROM golang AS builder

ARG TARGETOS
ARG TARGETARCH

WORKDIR /go/src/github.com/knative/docs/
ADD . /go/src/github.com/knative/docs/

RUN CGO_ENABLED=0 go build ./code-samples/serving/kong-routing-go/
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build ./code-samples/serving/kong-routing-go/

FROM gcr.io/distroless/base

Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# https://hub.docker.com/_/golang
FROM golang:1.15 as builder

ARG TARGETOS
ARG TARGETARCH

# Create and change to the app directory.
WORKDIR /app

Expand All @@ -16,7 +19,7 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# https://hub.docker.com/_/golang
FROM golang:1.15 as builder

ARG TARGETOS
ARG TARGETARCH

# Create and change to the app directory.
WORKDIR /app

Expand All @@ -16,7 +19,7 @@ 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
Expand Down
5 changes: 4 additions & 1 deletion code-samples/serving/secrets-go/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
# https://hub.docker.com/_/golang
FROM golang as builder

ARG TARGETOS
ARG TARGETARCH

# Copy local code to the container image.
WORKDIR /go/src/github.com/knative/docs/hellosecrets
COPY . .

# Build the output command inside the container.
RUN CGO_ENABLED=0 GOOS=linux go build -v -o hellosecrets
RUN CGO_ENABLED=0 GOOS=linux GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -v -o hellosecrets

# Use a Docker multi-stage build to create a lean production image.
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
Expand Down
5 changes: 4 additions & 1 deletion code-samples/serving/secrets-go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,15 @@ cd knative-docs/code-samples/serving/secrets-go
# https://hub.docker.com/_/golang
FROM golang as builder
ARG TARGETOS
ARG TARGETARCH
# Copy local code to the container image.
WORKDIR /go/src/github.com/knative/docs/hellosecrets
COPY . .
# Build the output command inside the container.
RUN CGO_ENABLED=0 GOOS=linux go build -v -o hellosecrets
RUN CGO_ENABLED=0 GOOS=linux GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -v -o hellosecrets
# Use a Docker multi-stage build to create a lean production image.
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds
Expand Down

0 comments on commit 768d24e

Please sign in to comment.