-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
132 lines (99 loc) · 4.57 KB
/
Makefile
File metadata and controls
132 lines (99 loc) · 4.57 KB
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
# mystack-controller api
# https://github.com/topfreegames/mystack-controller
#
# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright © 2017 Top Free Games <backend@tfgco.com>
MY_IP=`ifconfig | grep --color=none -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep --color=none -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | head -n 1`
TEST_PACKAGES=`find . -type f -name "*.go" ! \( -path "*vendor*" \) | sed -En "s/([^\.])\/.*/\1/p" | uniq`
setup: setup-hooks
@go get -u github.com/golang/dep/...
@go get -u github.com/jteeuwen/go-bindata/...
@go get -u github.com/wadey/gocovmerge
@dep ensure
setup-hooks:
@cd .git/hooks && ln -sf ../../hooks/pre-commit.sh pre-commit
setup-ci:
@go get -u github.com/golang/dep/...
@go get github.com/onsi/ginkgo/ginkgo
@go get -u github.com/wadey/gocovmerge
@go get -u github.com/jteeuwen/go-bindata/...
@dep ensure
build:
@mkdir -p bin && go build -o ./bin/mystack-controller main.go
build-docker: cross-build-linux-amd64
@docker build -t mystack-controller .
cross-build-linux-amd64:
@env GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o ./bin/mystack-controller-linux-amd64
@chmod a+x ./bin/mystack-controller-linux-amd64
assets:
@go-bindata -o migrations/migrations.go -pkg migrations migrations/*.sql
migrate: assets
@go run main.go migrate -c ./config/local.yaml
migrate-test: assets
@go run main.go migrate -c ./config/test.yaml
deps: start-deps wait-for-pg
start-deps:
@echo "Starting dependencies using HOST IP of ${MY_IP}..."
@env MY_IP=${MY_IP} docker-compose --project-name mystack up -d
@sleep 10
@echo "Dependencies started successfully."
stop-deps:
@env MY_IP=${MY_IP} docker-compose --project-name mystack down
wait-for-pg:
@until docker exec mystack_postgres_1 pg_isready; do echo 'Waiting for Postgres...' && sleep 1; done
@sleep 2
deps-test: deps drop-test migrate-test
drop:
@-psql -d postgres -h localhost -p 8585 -U postgres -c "SELECT pg_terminate_backend(pid.pid) FROM pg_stat_activity, (SELECT pid FROM pg_stat_activity where pid <> pg_backend_pid()) pid WHERE datname='mystack';"
@psql -d postgres -h localhost -p 8585 -U postgres -f scripts/drop.sql > /dev/null
@echo "Database created successfully!"
drop-test:
@-psql -d postgres -h localhost -p 8585 -U postgres -c "SELECT pg_terminate_backend(pid.pid) FROM pg_stat_activity, (SELECT pid FROM pg_stat_activity where pid <> pg_backend_pid()) pid WHERE datname='mystack-test';"
@psql -d postgres -h localhost -p 8585 -U postgres -f scripts/drop-test.sql > /dev/null
@echo "Test Database created successfully!"
run:
@go run main.go start -v3 -c ./config/local.yaml
run-out:
@go run main.go start -v3 -c ./config/local.yaml -o
run-dev:
@mkdir -p ~/.mystack
@echo '{"controllerUrl": "http://localhost:8080"}' > ~/.mystack/mystack-dev.json
@MYSTACK_OAUTH_ENABLED=false go run main.go start -v3 -c ./config/local.yaml -o
run-full: deps drop migrate run
unit: unit-board clear-coverage-profiles unit-run gather-unit-profiles
clear-coverage-profiles:
@find . -name '*.coverprofile' -delete
unit-board:
@echo
@echo "\033[1;34m=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\033[0m"
@echo "\033[1;34m= Unit Tests -\033[0m"
@echo "\033[1;34m=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\033[0m"
unit-run:
@ginkgo -tags unit -cover -r -randomizeAllSpecs -randomizeSuites -skipMeasurements ${TEST_PACKAGES}
gather-unit-profiles:
@mkdir -p _build
@echo "mode: count" > _build/coverage-unit.out
@bash -c 'for f in $$(find . -name "*.coverprofile"); do tail -n +2 $$f >> _build/coverage-unit.out; done'
integration int: integration-board deps-test clear-coverage-profiles integration-run gather-integration-profiles
integration-board:
@echo
@echo "\033[1;34m=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\033[0m"
@echo "\033[1;34m= Integration Tests -\033[0m"
@echo "\033[1;34m=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\033[0m"
integration-run:
@ginkgo -tags integration -cover -r -randomizeAllSpecs -randomizeSuites -skipMeasurements ${TEST_PACKAGES}
gather-integration-profiles:
@mkdir -p _build
@echo "mode: count" > _build/coverage-integration.out
@bash -c 'for f in $$(find . -name "*.coverprofile"); do tail -n +2 $$f >> _build/coverage-integration.out; done'
merge-profiles:
@mkdir -p _build
@gocovmerge _build/*.out > _build/coverage-all.out
test-coverage-func coverage-func: merge-profiles
@echo
@echo "\033[1;34m=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\033[0m"
@echo "\033[1;34mFunctions NOT COVERED by Tests\033[0m"
@echo "\033[1;34m=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\033[0m"
@go tool cover -func=_build/coverage-all.out | egrep -v "100.0[%]"
test: unit integration test-coverage-func