This repository has been archived by the owner on Feb 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
156 lines (125 loc) · 4 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
dc=docker-compose
d=docker
dcb=$(dc) -f docker-compose-build.yml
dcp=$(dc) -f docker-compose-production.yml
# the same const value is used at `test_db` django command
TEST_DB=test_stb
.PHONY: migrate create-env build-static watch-static \
build test backup restore \
generate-production-static-data deploy
# ---------------------- Dev section ----------------------
bash:
$(dc) exec app bash
repl:
$(dc) exec app python manage.py shell
migrate:
$(dc) exec app python manage.py migrate
fixtures:
$(dc) exec app bash -c "\
python manage.py loaddata stroyprombeton/fixtures/admin.json \
&& python manage.py loaddata stroyprombeton/fixtures/dump.json \
"
gen-fixtures:
$(dc) exec postgres bash -c "\
psql -Upostgres <<< 'CREATE DATABASE $(TEST_DB);' \
"
$(dc) run --rm -e POSTGRES_DB=$(TEST_DB) app python manage.py test_db
$(dc) exec postgres bash -c "\
psql -Upostgres <<< 'DROP DATABASE $(TEST_DB);' \
"
prices:
$(dc) exec app python manage.py price
create-env:
@bash ./create-env.sh
create-config:
@bash ./create-config.sh
# update internationalization messages
i18n:
$(dc) run --rm app bash -c "\
python manage.py makemessages --ignore 'venv/**' \
&& python manage.py compilemessages -l ru \
"
npm-install:
$(dcb) build --no-cache nodejs
build-static:
$(dc) run --rm nodejs gulp build
watch-static:
$(dc) run --rm nodejs
collectstatic:
$(dc) exec app python manage.py collectstatic --noinput
test: build-static
$(dc) up -d selenium
$(dc) exec app python manage.py test --parallel
$(dc) stop
lint-code:
$(dc) run --rm lint
lint-pdd:
$(dc) run --rm pdd
lint-pdd-verbose:
$(dc) run --rm pdd --verbose
lint:
$(MAKE) lint-code
$(MAKE) lint-pdd
deploy-dev:
$(MAKE) create-env
# uncomment in #167
# $(MAKE) create-config
$(dc) pull
$(dc) up -d app
$(MAKE) build-static
$(MAKE) migrate
# Create admin user with login/pass: admin/asdfjkl;
$(MAKE) fixtures
# Launch "collectstatic" not in static recipe because ManifestStaticStorage writes to db
$(MAKE) collectstatic
# to make fresh collected static visible immediately
$(dc) stop app && $(dc) up -d app
# stage helps to expose given branch different from master.
# `prod` image contains master branch.
# `stage` contains a given one.
prepare-stage-deploy:
# preserve the dev image from repository
$(dcp) rm -fs app-stage
$(MAKE) build-static
$(dcb) build --no-cache python-dev-stage python-stage
# to expose required branch on stage
# just checkout it on a stage server and run this rule.
deploy-stage:
$(MAKE) prepare-stage-deploy
$(dcp) up -d app-stage
$(dcp) exec app-stage python manage.py migrate
$(dcp) exec app-stage python manage.py loaddata stroyprombeton/fixtures/admin.json
$(dcp) exec app-stage python manage.py loaddata stroyprombeton/fixtures/dump.json
$(dcp) exec app-stage python manage.py collectstatic --noinput
$(dcp) stop app-stage && $(dcp) up -d app-stage
# ---------------------- Production deploy section ----------------------
# @todo #142:60m Resurrect backup system.
# Right now it's too dangerous and not used.
backup:
$(dcp) run --rm backup-data sh /usr/bin/entrypoint.sh
restore:
@bash ../etc/backup/backup-restore.sh
generate-production-static-data:
$(dcp) exec app python manage.py price
# drone should do this in working flow.
# But if drone don't do this for some reasons,
# you can run this recipe from local machine.
prepare-deploy:
rm -rf front/build
$(dc) stop app && $(dcp) stop app
$(dc) rm -f app && $(dcp) rm -f app
$(MAKE) build-static
$(dcb) build --no-cache python-dev python-prod
$(dcb) push python-dev python-prod
deploy:
$(dcp) pull
$(dcp) stop
# to flush nginx's inner static caches
$(dcp) rm -f app nginx && $(dcp) up -d app nginx
$(dcp) exec app python manage.py migrate
$(dcp) exec app python manage.py custom_pages
$(MAKE) -j generate-production-static-data
# Launch "collectstatic" not in static recipe because ManifestStaticStorage writes to db
$(dcp) exec app python manage.py collectstatic --noinput
# to make fresh collected static visible immediately
$(dcp) stop && $(dcp) up -d