-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
172 lines (149 loc) · 4.6 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
172
NAME = thenets/easywaze
TAG = latest
SHELL = /bin/bash
APP_NAME=easywaze
USER_NAME=kratos
USER_HOME=/home/$(USER_NAME)
APP=/app
SOURCE_PATH=src/
VOLUME_PATH=-v $(PWD)/$(SOURCE_PATH)/:/app/ \
-v $(APP_NAME)-venv:/home/kratos/.pyenv/versions
ENVS=-e EW_CITY_NAME=Montivideo \
-e EW_COUNTRY_NAME=Uruguai \
-e EW_ENDPOINT='https://world-georss.waze.com/rtserver/web/TGeoRSS?acotu=true&format=JSON&irmie=true&types=traffic%2Calerts%2Cirregularities&tk=ccp_partner&ccp_partner_name=Fundacao+Getulio+Vargas&polygon=-56.324,-34.601;-56.45,-34.881;-55.934,-35.003;-55.39,-34.854;-56.324,-34.601'
# Prepare the environment
# ==============================
prepare:
# Build Docker image
make build
# Create volume for venv and fix permissions
docker volume create $(APP_NAME)-venv || true
docker run --rm -it \
$(VOLUME_PATH) \
--entrypoint="" \
$(NAME):$(TAG) chown 1000.1000 /home/kratos/.pyenv/versions
# Create database volume and dependencies
make services
@echo ""
@echo -e "\e[32mAll services working!\e[0m"
@echo "$$SERVICES_INSTRUCTIONS"
# Docker builds
# ==============================
build: basics
docker build -t $(NAME):$(TAG) --rm docker/base
docker build -t $(NAME):master --rm docker/master
docker build -t $(NAME):worker --rm docker/worker
# Interactive commands
# ==============================
shell: basics
@docker run --rm -it \
$(VOLUME_PATH) \
$(ENVS) \
--entrypoint="" \
--user=$(USER_NAME) \
--network $(APP_NAME) \
--name $(APP_NAME)-shell-$$RANDOM \
--workdir /app \
$(NAME):$(TAG) $(SHELL)
shell-root: basics
@echo -e "\e[91mMaking you a god...\e[0m"
@docker run --rm -it \
$(VOLUME_PATH) \
$(ENVS) \
--entrypoint="" \
--name $(APP_NAME)-shellroot-$$RANDOM \
--workdir /app \
--network $(APP_NAME) \
$(NAME):$(TAG) $(SHELL)
# Start master and worker mode
# ==============================
start-master: basics
@docker run --rm -it \
-v /opt/easywaze/config.yaml:/app/config.yaml \
-p 6000:6000 \
--network $(APP_NAME) \
$(NAME):$(TAG)
# Dependencies
# ==============================
define SERVICES_INSTRUCTIONS
- MySQL
| name : $(APP_NAME)-mysql
| user : root
| pass : root
| db : $(APP_NAME)
| port : 23306
- phpMyAdmin
| name : $(APP_NAME)-phpmyadmin
| addr : http://127.0.0.1:8000/
- PostGIS
| name : $(APP_NAME)-postgis
| user : root
| pass : root
| db : $(APP_NAME)
| port : 25432
endef
export SERVICES_INSTRUCTIONS
services:
@# Create network
@echo -e "\e[32mCreating network...\e[0m"
@docker network create $(APP_NAME) >/dev/null 2>/dev/null || true
@# Added MySQL and phpMyAdmin
@echo -e "\e[32mPreparing MySQL database and phpMyAdmin...\e[0m"
@docker rm -f $(APP_NAME)-mysql $(APP_NAME)-phpmyadmin >/dev/null 2>/dev/null || true
@docker volume create $(APP_NAME)-mysql >/dev/null 2>/dev/null || true
@echo -n $(APP_NAME)-mysql:
@docker run -d --name $(APP_NAME)-mysql --network=$(APP_NAME) \
-e MYSQL_ROOT_PASSWORD="root" \
-e MYSQL_DATABASE=$(APP_NAME) \
-v $(APP_NAME)-mysql:/var/lib/mysql \
-p 23306:3306 mysql:5.7.22
@echo -n $(APP_NAME)-phpmyadmin:
@docker run -d --name $(APP_NAME)-phpmyadmin -p 8000:80 \
--network=$(APP_NAME) \
-e PMA_HOST=$(APP_NAME)-mysql \
phpmyadmin/phpmyadmin:edge
@# Postgis
@echo -e "\e[32mPreparing PostGIS database...\e[0m"
@docker rm -f $(APP_NAME)-postgis >/dev/null 2>/dev/null || true
@docker volume create $(APP_NAME)-postgis >/dev/null 2>/dev/null || true
@echo -n $(APP_NAME)-postgis:
@docker run --name $(APP_NAME)-postgis --network=$(APP_NAME) \
-e POSTGRES_USER=root \
-e POSTGRES_PASS=root \
-e POSTGRES_DBNAME=$(APP_NAME) \
-e ALLOW_IP_RANGE=0.0.0.0/0 \
-v $(APP_NAME)-postgis:/var/lib/postgresql \
-p 25432:5432 -d -t kartoza/postgis
@# Redis
@echo -e "\e[32mPreparing Redis database...\e[0m"
@docker rm -f $(APP_NAME)-redis >/dev/null 2>/dev/null || true
@echo -n $(APP_NAME)-redis:
@docker run --name $(APP_NAME)-redis --network=$(APP_NAME) \
-d -t redis:alpine
# Tools
# ==============================
basics:
@mkdir -p ./$(SOURCE_PATH)
repair:
@echo -e "\e[32mReparing...\e[0m"
docker rm -f db $(docker container ls -af name=$(APP_NAME)) 2>/dev/null || true
make basics
make db
# Custom commands
# ==============================
cmd-capture:
@docker run --rm -it \
$(VOLUME_PATH) \
--entrypoint="" \
--user=$(USER_NAME) \
--network $(APP_NAME) \
--name $(APP_NAME)-shell-$$RANDOM \
$(NAME):$(TAG) bin/capture.sh uygviuyvbiuvbiugbiugbviuygviv
cmd-export:
@docker run --rm -it \
$(VOLUME_PATH) \
--entrypoint="" \
--user=$(USER_NAME) \
--network $(APP_NAME) \
--name $(APP_NAME)-shell-$$RANDOM \
$(NAME):$(TAG) bin/export.sh