forked from codeforpdx/recordexpungPDX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
130 lines (105 loc) · 3.62 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
.PHONY: clean
REQUIREMENTS_TXT := src/backend/requirements.txt
OSFLAG :=
ifeq ($(OS),Windows_NT)
OSFLAG = WIN32
endif
clean:
ifeq ($(OSFLAG), WIN32)
del /s /q /f .\src\backend\*.egg-info -and \
del /s /q /f .\*pyc -and \
del /s /q /f .\*~
else
rm -rf src/backend/*.egg-info &
find . -type f -name \*~ | xargs rm &
find . -type f -name \*pyc | xargs rm
endif
BACKEND_SERVICE := expungeservice
FRONTEND_SERVICE := node
DB_SERVICE := postgres
# currently, only used for PGDATABASE var in 'dropdb' target
include config/postgres/client.env
# one step target for a new dev env
new: up
@echo waiting for database...
@sleep 10
@make initdb
# pulls the necessary images for the local dev services
pull:
docker-compose pull
# pushes the dev image for the local expungeservice service
push:
docker-compose push $(BACKEND_SERVICE)
# pulls, then fires up local dev services
up: pull
docker-compose up -d
# brings down local dev services
down:
docker-compose down
# runs database initialization scripts - run at first creation or if database
# data volume is removed
initdb:
docker-compose exec --user=postgres $(DB_SERVICE) /var/lib/postgresql/config/initdb/init-db.dev.sh
# drop database
dropdb:
docker-compose exec --user=postgres $(DB_SERVICE) sh -l -c "dropdb $(PGDATABASE)"
# run all tests
test: frontend_test_no_watch backend_test
# wipeout containers and volumes
clobber:
docker-compose down -v
# build expungeservice:dev image
backend_build:
docker-compose build $(BACKEND_SERVICE)
# tail logs from backend
backend_logs:
docker-compose logs -f $(BACKEND_SERVICE)
# recreate the backend container; n.b. does not recreate image
backend_reload:
docker-compose stop $(BACKEND_SERVICE)
docker rm recordexpungpdx_$(BACKEND_SERVICE)_1
docker-compose up -d $(BACKEND_SERVICE)
# run backend tests
backend_test:
docker-compose exec $(BACKEND_SERVICE) pipenv run mypy
docker-compose exec $(BACKEND_SERVICE) pipenv run pytest
# run react-scripts build
frontend_build: frontend_clean
docker run --rm \
-v `pwd`/src/frontend:/src/frontend \
-v recordexpungpdx_node_modules:/src/frontend/node_modules \
node:alpine /bin/sh -c 'cd /src/frontend && npm run build'
# delete react built files
frontend_clean:
rm -rf src/frontend/build/*
# stop and remove the frontend container
frontend_down:
docker-compose stop $(FRONTEND_SERVICE)
docker rm recordexpungpdx_$(FRONTEND_SERVICE)_1
# tail logs from frontend
frontend_logs:
docker-compose logs -f $(FRONTEND_SERVICE)
# restart frontend
frontend_restart:
docker-compose restart $(FRONTEND_SERVICE)
# run frontend tests, watching enabled (default)
frontend_test:
docker-compose exec $(FRONTEND_SERVICE) sh -c 'cd /src/frontend && npm test'
# run frontend tests without watching enabled
frontend_test_no_watch:
docker-compose exec $(FRONTEND_SERVICE) sh -c 'cd /src/frontend && CI=true npm test'
# pull a database backup from production
#
# expects:
# * 'Host recordsponge' section in _local_ ~/.ssh/config (see /src/ops/README.md#SSH_Config)
# * 'prod.env' with database credentials and TIER in _remote_ /etc/recordsponge/
#
prod_db_sync:
@ssh recordsponge -C \
'docker pull postgres:10-alpine; \
docker run --rm --user=`id -u` --env-file /etc/recordsponge/prod.env --name backup -v /var/tmp:/var/tmp postgres:10-alpine pg_dump -Fc -f /var/tmp/backup-prod.psql'
@scp recordsponge:/var/tmp/backup-prod.psql config/postgres/backup-prod.psql
@make dropdb
@docker-compose exec --user=postgres $(DB_SERVICE) sh -l -c "createdb $(PGDATABASE) && pg_restore -O -d $(PGDATABASE) /var/lib/postgresql/config/backup-prod.psql"
@rm config/postgres/backup-prod.psql
@ssh recordsponge -C 'rm /var/tmp/backup-prod.psql'