git.iko.soy/typeable/oauth2-proxy
on master help sign in
Merge pull request #1391 from oauth2-proxy/docker-buildx-selection
85c0282Joel Speed
CHANGELOG.md+1
@@ -18,6 +18,7 @@
18
18
19## Changes since v7.1.3
19## Changes since v7.1.3
20
20
21+- [#1391](https://github.com/oauth2-proxy/oauth2-proxy/pull/1391) Improve build times by sharing cache and allowing platform selection (@JoelSpeed)
21- [#1404](https://github.com/oauth2-proxy/oauth2-proxy/pull/1404) Improve error message when no cookie is found (@JoelSpeed)
22- [#1404](https://github.com/oauth2-proxy/oauth2-proxy/pull/1404) Improve error message when no cookie is found (@JoelSpeed)
22- [#1315](https://github.com/oauth2-proxy/oauth2-proxy/pull/1315) linkedin: Update provider to v2 (@wuurrd)
23- [#1315](https://github.com/oauth2-proxy/oauth2-proxy/pull/1315) linkedin: Update provider to v2 (@wuurrd)
23- [#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)
24- [#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+# 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.
1−FROM golang:1.16-buster AS builder
5+FROM --platform=${BUILDPLATFORM} golang:1.16-buster AS builder
2
6
3# Copy sources
7# Copy sources
4WORKDIR $GOPATH/src/github.com/oauth2-proxy/oauth2-proxy
8WORKDIR $GOPATH/src/github.com/oauth2-proxy/oauth2-proxy
5
9
6# Fetch dependencies
10# Fetch dependencies
7COPY go.mod go.sum ./
11COPY go.mod go.sum ./
8−RUN GO111MODULE=on go mod download
12+RUN go mod download
9
13
10# Now pull in our code
14# Now pull in our code
11COPY . .
15COPY . .
12
16
17+# Arguments go here so that the previous steps can be cached if no external
18+# sources have changed.
13ARG VERSION
19ARG VERSION
20+ARG TARGETPLATFORM
21+ARG BUILDPLATFORM
14
22
15# Build binary and make sure there is at least an empty key file.
23# Build binary and make sure there is at least an empty key file.
16# This is useful for GCP App Engine custom runtime builds, because
24# This is useful for GCP App Engine custom runtime builds, because
@@ -18,7 +26,15 @@ ARG VERSION
18# build the key into the container and then tell it where it is
26# build the key into the container and then tell it where it is
19# by setting OAUTH2_PROXY_JWT_KEY_FILE=/etc/ssl/private/jwt_signing_key.pem
27# by setting OAUTH2_PROXY_JWT_KEY_FILE=/etc/ssl/private/jwt_signing_key.pem
20# in app.yaml instead.
28# in app.yaml instead.
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" && \
21−RUN VERSION=${VERSION} make build && touch jwt_signing_key.pem
37+ VERSION=${VERSION} make build && touch jwt_signing_key.pem
22
38
23# Copy binary to alpine
39# Copy binary to alpine
24FROM alpine:3.14
40FROM alpine:3.14
Makefile+7−5
@@ -22,8 +22,8 @@ all: lint $(BINARY)
22
22
23.PHONY: clean
23.PHONY: clean
24clean:
24clean:
25− rm -rf release
25+ -rm -rf release
26− rm -f $(BINARY)
26+ -rm -f $(BINARY)
27
27
28.PHONY: distclean
28.PHONY: distclean
29distclean: clean
29distclean: clean
@@ -37,10 +37,12 @@ lint: validate-go-version
37build: validate-go-version clean $(BINARY)
37build: validate-go-version clean $(BINARY)
38
38
39$(BINARY):
39$(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
41
41
42+DOCKER_BUILD_PLATFORM ?= linux/amd64,linux/arm64,linux/arm/v6
43+DOCKER_BUILDX_ARGS ?=
42DOCKER_BUILD := docker build --build-arg VERSION=${VERSION}
44DOCKER_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}
44
46
45.PHONY: docker
47.PHONY: docker
46docker:
48docker:
@@ -58,7 +60,7 @@ docker-all: docker
58
60
59.PHONY: docker-push
61.PHONY: docker-push
60docker-push:
62docker-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 .
62
64
63.PHONY: docker-push-all
65.PHONY: docker-push-all
64docker-push-all: docker-push
66docker-push-all: docker-push