-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
executable file
·256 lines (192 loc) · 5.84 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
SHELL := /bin/bash
ENV ?= prod
DC := docker-compose -f docker-compose.yml -f docker-compose.${ENV}.yml --project-name smartroadsense
DC_RUN := ${DC} run --rm
CURRDIR=$(PWD)
.PHONY: confirmation
confirmation:
@echo -n 'Are you sure? [y|N] ' && read ans && [ $$ans == y ]
.PHONY: test
test:
${DC_RUN} tiles eslint ./
@echo 'All tests passed!'
.PHONY: fmt
fmt:
${DC_RUN} tiles eslint --fix ./
data:
mkdir data
test/payload.json:
gzip -kd test/payload.json.gz
.PHONY: create_db_volumes drop_db_volumes
create_db_volumes:
docker volume create postgis_db_data
@echo 'SmartRoadSense DATABASE volumes created'
drop_db_volumes: confirmation
docker volume rm postgis_db_data
@echo 'SmartRoadSense DATABASE volumes dropped'
init_db:
${DC} up -d db
@echo 'Waiting while db is starting...'
sleep 5
${DC_RUN} raw-setup-db-cli ./db-schema/init-db.sh
.PHONY: create_volumes drop_volumes
create_volumes:
docker volume create srs_web_data
docker volume create srs_open_data
docker volume create srs_ui_repo_data
@echo 'SmartRoadSense external volumes created'
drop_volumes: confirmation
docker volume rm srs_web_data
docker volume rm srs_open_data
docker volume rm srs_ui_repo_data
@echo 'SmartRoadSense external volumes dropped'
.PHONY: config
config:
@echo
@echo 'Generating SRS configuration'
docker run -it --rm --name srs-config-script -v ${CURRDIR}:/config dlpswr/srs-config-helper
@echo
.PHONY: up
up: data build
${DC} up -d
${DC} ps
@echo
@echo 'Now open http://127.0.0.1:8080 with your web browser'
@echo 'See `raw` database web UI at http://127.0.0.1:9000/phppgadmin/'
@echo 'See `agg` database web UI at http://127.0.0.1:9001/phppgadmin/'
@echo
down:
${DC} down --rmi all -v
@echo 'All images and volumes removed'
@echo
.PHONY: ps
ps:
${DC} ps
.PHONY: enable_jobs enable_6h_jobs enable_weekly_jobs
enable_jobs: enable_6h_jobs enable_weekly_jobs
enable_6h_jobs:
rsync $${PWD}/jobs/6h.service /lib/systemd/system/
rsync $${PWD}/jobs/6h.timer /lib/systemd/system/
systemctl daemon-reload
systemctl start 6h.timer
systemctl enable 6h.timer
systemctl status 6h.timer
enable_weekly_jobs:
rsync $${PWD}/jobs/weekly.service /lib/systemd/system/
rsync $${PWD}/jobs/weekly.timer /lib/systemd/system/
systemctl daemon-reload
systemctl start weekly.timer
systemctl enable weekly.timer
systemctl status weekly.timer
.PHONY: fetch_example fetch_italy
fetch_example: data clean_pbf
wget -O data/map.osm https://api.openstreetmap.org/api/0.6/map?bbox=12.898,43.9115,12.921,43.928
fetch_eu_%: data clean_pbf
wget http://download.geofabrik.de/europe/$*-latest.osm.pbf
wget http://download.geofabrik.de/europe/$*-latest.osm.pbf.md5
md5sum -c $*-latest.osm.pbf.md5
rm $*-latest.osm.pbf.md5
mv $*-latest.osm.pbf data/map.osm.pbf
fetch_region_%: data clean_pbf
wget http://download.geofabrik.de/$*-latest.osm.pbf
wget http://download.geofabrik.de/$*-latest.osm.pbf.md5
md5sum -c $*-latest.osm.pbf.md5
rm $*-latest.osm.pbf.md5
mv $*-latest.osm.pbf data/map.osm.pbf
fetch_italy: fetch_eu_italy
.PHONY: import_example import_italy import import_raw import_agg import_osm
import: import_raw import_agg
import_example: fetch_example import_osm
import_italy: fetch_italy import_osm
import_raw:
${DC_RUN} raw-cli psql -f /code/data.sql
import_agg:
${DC_RUN} agg-cli psql -f /code/data.sql
import_osm: fetch_eu_italy
${DC_RUN} raw-cli ./import_osm.sh
import_osm_%: fetch_eu_%
${DC_RUN} raw-cli ./import_osm.sh
append_osm_%: fetch_eu_%
${DC_RUN} raw-cli ./append_osm.sh
@echo '* correctly imported'
.PHONY: export_osm
export_osm:
${DC_RUN} raw-cli pg_dump -a -t 'planet_osm*' -f /code/osm.sql
.PHONY: export export_raw export_agg export_single_data_as_JSON data_extraction
export: export_raw export_agg
export_raw:
${DC_RUN} raw-cli pg_dump -a -T 'planet_osm*' -f /code/data.sql
export_agg:
${DC_RUN} agg-cli pg_dump -a -f /data/data.sql
export_single_data_as_JSON:
${DC_RUN} raw-cli psql -c 'select st_asgeojson(st_collect(position)) from single_data;' -o /code/single_data.json
data_extraction:
${DC_RUN} export bash
.PHONY: rs
rs:
${DC} restart
.PHONY: stop
stop: clean_ui
${DC} stop
.PHONY: rm rmc
rm rmc: stop
${DC} rm -f
.PHONY: rmi
rmi: rmc
docker rmi $$(docker images | grep 'smartroadsense_' | awk '{print $$1}')
.PHONY: rmv
rmv: stop
${DC} rm -fv
docker volume rm $$(docker volume ls | grep 'smartroadsense_' | awk '{print $$2}')
sh_%:
${DC_RUN} $* /bin/bash
logs_%:
${DC} logs $*
.PHONY: raw-cli
raw-cli:
${DC_RUN} raw-cli pgcli
.PHONY: agg-cli
agg-cli:
${DC_RUN} agg-cli pgcli
.PHONY: update_meta
update_meta: jobs/meta-updater/meta-updater
${DC_RUN} meta-updater /code/meta-updater
.PHONY: map-reduce
map-reduce:
${DC_RUN} map-reduce php semi_parallel_updater.php
.PHONY: history
history:
${DC_RUN} map-reduce php /code/history_stepper.php
.PHONY: open_data
open_data:
${DC_RUN} agg-cli ./update_open_data.sh
.PHONY: website
website:
${DC_RUN} ui
.PHONY: reset_projs
reset_projs:
${DC_RUN} map-reduce php /code/reset_projections.php
load_test_sh: test/boom test/payload.json
docker run --net=srs_default -v /var/run/docker.sock:/var/run/docker.sock \
-v $$PWD/test:/code -w /code -it michelesr/docker-cli bash
.PHONY: build build_go
build: build_go
build_go: jobs/meta-updater/meta-updater test/boom
jobs/meta-updater/meta-updater: jobs/meta-updater/meta-updater.go
docker run --rm -v $${PWD}/jobs/meta-updater:/code dlpswr/gopg:latest env CGO_ENABLED=0 go build /code/meta-updater.go
test/boom:
docker run --rm -it -v $${PWD}/test:/code dlpswr/gopg:latest env CGO_ENABLED=0 \
bash -c 'go get github.com/michelesr/boom && cp `which boom` .'
.PHONY: clean clean_go clean_raw clean_ui clean_data
clean: clean_go clean_raw clean_ui clean_data clean_pbf
clean_go:
rm -f jobs/meta-updater/meta-updater
rm -f test/boom
clean_raw:
rm -f raw/*.pbf
rm -f raw/*.md5
clean_data:
rm -rf data/
clean_pbf:
rm -rf *.pbf*
rm -rf data/map.osm.pbf