git.iko.soy/typeable/oauth2-proxy
on master help sign in
Drop configure script in favour of native Makefile env and checks (#515)

Co-authored-by: Henry Jenkins <henry@henryjenkins.name>

commit07df29db37a89e4301b8a5f810ed293765f13e48 authorJoel Speed <Joel.speed@hotmail.co.uk> dateSat 9 May 2020, 16:07 (6 years ago) parent9ed5a43
8 files changed+28−147
.travis.yml+1−1 CHANGELOG.md+1 CONTRIBUTING.md−1 Dockerfile+1−1 Dockerfile.arm64+1−1 Dockerfile.armv6+1−1 Makefile+23−3 configure−139
.travis.yml+1−1
@@ -6,7 +6,7 @@ install:
66 - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $GOPATH/bin v1.24.0
77 - GO111MODULE=on go mod download
88script:
9− - ./configure && make test
9+ - make test
1010sudo: false
1111notifications:
1212 email: false
CHANGELOG.md+1
@@ -25,6 +25,7 @@
2525
2626## Changes since v5.1.1
2727
28+- [#515](https://github.com/oauth2-proxy/oauth2-proxy/pull/515) Drop configure script in favour of native Makefile env and checks (@JoelSpeed)
2829- [#487](https://github.com/oauth2-proxy/oauth2-proxy/pull/487) Switch flags to PFlag to remove StringArray (@JoelSpeed)
2930- [#484](https://github.com/oauth2-proxy/oauth2-proxy/pull/484) Replace configuration loading with Viper (@JoelSpeed)
3031- [#499](https://github.com/oauth2-proxy/oauth2-proxy/pull/499) Add `-user-id-claim` to support generic claims in addition to email (@holyjak)
CONTRIBUTING.md−1
@@ -9,7 +9,6 @@ Download the dependencies using `go mod download`.
99cd $GOPATH/src/github.com # Create this directory if it doesn't exist
1010git clone git@github.com:<YOUR_FORK>/oauth2-proxy oauth2-proxy/oauth2-proxy
1111cd oauth2-proxy/oauth2-proxy
12−./configure # Setup your environment variables
1312go mod download
1413```
1514
Dockerfile+1−1
@@ -19,7 +19,7 @@ COPY . .
1919# build the key into the container and then tell it where it is
2020# by setting OAUTH2_PROXY_JWT_KEY_FILE=/etc/ssl/private/jwt_signing_key.pem
2121# in app.yaml instead.
22−RUN ./configure && make build && touch jwt_signing_key.pem
22+RUN make build && touch jwt_signing_key.pem
2323
2424# Copy binary to alpine
2525FROM alpine:3.11
Dockerfile.arm64+1−1
@@ -19,7 +19,7 @@ COPY . .
1919# build the key into the container and then tell it where it is
2020# by setting OAUTH2_PROXY_JWT_KEY_FILE=/etc/ssl/private/jwt_signing_key.pem
2121# in app.yaml instead.
22−RUN ./configure && GOARCH=arm64 make build && touch jwt_signing_key.pem
22+RUN GOARCH=arm64 make build && touch jwt_signing_key.pem
2323
2424# Copy binary to alpine
2525FROM arm64v8/alpine:3.11
Dockerfile.armv6+1−1
@@ -19,7 +19,7 @@ COPY . .
1919# build the key into the container and then tell it where it is
2020# by setting OAUTH2_PROXY_JWT_KEY_FILE=/etc/ssl/private/jwt_signing_key.pem
2121# in app.yaml instead.
22−RUN ./configure && GOARCH=arm GOARM=6 make build && touch jwt_signing_key.pem
22+RUN GOARCH=arm GOARM=6 make build && touch jwt_signing_key.pem
2323
2424# Copy binary to alpine
2525FROM arm32v6/alpine:3.11
Makefile+23−3
@@ -1,10 +1,18 @@
1−include .env
1+GO ?= go
2+GOLANGCILINT ?= golangci-lint
3+
24BINARY := oauth2-proxy
35VERSION := $(shell git describe --always --dirty --tags 2>/dev/null || echo "undefined")
46# Allow to override image registry.
57REGISTRY ?= quay.io/oauth2-proxy
68.NOTPARALLEL:
79
10+GO_MAJOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
11+GO_MINOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
12+MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1
13+MINIMUM_SUPPORTED_GO_MINOR_VERSION = 14
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)
15+
816.PHONY: all
917all: lint $(BINARY)
1018
@@ -18,11 +26,11 @@ distclean: clean
1826 rm -rf vendor
1927
2028.PHONY: lint
21−lint:
29+lint: validate-go-version
2230 GO111MODULE=on $(GOLANGCILINT) run
2331
2432.PHONY: build
25−build: clean $(BINARY)
33+build: validate-go-version clean $(BINARY)
2634
2735$(BINARY):
2836 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
6270.PHONY: release
6371release: lint test
6472 BINARY=${BINARY} VERSION=${VERSION} ./dist.sh
73+
74+.PHONY: validate-go-version
75+validate-go-version: ## Validates the installed version of go against Mattermost's minimum requirement.
76+ @if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
77+ exit 0 ;\
78+ elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
79+ echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
80+ exit 1; \
81+ elif [ $(GO_MINOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \
82+ echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
83+ exit 1; \
84+ fi
configuredeleted−139
@@ -1,139 +0,0 @@
1−#!/usr/bin/env bash
2−
3−RED='\033[0;31m'
4−GREEN='\033[0;32m'
5−BLUE='\033[0;34m'
6−NC='\033[0m'
7−
8−if [ -z "${BASH_VERSINFO}" ] || [ -z "${BASH_VERSINFO[0]}" ] || [ ${BASH_VERSINFO[0]} -lt 4 ]; then
9− echo "This script requires Bash version >= 4"; exit 1;
10−fi
11−
12−declare -A tools=()
13−declare -A desired=()
14−
15−for arg in "$@"; do
16− case ${arg%%=*} in
17− "--with-go")
18− desired[go]="${arg##*=}"
19− ;;
20− "--help")
21− printf "${GREEN}$0${NC}\n"
22− printf " available options:\n"
23− printf " --with-go=${BLUE}<path_to_go_binary>${NC}\n"
24− exit 0
25− ;;
26− *)
27− echo "Unknown option: $arg"
28− exit 2
29− ;;
30− esac
31−done
32−
33−vercomp () {
34− if [[ $1 == $2 ]]
35− then
36− return 0
37− fi
38− local IFS=.
39− local i ver1=($1) ver2=($2)
40− # fill empty fields in ver1 with zeros
41− for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
42− do
43− ver1[i]=0
44− done
45− for ((i=0; i<${#ver1[@]}; i++))
46− do
47− if [[ -z ${ver2[i]} ]]
48− then
49− # fill empty fields in ver2 with zeros
50− ver2[i]=0
51− fi
52− if ((10#${ver1[i]} > 10#${ver2[i]}))
53− then
54− return 1
55− fi
56− if ((10#${ver1[i]} < 10#${ver2[i]}))
57− then
58− return 2
59− fi
60− done
61− return 0
62−}
63−
64−check_for() {
65− echo -n "Checking for $1... "
66− if ! [ -z "${desired[$1]}" ]; then
67− TOOL_PATH="${desired[$1]}"
68− else
69− TOOL_PATH=$(command -v $1)
70− fi
71− if ! [ -x "$TOOL_PATH" -a -f "$TOOL_PATH" ]; then
72− printf "${RED}not found${NC}\n"
73− cd -
74− exit 1
75− else
76− printf "${GREEN}found${NC}\n"
77− tools[$1]=$TOOL_PATH
78− fi
79−}
80−
81−check_go_version() {
82− echo -n "Checking go version... "
83− GO_VERSION=$(${tools[go]} version | ${tools[awk]} '{where = match($0, /[0-9]\.[0-9]+\.[0-9]*/); if (where != 0) print substr($0, RSTART, RLENGTH)}')
84− vercomp $GO_VERSION 1.14
85− case $? in
86− 0) ;&
87− 1)
88− printf "${GREEN}"
89− echo $GO_VERSION
90− printf "${NC}"
91− ;;
92− 2)
93− printf "${RED}"
94− echo "$GO_VERSION < 1.14"
95− exit 1
96− ;;
97− esac
98− VERSION=$(${tools[go]} version | ${tools[awk]} '{print $3}')
99− tools["go_version"]="${VERSION}"
100−}
101−
102−check_docker_version() {
103− echo -n "Checking docker version... "
104− DOCKER_VERSION=$(${tools[docker]} version | ${tools[awk]})
105−}
106−
107−check_go_env() {
108− echo -n "Checking \$GOPATH... "
109− GOPATH="$(go env GOPATH)"
110− if [ -z "$GOPATH" ]; then
111− printf "${RED}invalid${NC} - GOPATH not set\n"
112− exit 1
113− fi
114− printf "${GREEN}valid${NC} - $GOPATH\n"
115−}
116−
117−cd ${0%/*}
118−
119−rm -fv .env
120−
121−check_for make
122−check_for awk
123−check_for go
124−check_go_version
125−check_go_env
126−check_for golangci-lint
127−
128−echo
129−
130−cat <<- EOF > .env
131− MAKE := "${tools[make]}"
132− GO := "${tools[go]}"
133− GO_VERSION := ${tools[go_version]}
134− GOLANGCILINT := "${tools[golangci-lint]}"
135−EOF
136−
137−echo "Environment configuration written to .env"
138−
139−cd - > /dev/null