-
Notifications
You must be signed in to change notification settings - Fork 26
/
Makefile
189 lines (150 loc) · 7.67 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
export SHELL := /bin/bash
API_VERSION:=$(shell cat API_VERSION)
.PHONY: default PHONY clean offline prepare dep test unit-test whitebox-integration-test coverage blackbox-integration-test shell-test-alpine shell-test-wrong-image shell-test-docker-socket shell-test-docker-tcp shell-test-pullpush start-local-registry stop-local-registry push-to-local-registry stress-test stress-test-async stress-test-wait lint vet fail-on-errors docker-image build xbuild changelog release validate-release deploy deploy-github deploy-docker poc-app wrapper install
default: prepare dep test lint vet build
PHONY:
@egrep "^[0-9a-zA-Z_\-]+:( |$$)" Makefile \
| cut -d":" -f1 | uniq | tr '\n' ' ' | sed 's/^/.PHONY: /;s/ $$//' \
| xargs -I {} sed -i "s/^\.PHONY:.*$$/{}/" Makefile
clean:
git clean -fdx
offline: unit-test lint vet build
prepare:
go get -u \
golang.org/x/lint/golint \
github.com/go-playground/overalls \
github.com/mattn/goveralls
dep:
go mod verify
go mod vendor
test: unit-test whitebox-integration-test
unit-test:
@find . \
-mindepth 2 -type f ! -path "./vendor/*" ! -path "./api/*" -name "*_test.go" \
| xargs -I {} dirname {} \
| xargs -I {} bash -c "pushd {}; go test -v -cover || exit 1; popd"
whitebox-integration-test:
@find . \
-mindepth 2 -type f -path "./api/*" -name "*_test.go" \
| xargs -I {} dirname {} \
| xargs -I {} bash -c "pushd {}; go test -v -cover || exit 1; popd"
coverage: SERVICE:=ci
coverage:
@overalls -project=${PWD} -covermode=count \
&& if [[ -n "${COVERALLS_REPO_TOKEN}" ]]; then goveralls -coverprofile=overalls.coverprofile -repotoken ${COVERALLS_REPO_TOKEN} -service=${SERVICE}; fi
blackbox-integration-test: shell-test-docker-socket shell-test-docker-tcp shell-test-pullpush
shell-test-docker-socket:
unset DOCKER_HOST && ./lstags alpine~/latest/
shell-test-docker-tcp: DOCKER_HOST:=tcp://127.0.0.1:2375
shell-test-docker-tcp:
./lstags nginx~/stable/
shell-test-pullpush: start-local-registry push-to-local-registry stop-local-registry
start-local-registry: REGISTRY_PORT:=5757
start-local-registry:
docker run -d -p ${REGISTRY_PORT}:5000 --name registry-lstags registry:2
stop-local-registry:
docker rm -f registry-lstags || true
push-to-local-registry: REPOSITORIES:=alpine:latest busybox:latest
push-to-local-registry: REGISTRY_PORT:=5757
push-to-local-registry:
./lstags --push-registry=localhost:${REGISTRY_PORT} ${REPOSITORIES}
stress-test: YAML_CONFIG:=./fixtures/config/config-stress.yaml
stress-test: CONCURRENT_REQUESTS:=64
stress-test:
./lstags --yaml-config=${YAML_CONFIG} --concurrent-requests=${CONCURRENT_REQUESTS}
stress-test-async: YAML_CONFIG:=./fixtures/config/config-stress.yaml
stress-test-async: CONCURRENT_REQUESTS:=64
stress-test-async:
@scripts/async-run.sh stress-test make stress-test YAML_CONFIG=${YAML_CONFIG} CONCURRENT_REQUESTS=${CONCURRENT_REQUESTS}
stress-test-wait: TIME:=180
stress-test-wait: MODE:=verbose
stress-test-wait:
@scripts/async-wait.sh stress-test ${TIME} ${MODE}
lint: ERRORS=$(shell find . -name "*.go" ! -path "./vendor/*" | xargs -I {} golint {} | tr '`' '|')
lint: fail-on-errors
vet: ERRORS=$(shell go vet)
vet: fail-on-errors
semantic: REGEX:="^(feat|fix|docs|style|refactor|test|chore|localize|security)(\([a-zA-Z0-9\/_-]+\))?: [a-zA-Z]"
semantic:
@if [[ -n "${RANGE}" ]]; then \
git log --pretty="format:%s" ${RANGE} | egrep -v "(Merge pull request|Merge branch)" \
| egrep -v ${REGEX} | awk '{print "NON-SEMANTIC: "$$0}' | grep . \
&& echo -e "\e[1m\e[31mFATAL: Non-semantic commit messages found (${RANGE})!\e[0m" && exit 1 || echo "OK"; \
else \
echo -e "\e[33mERROR: Please define 'RANGE' variable!\e[0m"; exit 1; \
fi
fail-on-errors:
@echo "${ERRORS}" | grep . || echo "OK"
@test `echo "${ERRORS}" | grep . | wc -l` -eq 0
./dist/assets/lstags-linux/lstags: export GOOS:=linux
./dist/assets/lstags-linux/lstags:
mkdir -p dist/assets/lstags-linux; \
go build -mod=vendor -ldflags '-s -w' -a -tags netgo -installsuffix netgo -o dist/assets/lstags-linux/lstags
docker-image: DOCKER_REPO:=ivanilves/lstags
docker-image: DOCKER_TAG:=latest
docker-image: ./dist/assets/lstags-linux/lstags
docker-image:
@docker image build --no-cache -t ${DOCKER_REPO}:${DOCKER_TAG} .
build: LDFLAGS=$(shell test `uname -s` = "Darwin" && echo '-s -w' || echo '-d -s -w')
build: NAME=$(shell test "${GOOS}" = "windows" && echo 'lstags.exe' || echo 'lstags')
build:
@if [[ -z "${GOOS}" ]]; then go build -mod=vendor -ldflags '${LDFLAGS}' -a -tags netgo -installsuffix netgo; fi
@if [[ -n "${GOOS}" ]]; then mkdir -p dist/assets/lstags-${GOOS}; GOOS=${GOOS} go build -mod=vendor -ldflags '-s -w' -a -tags netgo -installsuffix netgo -o dist/assets/lstags-${GOOS}/${NAME}; fi
xbuild:
${MAKE} --no-print-directory build GOOS=linux
${MAKE} --no-print-directory build GOOS=darwin
${MAKE} --no-print-directory build GOOS=windows
changelog: LAST_RELEASED_TAG:=$(shell git tag --sort=creatordate | tail -n1)
changelog: GITHUB_COMMIT_URL:=https://github.com/ivanilves/lstags/commit
changelog:
@echo "## Changelog" \
&& git log --oneline --reverse ${LAST_RELEASED_TAG}..HEAD | egrep -iv "^[0-9a-f]{7,} (Merge pull request |Merge branch |.*NORELEASE)" | \
sed -r "s|^([0-9a-f]{7,}) (.*)|* [\`\1\`](${GITHUB_COMMIT_URL}/\1) \2|"
release: clean
release: LAST_BUILD_NUMBER:=$(shell git fetch --tags && git tag --sort=creatordate | grep "^v${API_VERSION}\." | tail -n1 | sed 's/^v.*\.//' | grep . || echo -1)
release: THIS_BUILD_NUMBER:=$(shell expr ${LAST_BUILD_NUMBER} + 1)
release: THIS_RELEASE_NAME:=v${API_VERSION}.${THIS_BUILD_NUMBER}
release:
mkdir -p ./dist/release ./dist/assets \
&& sed -i "s/CURRENT/${THIS_RELEASE_NAME}/" ./version.go && ${MAKE} xbuild && git checkout ./version.go \
&& echo ${THIS_RELEASE_NAME} > ./dist/release/NAME && echo ${THIS_RELEASE_NAME} > ./dist/release/TAG \
&& ${MAKE} --no-print-directory changelog > ./dist/release/CHANGELOG.md \
&& cp README.md ./dist/assets/
validate-release:
test -s ./dist/release/TAG && test -s ./dist/release/NAME
test -f ./dist/release/CHANGELOG.md && grep '^\* ' ./dist/release/CHANGELOG.md >/dev/null
[[ `find dist/assets -mindepth 2 -type f | wc -l` -ge 3 ]]
deploy: DO_RELEASE:=$(shell git log --oneline -n1 | grep -i "Merge.*NORELEASE" >/dev/null && echo "false" || echo "true")
deploy: deploy-github deploy-docker
deploy-github: TAG=$(shell cat ./dist/release/TAG)
deploy-github:
@if [[ "${DO_RELEASE}" == "true" ]]; then \
${MAKE} --no-print-directory validate-release \
&& test -n "${GITHUB_TOKEN}" && git tag ${TAG} && git push --tags \
&& GITHUB_TOKEN=${GITHUB_TOKEN} scripts/github-create-release.sh ./dist/release \
&& GITHUB_TOKEN=${GITHUB_TOKEN} scripts/github-upload-assets.sh ${TAG} ./dist/assets; \
else \
echo "NB! GitHub release skipped! (DO_RELEASE != true)"; \
fi
deploy-docker: DOCKER_REPO:=ivanilves/lstags
deploy-docker: DOCKER_TAG=$(shell cat ./dist/release/TAG)
deploy-docker:
@if [[ "${DO_RELEASE}" == "true" ]]; then \
docker tag ${DOCKER_REPO}:release ${DOCKER_REPO}:${DOCKER_TAG} && docker tag ${DOCKER_REPO}:release ${DOCKER_REPO}:latest \
&& docker push ${DOCKER_REPO}:${DOCKER_TAG} && docker push ${DOCKER_REPO}:latest; \
else \
echo "NB! Docker release skipped! (DO_RELEASE != true)"; \
fi
poc-app: APP_PATH=../lstags-api
poc-app: prepare dep
poc-app:
@echo -e "\e[1mInitializing PoC application:\e[0m" \
&& mkdir -p ${APP_PATH} \
&& cp api_poc.go.sample ${APP_PATH}/main.go \
&& pushd ${APP_PATH} >/dev/null; go build -mod=vendor; pwd; popd >/dev/null \
&& echo -e "\e[31mHINT: Set 'APP_PATH' makefile variable to adjust PoC application path ;)\e[0m"
wrapper: PARAMS?=$(shell test "$${UID}" = "0" && echo "-o root -g 0 -m755" || echo "-m755")
wrapper: PREFIX:=/usr/local
wrapper:
install ${PARAMS} scripts/wrapper.sh ${PREFIX}/bin/lstags
install: wrapper