git.iko.soy/typeable/oauth2-proxy
on master help sign in
Introduce Makefile
commit372ecd0cf81721b81b59a8ca4a90359410f6554b authorJoel Speed <Joel.speed@hotmail.co.uk> dateFri 4 Jan 2019, 10:58 (8 years ago) parent9096c70
11 files changed+209−26
.env+3 .travis.yml+2−7 CHANGELOG.md+6 CONTRIBUTING.md+1−1 Dockerfile+3−3 Makefile+55 configure+137 lint.sh−11 main.go+1−1 test.sh−2 version.go+1−1
.envnew file+3
@@ -0,0 +1,3 @@
1+MAKE := "/usr/bin/make"
2+ GO := "/usr/local/bin/go"
3+ DEP := "/usr/local/bin/dep"
.travis.yml+2−7
@@ -6,15 +6,10 @@ install:
66 # Fetch dependencies
77 - wget -O dep https://github.com/golang/dep/releases/download/v0.3.2/dep-linux-amd64
88 - chmod +x dep
9− - ./dep ensure --vendor-only
109script:
11− - set -e
12− # Lint
13− - go get -u github.com/alecthomas/gometalinter
14− - gometalinter --install
15− - ./lint.sh
10+ - ./configure
1611 # Run tests
17− - ./test.sh
12+ - make test
1813sudo: false
1914notifications:
2015 email: false
CHANGELOG.md+6
@@ -2,6 +2,12 @@
22
33## Changes since v2.2:
44
5+- Move automated build to debian base image
6+- Add Makefile
7+ - Update CI to run `make test`
8+ - Update Dockerfile to use `make clean oauth2_proxy`
9+ - Update `VERSION` parameter to be set by `ldflags` from Git Status
10+ - Remove lint and test scripts
511- Remove Go v1.8.x from Travis CI testing
612- Add CODEOWNERS file
713- Add CONTRIBUTING guide
CONTRIBUTING.md+1−1
@@ -8,7 +8,7 @@ Download the dependencies using [`dep`](https://github.com/golang/dep).
88```bash
99cd $GOPATH/src/github.com # Create this directory if it doesn't exist
1010git clone git@github.com:<YOUR_FORK>/oauth2_proxy pusher/oauth2_proxy
11−dep ensure # Installs dependencies to vendor folder.
11+make dep
1212```
1313
1414## Pull Requests and Issues
Dockerfile+3−3
@@ -7,10 +7,10 @@ RUN go get -u github.com/golang/dep/cmd/dep
77RUN dep ensure --vendor-only
88
99# Build image
10−RUN CGO_ENABLED=0 GOOS=linux go build
10+RUN ./configure && make clean oauth2_proxy
1111
12−# Copy binary to alpine
13−FROM alpine:3.8
12+# Copy binary to debian
13+FROM debian:stretch
1414COPY --from=builder /go/src/github.com/pusher/oauth2_proxy/oauth2_proxy /bin/oauth2_proxy
1515
1616ENTRYPOINT ["/bin/oauth2_proxy"]
Makefilenew file+55
@@ -0,0 +1,55 @@
1+include .env
2+BINARY := oauth2_proxy
3+VERSION := $(shell git describe --always --long --dirty --tags 2>/dev/null || echo "undefined")
4+
5+.PHONY: all
6+all: dep lint $(BINARY)
7+
8+.PHONY: clean
9+clean:
10+ rm -rf release
11+ rm -f $(BINARY)
12+
13+.PHONY: distclean
14+distclean: clean
15+ rm -rf vendor
16+
17+BIN_DIR := $(GOPATH)/bin
18+GOMETALINTER := $(BIN_DIR)/gometalinter
19+
20+$(GOMETALINTER):
21+ $(GO) get -u github.com/alecthomas/gometalinter
22+ gometalinter --install %> /dev/null
23+
24+.PHONY: lint
25+lint: $(GOMETALINTER)
26+ $(GOMETALINTER) --vendor --disable-all \
27+ --enable=vet \
28+ --enable=vetshadow \
29+ --enable=golint \
30+ --enable=ineffassign \
31+ --enable=goconst \
32+ --enable=deadcode \
33+ --enable=gofmt \
34+ --enable=goimports \
35+ --tests ./...
36+
37+.PHONY: dep
38+dep:
39+ $(DEP) ensure --vendor-only
40+
41+.PHONY: build
42+build: clean $(BINARY)
43+
44+$(BINARY):
45+ $(GO) build -ldflags="-X main.VERSION=${VERSION}" -o $(BINARY) github.com/pusher/oauth2_proxy
46+
47+.PHONY: test
48+test: dep lint
49+ $(GO) test -v -race $(go list ./... | grep -v /vendor/)
50+
51+.PHONY: release
52+release: dep lint test
53+ mkdir release
54+ GOOS=darwin GOARCH=amd64 go build -ldflags="-X main.VERSION=${VERSION}" -o release/$(BINARY)-darwin-amd64 github.com/pusher/oauth2_proxy
55+ GOOS=linux GOARCH=amd64 go build -ldflags="-X main.VERSION=${VERSION}" -o release/$(BINARY)-linux-amd64 github.com/pusher/oauth2_proxy
configurenew file+137
@@ -0,0 +1,137 @@
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+declare -A tools=()
9+declare -A desired=()
10+
11+for arg in "$@"; do
12+ case ${arg%%=*} in
13+ "--with-go")
14+ desired[go]="${arg##*=}"
15+ ;;
16+ "--with-dep")
17+ desired[dep]="${arg##*=}"
18+ ;;
19+ "--help")
20+ printf "${GREEN}$0${NC}\n"
21+ printf " available options:\n"
22+ printf " --with-dep=${BLUE}<path_to_dep_binary>${NC}\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.10
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.10"
95+ exit 1
96+ ;;
97+ esac
98+}
99+
100+check_docker_version() {
101+ echo -n "Checking docker version... "
102+ DOCKER_VERSION=$(${tools[docker]} version | ${tools[awk]})
103+}
104+
105+check_go_env() {
106+ echo -n "Checking \$GOPATH... "
107+ if [ -z "$GOPATH" ]; then
108+ printf "${RED}invalid${NC} - GOPATH not set\n"
109+ exit 1
110+ fi
111+ printf "${GREEN}valid${NC} - $GOPATH\n"
112+}
113+
114+cd ${0%/*}
115+
116+if [ ! -f .env ]; then
117+ rm .env
118+fi
119+
120+check_for make
121+check_for awk
122+check_for go
123+check_go_version
124+check_go_env
125+check_for dep
126+
127+echo
128+
129+cat <<- EOF > .env
130+ MAKE := "${tools[make]}"
131+ GO := "${tools[go]}"
132+ DEP := "${tools[dep]}"
133+EOF
134+
135+echo "Environment configuration written to .env"
136+
137+cd - > /dev/null
lint.shdeleted−11
@@ -1,11 +0,0 @@
1−#!/bin/bash
2−gometalinter --vendor --disable-all \
3−--enable=vet \
4−--enable=vetshadow \
5−--enable=golint \
6−--enable=ineffassign \
7−--enable=goconst \
8−--enable=deadcode \
9−--enable=gofmt \
10−--enable=goimports \
11−--tests ./...
main.go+1−1
@@ -84,7 +84,7 @@ func main() {
8484 flagSet.Parse(os.Args[1:])
8585
8686 if *showVersion {
87− fmt.Printf("oauth2_proxy v%s (built with %s)\n", VERSION, runtime.Version())
87+ fmt.Printf("oauth2_proxy %s (built with %s)\n", VERSION, runtime.Version())
8888 return
8989 }
9090
test.shdeleted−2
@@ -1,2 +0,0 @@
1−#!/bin/bash
2−go test -v -race $(go list ./... | grep -v /vendor/)
version.go+1−1
@@ -1,4 +1,4 @@
11package main
22
33// VERSION contains version information
4−const VERSION = "2.2.1-alpha"
4+var VERSION = "undefined"