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}
|
2023-09-05 16:22:15 +02:00
|
|
|
ARG RUNTIME_IMAGE=docker.io/library/alpine:3.18
|
2022-04-14 15:10:59 +02:00
|
|
|
|
2021-10-05 16:58:54 +01: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-22 02:50:50 +09:00
|
|
|
|
|
|
|
# Copy sources
|
2020-03-29 14:54:36 +01:00
|
|
|
WORKDIR $GOPATH/src/github.com/oauth2-proxy/oauth2-proxy
|
2018-12-20 11:06:26 +00:00
|
|
|
|
|
|
|
# Fetch dependencies
|
2019-07-15 21:38:55 +01:00
|
|
|
COPY go.mod go.sum ./
|
2021-10-05 16:58:54 +01:00
|
|
|
RUN go mod download
|
2018-12-20 11:06:26 +00:00
|
|
|
|
2019-07-11 17:18:07 -05:00
|
|
|
# Now pull in our code
|
|
|
|
COPY . .
|
|
|
|
|
2021-10-05 16:58:54 +01:00
|
|
|
# Arguments go here so that the previous steps can be cached if no external
|
|
|
|
# sources have changed.
|
2021-03-29 19:08:40 +01:00
|
|
|
ARG VERSION
|
2021-10-05 16:58:54 +01:00
|
|
|
ARG TARGETPLATFORM
|
|
|
|
ARG BUILDPLATFORM
|
2021-03-29 19:08:40 +01:00
|
|
|
|
2019-03-20 15:15:47 -07: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 16:58:54 +01: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 10:52:43 -04:00
|
|
|
# arm64 and arm64v8 are equivilant in go and do not require a goarm
|
|
|
|
# https://github.com/golang/go/wiki/GoArm
|
2022-11-03 21:24:52 -04:00
|
|
|
"linux/arm64" | "linux/arm/v8") GOARCH=arm64 ;; \
|
2022-02-17 22:55:57 +01:00
|
|
|
"linux/ppc64le") GOARCH=ppc64le ;; \
|
2021-10-05 16:58:54 +01: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 16:58:54 +01:00
|
|
|
esac && \
|
|
|
|
printf "Building OAuth2 Proxy for arch ${GOARCH}\n" && \
|
2021-11-13 03:12:46 +05:30
|
|
|
GOARCH=${GOARCH} VERSION=${VERSION} make build && touch jwt_signing_key.pem
|
2018-12-20 11:06:26 +00:00
|
|
|
|
2019-01-22 02:50:50 +09:00
|
|
|
# Copy binary to alpine
|
2022-04-14 15:10:59 +02:00
|
|
|
FROM ${RUNTIME_IMAGE}
|
2020-02-23 18:16:18 +00:00
|
|
|
COPY nsswitch.conf /etc/nsswitch.conf
|
2020-03-29 14:54:36 +01: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 11:06:26 +00:00
|
|
|
|
2022-04-14 15:10:59 +02:00
|
|
|
# UID/GID 65532 is also known as nonroot user in distroless image
|
|
|
|
USER 65532:65532
|
2019-03-05 21:26:49 +13:00
|
|
|
|
2020-03-29 14:54:36 +01:00
|
|
|
ENTRYPOINT ["/bin/oauth2-proxy"]
|