-
Notifications
You must be signed in to change notification settings - Fork 62
/
Makefile
156 lines (128 loc) · 3.88 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
$stdout.sync = true
export VETS_API_USER_ID := $(shell id -u)
ifdef env
ENV_ARG := $(env)
else
ENV_ARG := dev
endif
ifdef clam
FOREMAN_ARG := all=1
else
FOREMAN_ARG := all=1,clamd=0,freshclam=0
endif
COMPOSE_DEV := docker-compose
COMPOSE_TEST := docker-compose -f docker-compose.test.yml
BASH := run --rm --service-ports web bash
BASH_DEV := $(COMPOSE_DEV) $(BASH) -c
BASH_TEST := $(COMPOSE_TEST) $(BASH) --login -c
SPEC_PATH := spec/ modules/
DB := "bin/rails db:setup db:migrate"
LINT := "bin/rails lint['$(files)']"
DOWN := down
SECURITY := "bin/rails security"
.DEFAULT_GOAL := ci
# cribbed from https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html and https://news.ycombinator.com/item?id=11195539
help: ## Prints out documentation for available commands
@awk -F ':|##' \
'/^[^\t].+?:.*?##/ {\
printf "\033[36m%-30s\033[0m %s\n", $$1, $$NF \
}' $(MAKEFILE_LIST)
.PHONY: ci
ci: ## Sets up databases and runs tests for ci
@$(BASH_TEST) "bin/rails db:setup db:migrate ci"
.PHONY: bash
bash: ## Starts a bash shell inside the docker container
@$(COMPOSE_DEV) $(BASH)
.PHONY: build
build: ## Builds the api
ifeq ($(ENV_ARG), dev)
$(COMPOSE_DEV) build
else
$(COMPOSE_TEST) build
endif
.PHONY: db
db: ## Sets up database and runs migrations
ifeq ($(ENV_ARG), dev)
@$(BASH_DEV) $(DB)
else
@$(BASH_TEST) $(DB)
endif
.PHONY: lint
lint: ## runs the linter
ifeq ($(ENV_ARG), dev)
@$(BASH_DEV) $(LINT)
else
@$(BASH_TEST) $(LINT)
endif
.PHONY: console
console: ## Starts a rails console
@$(BASH_DEV) "bundle exec rails c"
.PHONY: danger
danger: ## Runs the danger static analysis
@$(BASH_TEST) "bundle exec danger --verbose"
.PHONY: docker-clean
docker-clean: ## Removes all docker images and volumes associated with vets-api
@$(COMPOSE_DEV) down --rmi all --volumes
.PHONY: down
down: ## Stops all docker services
ifeq ($(ENV_ARG), dev)
@$(COMPOSE_DEV) $(DOWN)
else
@$(COMPOSE_TEST) $(DOWN)
endif
.PHONY: guard
guard: ## Runs guard
@$(BASH_DEV) "bundle exec guard"
.PHONY: migrate
migrate: ## Runs the database migrations
@$(BASH_DEV) "bin/rails db:migrate"
.PHONY: rebuild
rebuild: down ## Stops the docker services and builds the api
@$(COMPOSE_DEV) build
.PHONY: security
security: ## Runs security scans
ifeq ($(ENV_ARG), dev)
@$(BASH_DEV) $(SECURITY)
else
@$(BASH_TEST) $(SECURITY)
endif
.PHONY: server
server: ## Starts the server (natively)
@$(BASH_DEV) "rm -f tmp/pids/server.pid && bundle exec rails server"
.PHONY: spec
spec: ## Runs spec tests
@$(BASH_DEV) "RAILS_ENV=test bin/rspec ${SPEC_PATH}"
.PHONY: spec_parallel_setup
spec_parallel_setup: ## Setup the parallel test dbs. This resets the current test db, as well as the parallel test dbs
ifeq ($(ENV_ARG), dev)
@$(BASH_DEV) "RAILS_ENV=test DISABLE_BOOTSNAP=true bundle exec parallel_test -e 'bundle exec rake db:reset db:migrate'"
else
@$(COMPOSE_TEST) $(BASH) -c "RAILS_ENV=test DISABLE_BOOTSNAP=true parallel_test -e 'bundle exec rake db:reset db:migrate'"
endif
.PHONY: spec_parallel
spec_parallel: ## Runs spec tests in parallel
ifeq ($(ENV_ARG), dev)
@$(BASH_DEV) "RAILS_ENV=test DISABLE_BOOTSNAP=true NOCOVERAGE=true bundle exec parallel_rspec ${SPEC_PATH}"
else
@$(COMPOSE_TEST) $(BASH) -c "DISABLE_BOOTSNAP=true bundle exec parallel_rspec ${SPEC_PATH}"
endif
.PHONY: up
up: db ## Starts the server and associated services with docker-compose
@$(BASH_DEV) "rm -f tmp/pids/server.pid && bundle exec foreman start -m all=1"
# NATIVE COMMANDS
.PHONY: native-up
native-up:
bundle install
foreman start -m all=1
.PHONY: native-lint
native-lint:
bundle exec rake lint
.PHONY: native-spec
native-spec:
bundle exec rake spec
.PHONY: native-spec-parallel
native-spec-parallel:
RAILS_ENV=test NOCOVERAGE=true bundle exec rake parallel:spec
.PHONY: native-spec-parallel-setup
native-spec-parallel-setup:
RAILS_ENV=test bundle exec rake parallel:setup