@@ -1,16 +1,24 @@
1+# All builds should be done using the platform native to the build node to allow
2+# cache sharing of the go mod download step.
3+# Go cross compilation is also faster than emulation the go compilation across
1−FROM golang:1.16-buster AS builder
5+FROM --platform=${BUILDPLATFORM} golang:1.16-buster AS builder
3# Copy sources
7# Copy sources
4WORKDIR $GOPATH/src/github.com/oauth2-proxy/oauth2-proxy
8WORKDIR $GOPATH/src/github.com/oauth2-proxy/oauth2-proxy
6# Fetch dependencies
10# Fetch dependencies
7COPY go.mod go.sum ./
11COPY go.mod go.sum ./
8−RUN GO111MODULE=on go mod download
12+RUN go mod download
10# Now pull in our code
14# Now pull in our code
17+# Arguments go here so that the previous steps can be cached if no external
18+# sources have changed.
13ARG VERSION
19ARG VERSION
15# Build binary and make sure there is at least an empty key file.
23# Build binary and make sure there is at least an empty key file.
16# This is useful for GCP App Engine custom runtime builds, because
24# This is useful for GCP App Engine custom runtime builds, because
@@ -18,7 +26,15 @@ ARG VERSION
18# build the key into the container and then tell it where it is
26# build the key into the container and then tell it where it is
19# by setting OAUTH2_PROXY_JWT_KEY_FILE=/etc/ssl/private/jwt_signing_key.pem
27# by setting OAUTH2_PROXY_JWT_KEY_FILE=/etc/ssl/private/jwt_signing_key.pem
20# in app.yaml instead.
28# in app.yaml instead.
29+# Set the cross compilation arguments based on the TARGETPLATFORM which is
30+# automatically set by the docker engine.
31+RUN case ${TARGETPLATFORM} in \
32+ "linux/amd64") GOARCH=amd64 ;; \
33+ "linux/arm64") GOARCH=arm64 ;; \
34+ "linux/arm/v6") GOARCH=arm GOARM=6 ;; \
36+ printf "Building OAuth2 Proxy for arch ${GOARCH}\n" && \
21−RUN VERSION=${VERSION} make build && touch jwt_signing_key.pem
37+ VERSION=${VERSION} make build && touch jwt_signing_key.pem
23# Copy binary to alpine
39# Copy binary to alpine
24FROM alpine:3.14
40FROM alpine:3.14