git.iko.soy/typeable/oauth2-proxy
on 2bb7ea5 help sign in
51 lines 2.2 kB history raw
1# This ARG has to be at the top, otherwise the docker daemon does not known what to do with FROM ${RUNTIME_IMAGE}
2ARG RUNTIME_IMAGE=gcr.io/distroless/static:nonroot
4# All builds should be done using the platform native to the build node to allow
5# cache sharing of the go mod download step.
6# Go cross compilation is also faster than emulation the go compilation across
7# multiple platforms.
8FROM --platform=${BUILDPLATFORM} docker.io/library/golang:1.22-bookworm AS builder
10# Copy sources
11WORKDIR $GOPATH/src/github.com/oauth2-proxy/oauth2-proxy
13# Fetch dependencies
14COPY go.mod go.sum ./
15RUN go mod download
17# Now pull in our code
18COPY . .
20# Arguments go here so that the previous steps can be cached if no external
21# sources have changed.
22ARG VERSION
23ARG TARGETPLATFORM
24ARG BUILDPLATFORM
26# Build binary and make sure there is at least an empty key file.
27# This is useful for GCP App Engine custom runtime builds, because
28# you cannot use multiline variables in their app.yaml, so you have to
29# build the key into the container and then tell it where it is
30# by setting OAUTH2_PROXY_JWT_KEY_FILE=/etc/ssl/private/jwt_signing_key.pem
31# in app.yaml instead.
32# Set the cross compilation arguments based on the TARGETPLATFORM which is
33# automatically set by the docker engine.
34RUN case ${TARGETPLATFORM} in \
35 "linux/amd64") GOARCH=amd64 ;; \
36 # arm64 and arm64v8 are equivilant in go and do not require a goarm
37 # https://github.com/golang/go/wiki/GoArm
38 "linux/arm64" | "linux/arm/v8") GOARCH=arm64 ;; \
39 "linux/ppc64le") GOARCH=ppc64le ;; \
40 "linux/arm/v6") GOARCH=arm GOARM=6 ;; \
41 "linux/arm/v7") GOARCH=arm GOARM=7 ;; \
42 esac && \
43 printf "Building OAuth2 Proxy for arch ${GOARCH}\n" && \
44 GOARCH=${GOARCH} VERSION=${VERSION} make build && touch jwt_signing_key.pem
46# Copy binary to runtime image
47FROM ${RUNTIME_IMAGE}
48COPY --from=builder /go/src/github.com/oauth2-proxy/oauth2-proxy/oauth2-proxy /bin/oauth2-proxy
49COPY --from=builder /go/src/github.com/oauth2-proxy/oauth2-proxy/jwt_signing_key.pem /etc/ssl/private/jwt_signing_key.pem
51ENTRYPOINT ["/bin/oauth2-proxy"]