git.iko.soy/typeable/oauth2-proxy
on ea261ca help sign in
48 lines 1.9 kB history raw
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
4# multiple platforms.
5FROM --platform=${BUILDPLATFORM} golang:1.16-buster AS builder
7# Copy sources
8WORKDIR $GOPATH/src/github.com/oauth2-proxy/oauth2-proxy
10# Fetch dependencies
11COPY go.mod go.sum ./
12RUN go mod download
14# Now pull in our code
15COPY . .
17# Arguments go here so that the previous steps can be cached if no external
18# sources have changed.
19ARG VERSION
20ARG TARGETPLATFORM
21ARG BUILDPLATFORM
23# Build binary and make sure there is at least an empty key file.
24# This is useful for GCP App Engine custom runtime builds, because
25# you cannot use multiline variables in their app.yaml, so you have to
26# build the key into the container and then tell it where it is
27# by setting OAUTH2_PROXY_JWT_KEY_FILE=/etc/ssl/private/jwt_signing_key.pem
28# in app.yaml instead.
29# Set the cross compilation arguments based on the TARGETPLATFORM which is
30# automatically set by the docker engine.
31RUN case ${TARGETPLATFORM} in \
32 "linux/amd64") GOARCH=amd64 ;; \
33 "linux/arm64") GOARCH=arm64 ;; \
34 "linux/arm/v6") GOARCH=arm GOARM=6 ;; \
35 esac && \
36 printf "Building OAuth2 Proxy for arch ${GOARCH}\n" && \
37 VERSION=${VERSION} make build && touch jwt_signing_key.pem
39# Copy binary to alpine
40FROM alpine:3.14
41COPY nsswitch.conf /etc/nsswitch.conf
42COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
43COPY --from=builder /go/src/github.com/oauth2-proxy/oauth2-proxy/oauth2-proxy /bin/oauth2-proxy
44COPY --from=builder /go/src/github.com/oauth2-proxy/oauth2-proxy/jwt_signing_key.pem /etc/ssl/private/jwt_signing_key.pem
46USER 2000:2000
48ENTRYPOINT ["/bin/oauth2-proxy"]