2025-01-17 17:56:28 +01:00
# The image ARGs have to be at the top, otherwise the docker daemon cannot validate
# the FROM statements and overall Dockerfile
#
# Argument for setting the build image
ARG BUILD_IMAGE = placeholder
# Argument for setting the runtime image
ARG RUNTIME_IMAGE = placeholder
# Argument for setting the oauth2-proxy build version
2024-10-09 06:01:36 -07:00
ARG VERSION
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.
2025-01-17 17:56:28 +01:00
FROM --platform=${BUILDPLATFORM} ${BUILD_IMAGE} 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 . .
2025-01-17 17:56:28 +01:00
# Arguments go here so that the previous steps can be cached if no external sources
# have changed. These arguments are automatically set by the docker engine.
2021-10-05 16:58:54 +01:00
ARG TARGETPLATFORM
ARG BUILDPLATFORM
2025-01-17 17:56:28 +01:00
# Reload version argument
2025-01-14 16:29:26 +01:00
ARG VERSION
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 ; ; \
2024-10-09 06:01:36 -07:00
# arm64 and arm64v8 are equivalent in go and do not require a goarm
2022-04-14 10:52:43 -04:00
# 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 ; ; \
2024-08-23 02:02:02 -05:00
"linux/s390x" ) GOARCH = s390x ; ; \
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
2025-01-17 17:56:28 +01:00
# Reload runtime image
ARG RUNTIME_IMAGE
2024-01-20 19:48:04 +01:00
# Copy binary to runtime image
2022-04-14 15:10:59 +02:00
FROM ${RUNTIME_IMAGE}
2025-01-17 17:56:28 +01:00
# Reload version
2024-10-09 06:01:36 -07:00
ARG VERSION
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
2024-10-09 06:01:36 -07:00
LABEL org.opencontainers.image.licenses= MIT \
org.opencontainers.image.description= "A reverse proxy that provides authentication with Google, Azure, OpenID Connect and many more identity providers." \
org.opencontainers.image.documentation= https://oauth2-proxy.github.io/oauth2-proxy/ \
org.opencontainers.image.source= https://github.com/oauth2-proxy/oauth2-proxy \
org.opencontainers.image.url= https://quay.io/oauth2-proxy/oauth2-proxy \
org.opencontainers.image.title= oauth2-proxy \
org.opencontainers.image.version= ${ VERSION }
2020-03-29 14:54:36 +01:00
ENTRYPOINT [ "/bin/oauth2-proxy" ]