mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2026-10-18 13:18:26 +02:00
Improve build times by sharing cache and allowing platform selection
This commit is contained in:
+19
-3
@@ -1,16 +1,24 @@
|
||||
FROM golang:1.16-buster AS builder
|
||||
# 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.
|
||||
FROM --platform=${BUILDPLATFORM} golang:1.16-buster AS builder
|
||||
|
||||
# Copy sources
|
||||
WORKDIR $GOPATH/src/github.com/oauth2-proxy/oauth2-proxy
|
||||
|
||||
# Fetch dependencies
|
||||
COPY go.mod go.sum ./
|
||||
RUN GO111MODULE=on go mod download
|
||||
RUN go mod download
|
||||
|
||||
# Now pull in our code
|
||||
COPY . .
|
||||
|
||||
# Arguments go here so that the previous steps can be cached if no external
|
||||
# sources have changed.
|
||||
ARG VERSION
|
||||
ARG TARGETPLATFORM
|
||||
ARG BUILDPLATFORM
|
||||
|
||||
# Build binary and make sure there is at least an empty key file.
|
||||
# This is useful for GCP App Engine custom runtime builds, because
|
||||
@@ -18,7 +26,15 @@ ARG VERSION
|
||||
# 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.
|
||||
RUN VERSION=${VERSION} make build && touch jwt_signing_key.pem
|
||||
# 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 ;; \
|
||||
"linux/arm64") GOARCH=arm64 ;; \
|
||||
"linux/arm/v6") GOARCH=arm GOARM=6 ;; \
|
||||
esac && \
|
||||
printf "Building OAuth2 Proxy for arch ${GOARCH}\n" && \
|
||||
VERSION=${VERSION} make build && touch jwt_signing_key.pem
|
||||
|
||||
# Copy binary to alpine
|
||||
FROM alpine:3.14
|
||||
|
||||
Reference in New Issue
Block a user