From 7ffe9b76203c0bb6c9aa4f06e6fd1e36a7e05ffb Mon Sep 17 00:00:00 2001 From: Joel Speed Date: Tue, 7 Jul 2020 09:53:32 +0100 Subject: [PATCH] Reduce docker context to improve build times --- .dockerignore | 4 ++++ CHANGELOG.md | 1 + Dockerfile | 3 ++- Dockerfile.arm64 | 3 ++- Dockerfile.armv6 | 3 ++- Makefile | 20 +++++++++++--------- 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.dockerignore b/.dockerignore index f3c61a6..1bc5bbc 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,5 @@ Dockerfile.dev +docs +vendor +.git +oauth2-proxy diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ba2989..4aa10f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ## Changes since v6.0.0 +- [#669](https://github.com/oauth2-proxy/oauth2-proxy/pull/669) Reduce docker context to improve build times (@JoelSpeed) - [#668](https://github.com/oauth2-proxy/oauth2-proxy/pull/668) Use req.Host in --force-https when req.URL.Host is empty (@zucaritask) - [#660](https://github.com/oauth2-proxy/oauth2-proxy/pull/660) Use builder pattern to simplify requests to external endpoints (@JoelSpeed) - [#591](https://github.com/oauth2-proxy/oauth2-proxy/pull/591) Introduce upstream package with new reverse proxy implementation (@JoelSpeed) diff --git a/Dockerfile b/Dockerfile index dd286a7..a989cb7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,5 @@ FROM golang:1.14-buster AS builder +ARG VERSION # Download tools RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.24.0 @@ -19,7 +20,7 @@ COPY . . # 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 make build && touch jwt_signing_key.pem +RUN VERSION=${VERSION} make build && touch jwt_signing_key.pem # Copy binary to alpine FROM alpine:3.11 diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 index 6b494b7..642770f 100644 --- a/Dockerfile.arm64 +++ b/Dockerfile.arm64 @@ -1,4 +1,5 @@ FROM golang:1.14-buster AS builder +ARG VERSION # Download tools RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.24.0 @@ -19,7 +20,7 @@ COPY . . # 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 GOARCH=arm64 make build && touch jwt_signing_key.pem +RUN VERSION=${VERSION} GOARCH=arm64 make build && touch jwt_signing_key.pem # Copy binary to alpine FROM arm64v8/alpine:3.11 diff --git a/Dockerfile.armv6 b/Dockerfile.armv6 index 1f8680c..2d16e3e 100644 --- a/Dockerfile.armv6 +++ b/Dockerfile.armv6 @@ -1,4 +1,5 @@ FROM golang:1.14-buster AS builder +ARG VERSION # Download tools RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.24.0 @@ -19,7 +20,7 @@ COPY . . # 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 GOARCH=arm GOARM=6 make build && touch jwt_signing_key.pem +RUN VERSION=${VERSION} GOARCH=arm GOARM=6 make build && touch jwt_signing_key.pem # Copy binary to alpine FROM arm32v6/alpine:3.11 diff --git a/Makefile b/Makefile index ba58b35..19b91a1 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ GO ?= go GOLANGCILINT ?= golangci-lint BINARY := oauth2-proxy -VERSION := $(shell git describe --always --dirty --tags 2>/dev/null || echo "undefined") +VERSION ?= $(shell git describe --always --dirty --tags 2>/dev/null || echo "undefined") # Allow to override image registry. REGISTRY ?= quay.io/oauth2-proxy .NOTPARALLEL: @@ -13,6 +13,8 @@ MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1 MINIMUM_SUPPORTED_GO_MINOR_VERSION = 14 GO_VERSION_VALIDATION_ERR_MSG = Golang version is not supported, please update to at least $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION).$(MINIMUM_SUPPORTED_GO_MINOR_VERSION) +DOCKER_BUILD := docker build --build-arg VERSION=${VERSION} + ifeq ($(COVER),true) TESTCOVER ?= -coverprofile c.out endif @@ -41,17 +43,17 @@ $(BINARY): .PHONY: docker docker: - docker build -f Dockerfile -t $(REGISTRY)/oauth2-proxy:latest . + $(DOCKER_BUILD) -f Dockerfile -t $(REGISTRY)/oauth2-proxy:latest . .PHONY: docker-all docker-all: docker - docker build -f Dockerfile -t $(REGISTRY)/oauth2-proxy:latest-amd64 . - docker build -f Dockerfile -t $(REGISTRY)/oauth2-proxy:${VERSION} . - docker build -f Dockerfile -t $(REGISTRY)/oauth2-proxy:${VERSION}-amd64 . - docker build -f Dockerfile.arm64 -t $(REGISTRY)/oauth2-proxy:latest-arm64 . - docker build -f Dockerfile.arm64 -t $(REGISTRY)/oauth2-proxy:${VERSION}-arm64 . - docker build -f Dockerfile.armv6 -t $(REGISTRY)/oauth2-proxy:latest-armv6 . - docker build -f Dockerfile.armv6 -t $(REGISTRY)/oauth2-proxy:${VERSION}-armv6 . + $(DOCKER_BUILD) -f Dockerfile -t $(REGISTRY)/oauth2-proxy:latest-amd64 . + $(DOCKER_BUILD) -f Dockerfile -t $(REGISTRY)/oauth2-proxy:${VERSION} . + $(DOCKER_BUILD) -f Dockerfile -t $(REGISTRY)/oauth2-proxy:${VERSION}-amd64 . + $(DOCKER_BUILD) -f Dockerfile.arm64 -t $(REGISTRY)/oauth2-proxy:latest-arm64 . + $(DOCKER_BUILD) -f Dockerfile.arm64 -t $(REGISTRY)/oauth2-proxy:${VERSION}-arm64 . + $(DOCKER_BUILD) -f Dockerfile.armv6 -t $(REGISTRY)/oauth2-proxy:latest-armv6 . + $(DOCKER_BUILD) -f Dockerfile.armv6 -t $(REGISTRY)/oauth2-proxy:${VERSION}-armv6 . .PHONY: docker-push docker-push: