From 07df29db37a89e4301b8a5f810ed293765f13e48 Mon Sep 17 00:00:00 2001 From: Joel Speed Date: Sat, 9 May 2020 16:07:46 +0100 Subject: [PATCH] Drop configure script in favour of native Makefile env and checks (#515) Co-authored-by: Henry Jenkins --- .travis.yml | 2 +- CHANGELOG.md | 1 + CONTRIBUTING.md | 1 - Dockerfile | 2 +- Dockerfile.arm64 | 2 +- Dockerfile.armv6 | 2 +- Makefile | 26 ++++++++- configure | 139 ----------------------------------------------- 8 files changed, 28 insertions(+), 147 deletions(-) delete mode 100755 configure diff --git a/.travis.yml b/.travis.yml index 9f5dd1d..0eef19c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ install: - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $GOPATH/bin v1.24.0 - GO111MODULE=on go mod download script: - - ./configure && make test + - make test sudo: false notifications: email: false diff --git a/CHANGELOG.md b/CHANGELOG.md index c0a9a05..ada558b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ ## Changes since v5.1.1 +- [#515](https://github.com/oauth2-proxy/oauth2-proxy/pull/515) Drop configure script in favour of native Makefile env and checks (@JoelSpeed) - [#487](https://github.com/oauth2-proxy/oauth2-proxy/pull/487) Switch flags to PFlag to remove StringArray (@JoelSpeed) - [#484](https://github.com/oauth2-proxy/oauth2-proxy/pull/484) Replace configuration loading with Viper (@JoelSpeed) - [#499](https://github.com/oauth2-proxy/oauth2-proxy/pull/499) Add `-user-id-claim` to support generic claims in addition to email (@holyjak) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 63fb242..ae051a1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -9,7 +9,6 @@ Download the dependencies using `go mod download`. cd $GOPATH/src/github.com # Create this directory if it doesn't exist git clone git@github.com:/oauth2-proxy oauth2-proxy/oauth2-proxy cd oauth2-proxy/oauth2-proxy -./configure # Setup your environment variables go mod download ``` diff --git a/Dockerfile b/Dockerfile index 4242e5c..dd286a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,7 +19,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 ./configure && make build && touch jwt_signing_key.pem +RUN make build && touch jwt_signing_key.pem # Copy binary to alpine FROM alpine:3.11 diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 index d0b57b7..6b494b7 100644 --- a/Dockerfile.arm64 +++ b/Dockerfile.arm64 @@ -19,7 +19,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 ./configure && GOARCH=arm64 make build && touch jwt_signing_key.pem +RUN 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 cabdfb4..1f8680c 100644 --- a/Dockerfile.armv6 +++ b/Dockerfile.armv6 @@ -19,7 +19,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 ./configure && GOARCH=arm GOARM=6 make build && touch jwt_signing_key.pem +RUN 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 3231799..e0a0c70 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,18 @@ -include .env +GO ?= go +GOLANGCILINT ?= golangci-lint + BINARY := oauth2-proxy VERSION := $(shell git describe --always --dirty --tags 2>/dev/null || echo "undefined") # Allow to override image registry. REGISTRY ?= quay.io/oauth2-proxy .NOTPARALLEL: +GO_MAJOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1) +GO_MINOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2) +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) + .PHONY: all all: lint $(BINARY) @@ -18,11 +26,11 @@ distclean: clean rm -rf vendor .PHONY: lint -lint: +lint: validate-go-version GO111MODULE=on $(GOLANGCILINT) run .PHONY: build -build: clean $(BINARY) +build: validate-go-version clean $(BINARY) $(BINARY): GO111MODULE=on CGO_ENABLED=0 $(GO) build -a -installsuffix cgo -ldflags="-X main.VERSION=${VERSION}" -o $@ github.com/oauth2-proxy/oauth2-proxy @@ -62,3 +70,15 @@ test: lint .PHONY: release release: lint test BINARY=${BINARY} VERSION=${VERSION} ./dist.sh + +.PHONY: validate-go-version +validate-go-version: ## Validates the installed version of go against Mattermost's minimum requirement. + @if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \ + exit 0 ;\ + elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \ + echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\ + exit 1; \ + elif [ $(GO_MINOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \ + echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\ + exit 1; \ + fi diff --git a/configure b/configure deleted file mode 100755 index c8edb30..0000000 --- a/configure +++ /dev/null @@ -1,139 +0,0 @@ -#!/usr/bin/env bash - -RED='\033[0;31m' -GREEN='\033[0;32m' -BLUE='\033[0;34m' -NC='\033[0m' - -if [ -z "${BASH_VERSINFO}" ] || [ -z "${BASH_VERSINFO[0]}" ] || [ ${BASH_VERSINFO[0]} -lt 4 ]; then - echo "This script requires Bash version >= 4"; exit 1; -fi - -declare -A tools=() -declare -A desired=() - -for arg in "$@"; do - case ${arg%%=*} in - "--with-go") - desired[go]="${arg##*=}" - ;; - "--help") - printf "${GREEN}$0${NC}\n" - printf " available options:\n" - printf " --with-go=${BLUE}${NC}\n" - exit 0 - ;; - *) - echo "Unknown option: $arg" - exit 2 - ;; - esac -done - -vercomp () { - if [[ $1 == $2 ]] - then - return 0 - fi - local IFS=. - local i ver1=($1) ver2=($2) - # fill empty fields in ver1 with zeros - for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) - do - ver1[i]=0 - done - for ((i=0; i<${#ver1[@]}; i++)) - do - if [[ -z ${ver2[i]} ]] - then - # fill empty fields in ver2 with zeros - ver2[i]=0 - fi - if ((10#${ver1[i]} > 10#${ver2[i]})) - then - return 1 - fi - if ((10#${ver1[i]} < 10#${ver2[i]})) - then - return 2 - fi - done - return 0 -} - -check_for() { - echo -n "Checking for $1... " - if ! [ -z "${desired[$1]}" ]; then - TOOL_PATH="${desired[$1]}" - else - TOOL_PATH=$(command -v $1) - fi - if ! [ -x "$TOOL_PATH" -a -f "$TOOL_PATH" ]; then - printf "${RED}not found${NC}\n" - cd - - exit 1 - else - printf "${GREEN}found${NC}\n" - tools[$1]=$TOOL_PATH - fi -} - -check_go_version() { - echo -n "Checking go version... " - GO_VERSION=$(${tools[go]} version | ${tools[awk]} '{where = match($0, /[0-9]\.[0-9]+\.[0-9]*/); if (where != 0) print substr($0, RSTART, RLENGTH)}') - vercomp $GO_VERSION 1.14 - case $? in - 0) ;& - 1) - printf "${GREEN}" - echo $GO_VERSION - printf "${NC}" - ;; - 2) - printf "${RED}" - echo "$GO_VERSION < 1.14" - exit 1 - ;; - esac - VERSION=$(${tools[go]} version | ${tools[awk]} '{print $3}') - tools["go_version"]="${VERSION}" -} - -check_docker_version() { - echo -n "Checking docker version... " - DOCKER_VERSION=$(${tools[docker]} version | ${tools[awk]}) -} - -check_go_env() { - echo -n "Checking \$GOPATH... " - GOPATH="$(go env GOPATH)" - if [ -z "$GOPATH" ]; then - printf "${RED}invalid${NC} - GOPATH not set\n" - exit 1 - fi - printf "${GREEN}valid${NC} - $GOPATH\n" -} - -cd ${0%/*} - -rm -fv .env - -check_for make -check_for awk -check_for go -check_go_version -check_go_env -check_for golangci-lint - -echo - -cat <<- EOF > .env - MAKE := "${tools[make]}" - GO := "${tools[go]}" - GO_VERSION := ${tools[go_version]} - GOLANGCILINT := "${tools[golangci-lint]}" -EOF - -echo "Environment configuration written to .env" - -cd - > /dev/null