-
Notifications
You must be signed in to change notification settings - Fork 88
/
Makefile
107 lines (90 loc) · 2.81 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
# make sure RS_ENV is set and not 'dev'
env_check:
ifndef RS_ENV
@echo error: RS_ENV value required 1>&2
@exit 1
endif
ifeq ($(RS_ENV),dev)
@echo error: RS_ENV can not be set to 'dev' 1>&2
@exit 1
endif
# remove source from docker image context tree
clean:
rm -rf docker/expungeservice/backend \
docker/expungeservice/frontend
# synchronize source trees into docker context tree
rsync:
rsync -rlptoD --delete --omit-dir-times --exclude logs --exclude flask_session ../backend docker/expungeservice
rsync -rlptoD --delete --omit-dir-times ../frontend/build docker/expungeservice/frontend
# echo out version.json
version:
echo "{\"recordexpungPDX\":\"$$(git rev-parse HEAD)\",\"branch\":\"$$(git rev-parse --abbrev-ref HEAD)\"}" \
> docker/expungeservice/frontend/build/version.json
# build an expungeservice image with the given RS_ENV tag ('staging', 'prod', etc)
image: rsync env_check
cd docker/expungeservice; \
docker build . -t recordsponge/expungeservice:$(RS_ENV)
# push expungeservice image with the given RS_ENV tag to hub.docker.com
push: env_check
docker push recordsponge/expungeservice:$(RS_ENV)
# --- deploys
# configure port & syslog facility
ifeq ($(RS_ENV),staging)
PORT := 3032
FACILITY := local1
else ifeq ($(RS_ENV),prod)
PORT := 3031
FACILITY := local0
endif
# configure DEPLOY_TAG
ifndef DEPLOY_TAG
DEPLOY_TAG := $(RS_ENV)
endif
# validate PORT setting
port_check:
ifndef PORT
@echo error: PORT value required - default for '$(RS_ENV)' not found 1>&2
@exit 1
endif
# ssh to digitalocean host and perform deploy.
#
# * name of container based on RS_ENV e.g. 'staging' or 'prod'
# * PORT determined by RS_ENV, override on command line
# * DEPLOY_TAG defaults to RS_ENV, override on command line
#
# expects:
# * 'Host recordsponge' section in _local_ ~/.ssh/config (see /src/ops/README.md#SSH_Config)
# * '*.env' with TIER in _remote_ /etc/recordsponge/
#
ssh_deploy: env_check port_check
@ssh recordsponge -C \
'docker pull recordsponge/expungeservice:$(DEPLOY_TAG); \
docker stop $(RS_ENV); \
docker run --rm -d \
--name $(RS_ENV) \
--env-file /etc/recordsponge/$(RS_ENV).env \
-p $(PORT):5000 \
--log-driver syslog \
--log-opt syslog-facility=$(FACILITY) \
--log-opt tag=$(RS_ENV) \
recordsponge/expungeservice:$(DEPLOY_TAG)'
# --- staging
# build staging image
staging_image: clean
@cd ../..; make frontend_build
@make rsync version image RS_ENV=staging
staging_push:
@make push RS_ENV=staging
# build and deploy staging
staging: staging_image staging_push
@make ssh_deploy RS_ENV=staging
# --- production
# build prod image
prod_image: clean
@cd ../..; make frontend_build
@make rsync version image RS_ENV=prod
prod_push:
@make push RS_ENV=prod
# build and deploy prod
prod: prod_image prod_push
@make ssh_deploy RS_ENV=prod