-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathMakefile
More file actions
198 lines (162 loc) · 7.13 KB
/
Makefile
File metadata and controls
198 lines (162 loc) · 7.13 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
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
190
191
192
193
194
195
196
197
198
.PHONY: help setup install build clean full-clean \
up up-watch up-webapp up-webapp-watch up-full up-full-watch start stop down \
db-session webapp-shell webapp-py-repl scripts-shell scripts-py-repl test test-x \
active-build active-up active-up-watch active-test active-test-x active-down active-clean
.DEFAULT_GOAL := help
compose_file = docker-compose.yml
can_build_active_images = true
ifeq ($(shell uname -m),arm64)
compose_file = docker-compose.arm64.yml
can_build_active_images = false
endif
compose_command = docker-compose --file $(compose_file)
help:
@echo "Usage: make [COMMAND]"
@echo ""
@echo "Commands:"
@echo ""
@echo " help - Display this help text"
@echo ""
@echo " Local Development, Setup and Teardown:"
@echo ""
@echo " build - Build the local Docker images"
@echo " clean - Take down the local cluster and removes the db volume"
@echo " full-clean - Take down the local cluster and remove containers, volumes, and images"
@echo ""
@echo " Local Development, Cluster Control:"
@echo ""
@echo " up - Bring up the local cluster in detached mode"
@echo " up-watch - Bring up the local cluster, attach to webapp and scripts"
@echo " up-webapp - Start the webapp, db, and elasticsearch containers in detached mode"
@echo " up-webapp-watch - Start the webapp, db, and elasticsearch containers, stay attached"
@echo " up-scripts - Start the scripts, db, and elasticsearch containers in detached mode"
@echo " up-scripts-watch - Start the scripts, db, and elasticsearch containers, stay attached"
@echo " up-full - Bring up the local cluster in detached mode"
@echo " up-full-watch - Bring up the local cluster, remains attached"
@echo " start - Start a stopped cluster"
@echo " stop - Stop the cluster without removing containers"
@echo " down - Take down the local cluster"
@echo ""
@echo " Local Development, Interacting with Running Containers:"
@echo ""
@echo " db-session - Start a psql session as the superuser on the db container"
@echo " webapp-shell - Open a shell on the webapp container"
@echo " webapp-py-repl - Start a Python repl session on the webapp container, in the venv"
@echo " scripts-shell - Open a shell on the scripts container"
@echo " scripts-py-repl - Start a Python repl session on the scripts container, in the venv"
@echo " test - Run the python test suites (./tests, core/tests)"
@echo " test-x - Run the python test suites, exit at first failure"
@echo ""
@echo " CI/CD, building 'active' images for deployment (usable on amd64 ONLY):"
@echo ""
@echo " active-build - Build images based on the docker-compose.cicd.yml file"
@echo " active-up - Bring up the cluster from the docker-compose.cicd.yml file"
@echo " active-up-watch - Bring up the cluster from the docker-compose.cicd.yml file, remain attached"
@echo " active-test - Run the test suites on the active webapp container"
@echo " active-test-x - Run the test suites on the active webapp container, exit on failure"
@echo " active-down - Stop the cluster from the docker-compose.cicd.yml file, remove containers"
@echo " active-clean - Stop the 'active'/cicd cluster, remove containers and volumes"
@echo " active-full-clean - Stop the 'active'/cicd cluster, remove containers, volumes, and images"
@echo ""
##############################################################################
# Setup and Teardown Recipes
##############################################################################
build:
$(compose_command) build --build-arg build_TZ="$(TZ)"
clean:
$(compose_command) down --volumes
full-clean:
$(compose_command) down --volumes --rmi all
##############################################################################
# Cluster Control Recipes
##############################################################################
up:
$(compose_command) up -d
up-watch:
$(compose_command) up webapp scripts
up-webapp:
$(compose_command) up -d webapp
up-webapp-watch:
$(compose_command) up webapp
up-scripts:
$(compose_command) up scripts -d
up-scripts-watch:
$(compose_command) up scripts
up-full:
$(compose_command) up -d
up-full-watch:
$(compose_command) up
start:
$(compose_command) start
stop:
$(compose_command) stop
down:
$(compose_command) down
##############################################################################
# Interacting with Running Containers Recipes
##############################################################################
db-session:
docker exec -it cm_local_db psql -U postgres
webapp-shell:
docker exec -it cm_local_webapp /bin/bash
webapp-py-repl:
docker exec -it cm_local_webapp /bin/bash -c 'source $$SIMPLIFIED_VENV/bin/activate && python3'
scripts-shell:
docker exec -it cm_local_scripts /bin/bash
scripts-py-repl:
docker exec -it cm_local_scripts /bin/bash -c 'source $$SIMPLIFIED_VENV/bin/activate && python3'
test:
docker exec -it --env TESTING=1 cm_local_webapp /usr/local/bin/runinvenv /simplified_venv pytest tests core/tests -vv --disable-pytest-warnings
test-x:
docker exec -it --env TESTING=1 cm_local_webapp /usr/local/bin/runinvenv /simplified_venv pytest -x tests core/tests
##############################################################################
# CI/CD, building 'active' images for deployment Recipes
##############################################################################
active-build:
ifeq ($(can_build_active_images),true)
docker-compose --file docker-compose.cicd.yml build
else
@echo "WARNING: active-* recipes can only run on amd64 machines"
endif
active-up:
ifeq ($(can_build_active_images), true)
docker-compose --file docker-compose.cicd.yml up -d
else
@echo "WARNING: active-* recipes can only run on amd64 machines"
endif
active-up-watch:
ifeq ($(can_build_active_images),true)
docker-compose --file docker-compose.cicd.yml up
else
@echo "WARNING: active-* recipes can only run on amd64 machines"
endif
active-test:
ifeq ($(can_build_active_images),true)
docker exec -it --env TESTING=1 cm_active_webapp /usr/local/bin/runinvenv /simplified_venv pytest tests core/tests
else
@echo "WARNING: active-* recipes can only run on amd64 machines"
endif
active-test-x:
ifeq ($(can_build_active_images),true)
docker exec -it --env TESTING=1 cm_active_webapp /usr/local/bin/runinvenv /simplified_venv pytest -x tests core/tests
else
@echo "WARNING: active-* recipes can only run on amd64 machines"
endif
active-down:
ifeq ($(can_build_active_images),true)
docker-compose --file docker-compose.cicd.yml down
else
@echo "WARNING: active-* recipes can only run on amd64 machines"
endif
active-clean:
ifeq ($(can_build_active_images),true)
docker-compose --file docker-compose.cicd.yml down --volumes
else
@echo "WARNING: active-* recipes can only run on amd64 machines"
endif
active-full-clean:
ifeq ($(can_build_active_images),true)
docker-compose --file docker-compose.cicd.yml down --volumes --rmi all
else
@echo "WARNING: active-* recipes can only run on amd64 machines"
endif