generated from compsoc-edinburgh/deployment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
51 lines (39 loc) · 1.73 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
include .env
# .SILENT:
tail:
ssh ${REMOTE} 'docker logs -f --tail 0 service-${SUBDOMAIN}'
logs:
ssh ${REMOTE} 'docker logs service-${SUBDOMAIN}'
sync-secrets:
rsync -r ./secrets/ ${REMOTE}:/secrets/service-${SUBDOMAIN}
generate-port:
ssh ${REMOTE} 'ruby -e "require \"socket\"; puts Addrinfo.tcp(\"\", 0).bind {|s| s.local_address.ip_port }"' | tr -d '[:space:]' > .open-port
PORT = $(shell cat .open-port)
# Only run once, at service initialisation. All other deployment will be through github actions
initialise: generate-port
mkdir -p secrets
ssh ${REMOTE} "mkdir -p /secrets/service-${SUBDOMAIN}"
# _Definitely_ prone to race conditions, but this won't be called anywhere near frequently enough for that to matter
ssh ${REMOTE} 'docker run -d --name service-${SUBDOMAIN} \
--network traefik-net \
--label "traefik.enable=true" \
-p ${PORT}:${PORT} \
-e PORT=${PORT} \
-v /secrets/service-${SUBDOMAIN}:/usr/src/app/secrets \
-e "DATABASE_URL=postgresql://postgres:mysecretpassword@postgres:5432/service-db-${SUBDOMAIN}" \
-e "FILE_UPLOAD=https://service-simple-storage:3456/${SUBDOMAIN}" \
--label "com.centurylinklabs.watchtower.enable=true" \
--label "traefik.http.routers.service-${SUBDOMAIN}.rule=Host(\`${SUBDOMAIN}.dev.comp-soc.com\`)" \
--label "traefik.http.routers.service-${SUBDOMAIN}.middlewares=traefik-forward-auth" \
ghcr.io/compsoc-edinburgh/service-${SUBDOMAIN}'
rm .open-port
restart:
ssh ${REMOTE} 'docker restart service-${SUBDOMAIN}'
stop:
ssh ${REMOTE} 'docker stop service-${SUBDOMAIN}'
shell:
ssh -t ${REMOTE} 'docker exec -it service-${SUBDOMAIN} sh'
teardown:
ssh ${REMOTE} 'docker stop service-${SUBDOMAIN}'
ssh ${REMOTE} 'docker rm service-${SUBDOMAIN}'