git.iko.soy/typeable/oauth2-proxy
on master help sign in
Improve build times by sharing cache and allowing platform selection
commit2ce93b6b31f8a3dc47bdacaf5e6d4e0b960d1974 authorJoel Speed <joel.speed@hotmail.co.uk> dateTue 5 Oct 2021, 16:58 (5 years ago) parent9d8093f
3 files changed+27−8
CHANGELOG.md+1 Dockerfile+19−3 Makefile+7−5
CHANGELOG.md+1
@@ -18,6 +18,7 @@
1818
1919## Changes since v7.1.3
2020
21+- [#1391](https://github.com/oauth2-proxy/oauth2-proxy/pull/1391) Improve build times by sharing cache and allowing platform selection (@JoelSpeed)
2122- [#1404](https://github.com/oauth2-proxy/oauth2-proxy/pull/1404) Improve error message when no cookie is found (@JoelSpeed)
2223- [#1315](https://github.com/oauth2-proxy/oauth2-proxy/pull/1315) linkedin: Update provider to v2 (@wuurrd)
2324- [#1348](https://github.com/oauth2-proxy/oauth2-proxy/pull/1348) Using the native httputil proxy code for websockets rather than yhat/wsutil to properly handle HTTP-level failures (@thetrime)
Dockerfile+19−3
@@ -1,16 +1,24 @@
1−FROM golang:1.16-buster AS builder
1+# All builds should be done using the platform native to the build node to allow
2+# cache sharing of the go mod download step.
3+# Go cross compilation is also faster than emulation the go compilation across
4+# multiple platforms.
5+FROM --platform=${BUILDPLATFORM} golang:1.16-buster AS builder
26
37# Copy sources
48WORKDIR $GOPATH/src/github.com/oauth2-proxy/oauth2-proxy
59
610# Fetch dependencies
711COPY go.mod go.sum ./
8−RUN GO111MODULE=on go mod download
12+RUN go mod download
913
1014# Now pull in our code
1115COPY . .
1216
17+# Arguments go here so that the previous steps can be cached if no external
18+# sources have changed.
1319ARG VERSION
20+ARG TARGETPLATFORM
21+ARG BUILDPLATFORM
1422
1523# Build binary and make sure there is at least an empty key file.
1624# This is useful for GCP App Engine custom runtime builds, because
@@ -18,7 +26,15 @@ ARG VERSION
1826# build the key into the container and then tell it where it is
1927# by setting OAUTH2_PROXY_JWT_KEY_FILE=/etc/ssl/private/jwt_signing_key.pem
2028# in app.yaml instead.
21−RUN VERSION=${VERSION} make build && touch jwt_signing_key.pem
29+# Set the cross compilation arguments based on the TARGETPLATFORM which is
30+# automatically set by the docker engine.
31+RUN case ${TARGETPLATFORM} in \
32+ "linux/amd64") GOARCH=amd64 ;; \
33+ "linux/arm64") GOARCH=arm64 ;; \
34+ "linux/arm/v6") GOARCH=arm GOARM=6 ;; \
35+ esac && \
36+ printf "Building OAuth2 Proxy for arch ${GOARCH}\n" && \
37+ VERSION=${VERSION} make build && touch jwt_signing_key.pem
2238
2339# Copy binary to alpine
2440FROM alpine:3.14
Makefile+7−5
@@ -22,8 +22,8 @@ all: lint $(BINARY)
2222
2323.PHONY: clean
2424clean:
25− rm -rf release
26− rm -f $(BINARY)
25+ -rm -rf release
26+ -rm -f $(BINARY)
2727
2828.PHONY: distclean
2929distclean: clean
@@ -37,10 +37,12 @@ lint: validate-go-version
3737build: validate-go-version clean $(BINARY)
3838
3939$(BINARY):
40− GO111MODULE=on CGO_ENABLED=0 $(GO) build -a -installsuffix cgo -ldflags="-X main.VERSION=${VERSION}" -o $@ github.com/oauth2-proxy/oauth2-proxy/v7
40+ CGO_ENABLED=0 $(GO) build -a -installsuffix cgo -ldflags="-X main.VERSION=${VERSION}" -o $@ github.com/oauth2-proxy/oauth2-proxy/v7
4141
42+DOCKER_BUILD_PLATFORM ?= linux/amd64,linux/arm64,linux/arm/v6
43+DOCKER_BUILDX_ARGS ?=
4244DOCKER_BUILD := docker build --build-arg VERSION=${VERSION}
43−DOCKER_BUILDX := docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v6 --build-arg VERSION=${VERSION}
45+DOCKER_BUILDX := docker buildx build ${DOCKER_BUILDX_ARGS} --platform ${DOCKER_BUILD_PLATFORM} --build-arg VERSION=${VERSION}
4446
4547.PHONY: docker
4648docker:
@@ -58,7 +60,7 @@ docker-all: docker
5860
5961.PHONY: docker-push
6062docker-push:
61− docker buildx build --push --platform linux/amd64,linux/arm64,linux/arm/v6 -t $(REGISTRY)/oauth2-proxy:latest .
63+ docker buildx build --push --platform ${DOCKER_BUILD_PLATFORM} -t $(REGISTRY)/oauth2-proxy:latest .
6264
6365.PHONY: docker-push-all
6466docker-push-all: docker-push