git.iko.soy/typeable/oauth2-proxy
on master help sign in
74 lines 3.1 kB history raw
1# The image ARGs have to be at the top, otherwise the docker daemon cannot validate
2# the FROM statements and overall Dockerfile
3#
4# Argument for setting the build image
5ARG BUILD_IMAGE=placeholder
6# Argument for setting the runtime image
7ARG RUNTIME_IMAGE=placeholder
8# Argument for setting the oauth2-proxy build version
9ARG VERSION
11# All builds should be done using the platform native to the build node to allow
12# cache sharing of the go mod download step.
13# Go cross compilation is also faster than emulation the go compilation across
14# multiple platforms.
15FROM --platform=${BUILDPLATFORM} ${BUILD_IMAGE} AS builder
17# Copy sources
18WORKDIR $GOPATH/src/github.com/oauth2-proxy/oauth2-proxy
20# Fetch dependencies
21COPY go.mod go.sum ./
22RUN go mod download
24# Now pull in our code
25COPY . .
27# Arguments go here so that the previous steps can be cached if no external sources
28# have changed. These arguments are automatically set by the docker engine.
29ARG TARGETPLATFORM
30ARG BUILDPLATFORM
32# Reload version argument
33ARG VERSION
35# Build binary and make sure there is at least an empty key file.
36# This is useful for GCP App Engine custom runtime builds, because
37# you cannot use multiline variables in their app.yaml, so you have to
38# build the key into the container and then tell it where it is
39# by setting OAUTH2_PROXY_JWT_KEY_FILE=/etc/ssl/private/jwt_signing_key.pem
40# in app.yaml instead.
41# Set the cross compilation arguments based on the TARGETPLATFORM which is
42# automatically set by the docker engine.
43RUN case ${TARGETPLATFORM} in \
44 "linux/amd64") GOARCH=amd64 ;; \
45 # arm64 and arm64v8 are equivalent in go and do not require a goarm
46 # https://github.com/golang/go/wiki/GoArm
47 "linux/arm64" | "linux/arm/v8") GOARCH=arm64 ;; \
48 "linux/ppc64le") GOARCH=ppc64le ;; \
49 "linux/s390x") GOARCH=s390x ;; \
50 "linux/arm/v6") GOARCH=arm GOARM=6 ;; \
51 "linux/arm/v7") GOARCH=arm GOARM=7 ;; \
52 esac && \
53 printf "Building OAuth2 Proxy for arch ${GOARCH}\n" && \
54 GOARCH=${GOARCH} VERSION=${VERSION} make build && touch jwt_signing_key.pem
56# Reload runtime image
57ARG RUNTIME_IMAGE
58# Copy binary to runtime image
59FROM ${RUNTIME_IMAGE}
60# Reload version
61ARG VERSION
63COPY --from=builder /go/src/github.com/oauth2-proxy/oauth2-proxy/oauth2-proxy /bin/oauth2-proxy
64COPY --from=builder /go/src/github.com/oauth2-proxy/oauth2-proxy/jwt_signing_key.pem /etc/ssl/private/jwt_signing_key.pem
66LABEL org.opencontainers.image.licenses=MIT \
67 org.opencontainers.image.description="A reverse proxy that provides authentication with Google, Azure, OpenID Connect and many more identity providers." \
68 org.opencontainers.image.documentation=https://oauth2-proxy.github.io/oauth2-proxy/ \
69 org.opencontainers.image.source=https://github.com/oauth2-proxy/oauth2-proxy \
70 org.opencontainers.image.url=https://quay.io/oauth2-proxy/oauth2-proxy \
71 org.opencontainers.image.title=oauth2-proxy \
72 org.opencontainers.image.version=${VERSION}
74ENTRYPOINT ["/bin/oauth2-proxy"]