This repository has been archived by the owner on Aug 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
171 lines (147 loc) · 5.07 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
LOG_LINES = 100
FG = FALSE
UPDATE = FALSE
DATE_PREFIX = `date +'%Y_%m_%d-%Hh'`
DB_BKP_FILE := bkps/$(DATE_PREFIX)dump.json
MEDIA_BKP := bkps/$(DATE_PREFIX)media.tar
DOCKER_UP := docker-compose up
DOCKER_LOGS := docker-compose logs --tail=$(LOG_LINES)
DOCKER_START := docker-compose start
DOCKER_STOP := docker-compose stop
DOCKER_GEOLOCATE := docker-compose exec carceropolis python manage.py geolocate
ifeq ($(FG), TRUE)
DOCKER_UP += -d
endif
ifdef FOLLOW
DOCKER_LOGS += -f
endif
ifdef SERVICES
DOCKER_UP += $(SERVICES)
DOCKER_LOGS += $(SERVICES)
DOCKER_STOP += $(SERVICES)
DOCKER_START += $(SERVICES)
DOCKER_RECREATE := docker-compose rm -s $(SERVICES); docker-compose up -d $(SERVICES)
endif
ifeq ($(UPDATE), TRUE)
DOCKER_GEOLOCATTE += --all
endif
.DEFAULT_GOAL : help
help:
@echo "Welcome to Carcerópolis make file."
@echo "This file is intended to ease your life regarding docker-compose commands."
@echo "Bellow you will find the options you have with this makefile."
@echo "You just need to run 'make <command> <arguments..>'."
@echo " "
@echo " help - Print this help message"
@echo " "
@echo " run [FG=FALSE] [SERVICES=ALL]"
@echo " Run the project in Background mode by default."
@echo " FG: Define as TRUE to run in foreground."
@echo " SERVICES: servies that will be affected by the command. E.g.: SERVICES='service_a_name service_b_name'"
@echo " "
@echo " logs [LOG_LINES=100] [SERVICES=ALL] [FOLLOW=TRUE]"
@echo " See services logs."
@echo " LOG_LINES: The number of log lines for each service"
@echo " SERVICES: servies that will be affected by the command. E.g.: SERVICES='service_a_name service_b_name'"
@echo " FOLLOW: keep tracking the logs. E.g.: FOLLOW=TRUE"
@echo " "
@echo " stop [SERVICES=ALL]"
@echo " Stop one or more services."
@echo " SERVICES: servies that will be affected by the command. E.g.: SERVICES='service_a_name service_b_name'"
@echo " "
@echo " start [SERVICES=ALL]"
@echo " Start one or more stopped services."
@echo " SERVICES: servies that will be affected by the command. E.g.: SERVICES='service_a_name service_b_name'"
@echo " "
@echo " recreate SERVICES='<service_a> <service_b> ...'"
@echo " Remove and recreate the given services/containers, but not their volumes."
@echo " "
@echo " clean"
@echo " stop and remove all service containers and images."
@echo " "
@echo " clean-containers"
@echo " remove all containers, keeping images and volumes"
@echo " "
@echo " clean-volumes"
@echo " remove all volumes. It also remove containers"
@echo " "
@echo " clean-repo"
@echo " Clean the current repo by undoing all uncommited changes and remove untracked git files"
@echo " "
@echo " makemigrations"
@echo " "
@echo " migrate"
@echo " "
@echo " collectstatic"
@echo " "
@echo " update-carceropolis"
@echo " This command will execute 'makemigrations', 'migrate' and 'collectstatic' commands"
@echo " "
@echo " dump-database"
@echo " Dump the database to the 'bkps/' directory preppended by the current date-time"
@echo " "
@echo " geolocate [UPDATE=FALSE]"
@echo " Execute the gelolocation script for the Unidades Prisionais entities."
@echo " UPDATE: By default only Unidades without geolocation are updated, if you want to re-geolocate all Unidades, pass UPDATE=TRUE"
@echo " "
@echo " backup"
@echo " Backup both the database and the media files to 'bkps/' directory"
.PHONY: help
run:
@$(DOCKER_UP)
.PHONY: run
logs:
$(DOCKER_LOGS)
.PHONY: logs
stop:
@$(DOCKER_STOP)
.PHONY: stop
start:
@$(DOCKER_START)
.PHONY: start
recreate:
ifndef DOCKER_RECREATE
@echo "You need to pass the services you want to recreate with SERVICE='service_a_name service_b_name'"
@exit 1
else
@$(DOCKER_RECREATE)
endif
.PHONY: recreate
clean:
docker-compose down --rmi all
.PHONY: clean
clean-containers:
docker-compose down
.PHONY: clean-containers
clean-volumes:
docker-compose down --rmi -v
.PHONY: clean-containers
clean-repo:
git reset --hard HEAD
git clean -di -e '.env'
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '__pycache__' -exec rm -fr {} +
.PHONY: clean-pyc
makemigrations:
docker-compose exec carceropolis python manage.py makemigrations
.PHONY: makemigrations
migrate:
docker-compose exec carceropolis python manage.py migrate
.PHONY: migrate
collectstatic:
docker-compose exec carceropolis python manage.py collectstatic --no-input
.PHONY: collectstatic
update-carceropolis: makemigrations migrate collecetstatic
.PHONY: update-carceropolis
dump-database:
docker-compose exec carceropolis sh -c "python manage.py dumpdata --natural-foreign -e sessions -e admin -e contenttypes -e auth.Permission > /project/$(DB_BKP_FILE)"
bzip2 -9 -f $(DB_BKP_FILE)
.PHONY: dump-database
geolocate:
$(DOCKER_GEOLOCATE)
.PHONY: geolocate
backup: dump-database
tar -cf $(MEDIA_BKP) carceropolis/static/media
.PHONY: backup