-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
144 lines (125 loc) · 4.76 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
# cerebrum make
DEV_CONTAINER := $(shell docker ps --all --format "{{.ID}}\t{{.Names}}" | grep cerebrum_mysql_dev_db | cut -f1)
TEST_CONTAINER := $(shell docker ps --all --format "{{.ID}}\t{{.Names}}" | grep cerebrum_mysql_test_db | cut -f1)
.PHONY: list # show all make targets
list:
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' #| sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs
.PHONY: help # show all make targets with descriptions
help:
@echo "-----------------------"
@echo "| help |"
@echo "-----------------------"
@echo "| TARGET: DESCRIPTION |"
@echo "-----------------------"
@grep '^.PHONY: .* #' Makefile | sed 's/\.PHONY: \(.*\) # \(.*\)/\1: \2/'
.PHONY: godoc # run godoc server and site on port 6060 to see package docs
godoc:
godoc -play=true -index -http=:6060
.PHONY: init # install package and development dependencies such as docker, npm, swagger compiler, golang/dep
init:
./scripts/setup.bash
.PHONY: dep # install the project's dependencies
dep:
dep ensure -v
.PHONY: update # update all go package dependencies
update:
dep ensure --update -v
.PHONY: setup # setup development env or start docker dev db, bootstrap it and serve application
setup:
ifeq ($(FOR),app)
@make ENV=dev docker
@make bootstrap
go run -x cmd/api/main.go
else ifeq ($(FOR),env)
./scripts/setup.bash
else
@echo 'Usage: $ make FOR=VAR setup'
@echo 'where VAR could be `env` or `app`'
@echo 'run `$$ make help` for more info'
endif
.PHONY: serve # starts backend server, executes $ go run cmd/api/main.go
serve:
@make ENV=dev docker
go run -x cmd/api/main.go
.PHONY: docker # start docker dev dependencies, executes $ docker-compose --file ./build/package/docker/docker-compose.yml --file ./build/package/docker/docker-compose.dev.yml up --detach
docker:
ifeq ($(ENV),dev)
if ! [ -z $(TEST_CONTAINER) ]; then \
if [[ `docker inspect -f {{.State.Running}} $(TEST_CONTAINER)` = true ]]; then docker stop $(TEST_CONTAINER); fi \
fi
if [ -z $(DEV_CONTAINER) ] || [ `docker inspect -f {{.State.Running}} $(DEV_CONTAINER)` = false ]; then \
docker-compose --file ./build/package/docker/docker-compose.yml up --detach db_dev \
&& echo -e "... zzz\ngoing to sleep to allow mysql enough time to startup" \
&& sleep 10; fi
else ifeq ($(ENV),test)
if ! [ -z $(DEV_CONTAINER) ]; then \
if [[ `docker inspect -f {{.State.Running}} $(DEV_CONTAINER)` = true ]]; then docker stop $(DEV_CONTAINER); fi \
fi
if [ -z $(TEST_CONTAINER) ] || [ `docker inspect -f {{.State.Running}} $(TEST_CONTAINER)` = false ]; then \
docker-compose --file ./build/package/docker/docker-compose.yml up --detach db_test \
&& echo -e "... zzz\ngoing to sleep to allow mysql enough time to startup" \
&& sleep 10; fi
else
@echo 'Usage: $ make ENV=VAR docker'
@echo 'where VAR could be `test` or `dev`'
@echo 'run `$$ make help` for more info'
endif
.PHONY: bootstrap # bootstrap the db with dev models
bootstrap:
go run -x scripts/bootstrap/main.go
.PHONY: mysql # login to mysql dev container to inspect
mysql:
@make ENV=dev docker
docker exec -it $(DEV_CONTAINER) mysql -u root
.PHONY: test_script # runs a test script $ go run scripts/testing/main.go
test_script:
@make ENV=dev docker
go run -x scripts/testing/main.go
.PHONY: test # run all tests
test:
@make ENV=test docker
@make test_go
@make lint
.PHONY: test_go # run all go file tests
test_go:
./scripts/test.bash
.PHONY: lint # run linters on go package
lint:
golint pkg/...
golint cmd/...
.PHONY: swagger # compile swagger spec file from swagger directories. Usage: make TYPE=XXXXX swagger
swagger:
ifdef TYPE
cd third_party/swaggerui/spec && \
multi-file-swagger -o $(TYPE) index.yaml > compiled/full_spec.$(TYPE) && \
cp -rf compiled/full_spec.$(TYPE) ../dist/full_spec.yaml && \
cd -
else
@echo 'Usage: $ make TYPE=VAR swagger'
@echo 'where VAR is a valid file extension like `yaml` or `json`'
@echo 'run `$$ make help` for more info'
endif
.PHONY: clean # removes docker containers from the environmental variable ENV such as `test`
clean:
ifeq ($(ENV),dev)
docker stop $(DEV_CONTAINER)
docker rm $(DEV_CONTAINER)
else ifeq ($(ENV),test)
docker stop $(TEST_CONTAINER)
docker rm $(TEST_CONTAINER)
else ifeq ($(ENV),all)
@make ENV=dev clean
@make ENV=test clean
else
@echo 'Usage: $ make ENV=VAR clean'
@echo 'where VAR could be `test`, `dev` or `all`'
@echo 'run `$$ make help` for more info'
endif
.PHONY: refresh # refresh all docker db's and bootstrap a new dev db
refresh:
@make ENV=all clean
@make ENV=dev docker
@make bootstrap
.PHONY: remove_mysql_image # removes mysql:latest docker image
remove_mysql_image:
docker images --format "{{.Repository}}:{{.Tag}}\t{{.ID}}" --all | grep mysql:latest | cut -f2 | xargs docker rmi