2022-04-14 15:10:59 +02:00
|
|
|
# This ARG has to be at the top, otherwise the docker daemon does not known what to do with FROM ${RUNTIME_IMAGE}
|
2024-01-20 20:48:04 +02:00
|
|
|
ARG RUNTIME_IMAGE=gcr.io/distroless/static:nonroot
|
2022-04-14 15:10:59 +02:00
|
|
|
|
2021-10-05 17:58:54 +02:00
|
|
|
# All builds should be done using the platform native to the build node to allow
|
|
|
|
# cache sharing of the go mod download step.
|
|
|
|
# Go cross compilation is also faster than emulation the go compilation across
|
|
|
|
# multiple platforms.
|
2023-08-21 12:26:45 +02:00
|
|
|
FROM --platform=${BUILDPLATFORM} docker.io/library/golang:1.19-buster AS builder
|
2019-01-21 19:50:50 +02:00
|
|
|
|
|
|
|
# Copy sources
|
2020-03-29 15:54:36 +02:00
|
|
|
WORKDIR $GOPATH/src/github.com/oauth2-proxy/oauth2-proxy
|
2018-12-20 13:06:26 +02:00
|
|
|
|
|
|
|
# Fetch dependencies
|
2019-07-15 22:38:55 +02:00
|
|
|
COPY go.mod go.sum ./
|
2021-10-05 17:58:54 +02:00
|
|
|
RUN go mod download
|
2018-12-20 13:06:26 +02:00
|
|
|
|
2019-07-12 00:18:07 +02:00
|
|
|
# Now pull in our code
|
|
|
|
COPY . .
|
|
|
|
|
2021-10-05 17:58:54 +02:00
|
|
|
# Arguments go here so that the previous steps can be cached if no external
|
|
|
|
# sources have changed.
|
2021-03-29 20:08:40 +02:00
|
|
|
ARG VERSION
|
2021-10-05 17:58:54 +02:00
|
|
|
ARG TARGETPLATFORM
|
|
|
|
ARG BUILDPLATFORM
|
2021-03-29 20:08:40 +02:00
|
|
|
|
2019-03-21 00:15:47 +02:00
|
|
|
# Build binary and make sure there is at least an empty key file.
|
|
|
|
# This is useful for GCP App Engine custom runtime builds, because
|
|
|
|
# you cannot use multiline variables in their app.yaml, so you have to
|
|
|
|
# build the key into the container and then tell it where it is
|
|
|
|
# by setting OAUTH2_PROXY_JWT_KEY_FILE=/etc/ssl/private/jwt_signing_key.pem
|
|
|
|
# in app.yaml instead.
|
2021-10-05 17:58:54 +02:00
|
|
|
# Set the cross compilation arguments based on the TARGETPLATFORM which is
|
|
|
|
# automatically set by the docker engine.
|
|
|
|
RUN case ${TARGETPLATFORM} in \
|
|
|
|
"linux/amd64") GOARCH=amd64 ;; \
|
2022-04-14 16:52:43 +02:00
|
|
|
# arm64 and arm64v8 are equivilant in go and do not require a goarm
|
|
|
|
# https://github.com/golang/go/wiki/GoArm
|
2022-11-04 03:24:52 +02:00
|
|
|
"linux/arm64" | "linux/arm/v8") GOARCH=arm64 ;; \
|
2022-02-17 23:55:57 +02:00
|
|
|
"linux/ppc64le") GOARCH=ppc64le ;; \
|
2021-10-05 17:58:54 +02:00
|
|
|
"linux/arm/v6") GOARCH=arm GOARM=6 ;; \
|
2023-09-08 18:18:20 +02:00
|
|
|
"linux/arm/v7") GOARCH=arm GOARM=7 ;; \
|
2021-10-05 17:58:54 +02:00
|
|
|
esac && \
|
|
|
|
printf "Building OAuth2 Proxy for arch ${GOARCH}\n" && \
|
2021-11-12 23:42:46 +02:00
|
|
|
GOARCH=${GOARCH} VERSION=${VERSION} make build && touch jwt_signing_key.pem
|
2018-12-20 13:06:26 +02:00
|
|
|
|
2024-01-20 20:48:04 +02:00
|
|
|
# Copy binary to runtime image
|
2022-04-14 15:10:59 +02:00
|
|
|
FROM ${RUNTIME_IMAGE}
|
2020-03-29 15:54:36 +02:00
|
|
|
COPY --from=builder /go/src/github.com/oauth2-proxy/oauth2-proxy/oauth2-proxy /bin/oauth2-proxy
|
|
|
|
COPY --from=builder /go/src/github.com/oauth2-proxy/oauth2-proxy/jwt_signing_key.pem /etc/ssl/private/jwt_signing_key.pem
|
2018-12-20 13:06:26 +02:00
|
|
|
|
2020-03-29 15:54:36 +02:00
|
|
|
ENTRYPOINT ["/bin/oauth2-proxy"]
|