-
Notifications
You must be signed in to change notification settings - Fork 13
/
Makefile
266 lines (220 loc) · 9.56 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# TODO: Some of these should be converted into Ansible Playbooks when there's time.
# Chose a makefile because its easier to read over a bunch of if statements inside a bash script.
# We are taking advantage of .PHONY that is available in makefiles to create this simple looking
# list of command shortcuts
# Portable replacement for `sed` or `gsed`
# See https://unix.stackexchange.com/questions/92895/how-can-i-achieve-portability-with-sed-i-in-place-editing
REPLACE := perl -i -pe
RODAN_PATH := ./rodan-main/code/rodan
JOBS_PATH := $(RODAN_PATH)/jobs
PROD_TAG := v3.1.0
DOCKER_TAG := nightly
# Individual Commands
build:
@echo "[-] Rebuilding Docker Images for Rodan..."
# Build py3-celery, because it's needed for Rodan and Celery images
# @docker-compose -f build.yml build --no-cache py3-celery # Sometimes it's better to use the
# no-cache option if something unexplicably broke with the py3-celery image (a cached build step perhaps)
@docker compose -f build.yml build --no-cache py3-celery
# Build rodan and rodan-client because they are needed for nginx
@docker compose -f build.yml build --no-cache --parallel rodan rodan-client
# DockerHub is not intuitive. You won't be able to build from the source root folder in both build contextes.
# When you build locally, the COPY command is relative to the dockerfile. When you build on DockerHub, its relative to the source root.
# For this reason we replace the name to build locally because we build more often on DockerHub than on local.
@$(REPLACE) "s/COPY .\/postgres\/maintenance/COPY .\/maintenance/g" ./postgres/Dockerfile || $(REPLACE) "s/COPY .\/postgres\/maintenance/COPY .\/maintenance/g" ./postgres/Dockerfile
@docker compose -f build.yml build --no-cache --parallel nginx gpu-celery postgres hpc-rabbitmq
# Revert back the change to the COPY command so it will work on Docker Hub.
@$(REPLACE) "s/COPY .\/maintenance/COPY .\/postgres\/maintenance/g" ./postgres/Dockerfile || $(REPLACE) "s/COPY .\/maintenance/COPY .\/postgres\/maintenance/g" ./postgres/Dockerfile
@echo "[+] Done."
backup_db:
@docker exec `docker ps -f name=rodan_postgres -q` backup
restore_db:
@docker exec `docker ps -f name=rodan_postgres -q` restore
# Keep in mind, you may need to deal with the postgres/maintenance/backup or backups files depending on setup
run: remote_jobs
# Run local version for dev
# Hello, 2022 hires!
@DOCKER_TAG=$(DOCKER_TAG) docker compose up
test_prod: pull_prod
# Test production Rodan images with specified tag
# May want to change test-prod-compose.yml if you want a
# different tag.
docker compose -f test-prod-compose.yml up
run_client:
# Run Rodan-Client for dev (needs local dev up and running)
@docker run -p 8080:9002 -v `pwd`/rodan-client/code:/code ddmal/rodan-client:nightly bash
deploy_staging:
# Can also be used to update a configuration (point to a different image.)
@echo "[-] Deploying Docker Swarm for: Rodan Staging"
@docker stack deploy --prune --with-registry-auth -c staging.yml rodan
@echo "[+] Done."
deploy_production:
# Can also be used to update a configuration (point to a different image.)
@echo "[-] Deploying Docker Swarm for: Rodan Production"
@docker stack deploy --with-registry-auth -c production.yml rodan
@echo "[+] Done."
copy_docker_tag:
# tag=v1.5.0rc0 make copy_docker_tag
@docker image tag $(docker images ddmal/rodan:nightly -q) ddmal/rodan:$(tag)
@docker image tag $(docker images ddmal/rodan-python3-celery:nightly -q) ddmal/rodan-python3-celery:$(tag)
@docker image tag $(docker images ddmal/rodan-gpu-celery:nightly -q) ddmal/rodan-gpu-celery:$(tag)
pull_prod:
docker pull ddmal/iipsrv:nightly
docker pull ddmal/nginx:$(PROD_TAG)
docker pull ddmal/postgres-plpython:$(PROD_TAG)
docker pull ddmal/rodan-gpu-celery:$(PROD_TAG)
docker pull ddmal/rodan-main:$(PROD_TAG)
docker pull ddmal/rodan-python3-celery:$(PROD_TAG)
docker pull rabbitmq:alpine
docker pull redis:alpine
pull_docker_tag:
# tag=v1.5.0rc0 make pull_docker_tag
@docker pull ddmal/rodan:$(tag)
@docker pull ddmal/rodan-python3-celery:$(tag)
@docker pull ddmal/rodan-gpu-celery:$(tag)
push_docker_tag:
# tag=v1.5.0rc0 make push_docker_tag
@docker push ddmal/rodan:$(tag)
@docker push ddmal/rodan-python3-celery:$(tag)
@docker push ddmal/rodan-gpu-celery:$(tag)
update:
# tag1=v1.5.0rc0 tag2=v1.3.1 make update
# This will update the nightly images forcefully
@echo "[-] Updating Docker Swarm images..."
# @docker-compose pull
# DB First
@docker service update \
--force \
--update-order start-first \
--update-delay 30s \
--image ddmal/postgres-plpython:$(tag2) \
rodan_postgres
# You need to be logged in to docker for this one.
@docker service update \
--force \
--with-registry-auth \
--update-order start-first \
--update-delay 10m \
--image ddmal/rodan:$(tag1) \
rodan_rodan-main
# These images might need time to update.
@docker service update \
--force \
--with-registry-auth \
--update-order start-first \
--stop-grace-period 9h \
--update-delay 10m \
--image ddmal/rodan:$(tag1) \
rodan_celery
# These are public images
@docker service update \
--force \
--update-order start-first \
--stop-grace-period 9h \
--update-delay 30s \
--image ddmal/rodan-python3-celery:$(tag1) \
rodan_py3-celery
@docker service update \
--force \
--update-order start-first \
--stop-grace-period 9h \
--update-delay 30s \
--image ddmal/rodan-gpu-celery:$(tag1) \
rodan_gpu-celery
# # TODO: Need to make rabbitmq durable and permanent
# # before we can make rolling updates for rabbitmq/hpc-rabbitmq.
# @docker service update \
# --force \
# --update-order start-first \
# --update-delay 30s \
# --image ddmal/hpc-rabbitmq:$(tag2) \
# rodan_hpc-rabbitmq
@docker service update \
--force \
--update-order start-first \
--update-delay 30s \
--image ddmal/nginx:$(tag2) \
rodan_nginx
@echo "[+] Done."
scale:
@docker service scale rodan_nginx=$(num)
@docker service scale rodan_rodan=$(num)
@docker service scale rodan_celery=$(num)
@docker service scale rodan_py3-celery=$(num)
# @docker service scale rodan_gpu-celery=$(num)
@docker service scale rodan_redis=$(num)
# @docker service scale rodan_postgres=$(num)
@docker service scale rodan_rabbitmq=$(num)
health:
@docker inspect --format "{{json .State.Health }}" $(log) | jq
renew_certbot:
@docker exec `docker ps -f name=rodan_nginx -q` certbot renew --no-random-sleep-on-renew
@docker exec `docker ps -f name=rodan_nginx -q` nginx -s reload
stop:
# This is the same command to stop docker swarm or docker compose
@echo "[-] Stopping all running docker containers and services..."
@docker service rm `docker service ls -q` >>/dev/null 2>&1 || echo "[+] No Services Running"
# @docker stop `docker ps -aq` >>/dev/null 2>&1 || echo "[+] No Containers Running"
@docker stop `docker ps -aq | grep -v $$(docker ps -aq --filter "name=gpu_dont_kill_me")` >>/dev/null 2>&1 || echo "[+] No Containers Running"
@echo "[+] Done."
clean:
# Erase all docker data, this can be dangerous
@echo "[-] Removing all docker containers..."
@docker system prune -fa >>/dev/null 2>&1
@echo "[+] Done."
clean_git:
@echo "[-] Cleaning git..."
@git reset --hard
@git pull
@echo "[+] Done."
clean_swarm:
# Not usually needed, but this will restart the swarm
@echo "[-] Exiting from Docker Swarm and recreating new Swarm Manager..."
@docker stack rm rodan || echo "[-] No stack to remove"
@docker swarm leave --force || echo "[-] Not a swarm manager"
@docker swarm init
@echo "[+] Done."
debug_swarm:
@echo "[+] Creating a live service in the same network."
@docker service create --name statefulservice --network rodan_default --entrypoint="bash -c 'tail -f /dev/null'" --env-file=./scripts/staging.env ddmal/rodan:nightly bash
@docker exec -it `docker ps -f name=statefulservice -q` bash
push:
@echo "[-] Pushing images to Docker Hub..."
@docker compose push
@echo "[+] Done."
pull:
@echo "[-] Pulling docker images from Docker Hub..."
@DOCKER_TAG=$(DOCKER_TAG) docker compose pull
@echo "[+] Done."
$(JOBS_PATH)/neon_wrapper/Neon/package.json:
@cd $(JOBS_PATH); \
git clone --recurse-submodules -b develop https://github.com/DDMAL/neon_wrapper.git
$(JOBS_PATH)/neon_wrapper/static/editor.html: $(JOBS_PATH)/neon_wrapper/Neon/package.json
@cd $(JOBS_PATH)/neon_wrapper; \
yarn install && \
yarn build
$(JOBS_PATH)/pixel_wrapper/package.json:
@cd $(JOBS_PATH); git clone --recurse-submodules -b develop https://github.com/DDMAL/pixel_wrapper.git
remote_jobs: $(JOBS_PATH)/pixel_wrapper/package.json $(JOBS_PATH)/neon_wrapper/static/editor.html
@cd $(RODAN_PATH); $(REPLACE) "s/#py3 //g" ./settings.py
@cd $(RODAN_PATH); $(REPLACE) "s/#gpu //g" ./settings.py
gpu-celery_log:
@docker exec $$(docker ps -f name=rodan_gpu-celery --format "{{.ID}}") tail -f /code/Rodan/rodan-celery-GPU.log
py3-celery_log:
@docker exec $$(docker ps -f name=rodan_py3-celery --format "{{.ID}}") tail -f /code/Rodan/rodan-celery-Python3.log
celery_log:
@docker exec $$(docker ps -f name=rodan_celery --format "{{.ID}}") tail -f /code/Rodan/rodan-celery-celery.log
rodan-main_log:
@docker exec $$(docker ps -f name=rodan_rodan-main --format "{{.ID}}") tail -f /code/Rodan/rodan.log
update_prod_version_tag:
# old_tag=v2.x.x make update_prod_version_name
@$(REPLACE) "s/$(old_tag)/$(PROD_TAG)/g" ./production.yml
@$(REPLACE) "s/$(old_tag)/$(PROD_TAG)/g" ./rodan-main/code/rodan/__init__.py
# Command Groups
reset: stop clean pull run
clean_reset: stop clean build run
upload: clean_reset push
deploy: clean_git pull run_swarm
reset_swarm: stop clean_git clean_swarm clean pull deploy_staging
update_swarm: clean_git update
staging: stop clean pull deploy_staging