-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
69 lines (51 loc) · 1.7 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
.ONESHELL:
.SILENT: test build run-test job run-job run-service call-service clean
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SOURCES=$(wildcard $(ROOT_DIR)/input/*.csv)
OBJECTS=$(subst input,output,$(subst .csv,.out,$(SOURCES)))
UID := $(shell id -u)
GID := $(shell id -g)
DOCKER_COMPOSE := UID=${UID} GID=${GID} docker-compose
build:
[ -f .env ] || cp .env.example .env
$(DOCKER_COMPOSE) build
$(DOCKER_COMPOSE) run -u root --entrypoint="chown -R ${UID}:${GID} /var/lib/mysql" db
$(DOCKER_COMPOSE) up -d db
cd job
[ -f .env ] || ln -s ../.env .env
cd ../service
[ -f .env ] || cp ../.env .env
test:
$(DOCKER_COMPOSE) run --entrypoint="make ${MAKEFLAGS} TARGET=${TARGET} run-test" job
run-test:
ifneq ("$(TARGET)","")
cd job
python -m unittest ${TARGET}
else
python -m unittest discover -s ./job/tests/ -p *_test.py -t ./job/
endif
job: $(OBJECTS)
@$(MAKE) $(OBJECTS)
run-job:
$(DOCKER_COMPOSE) run --entrypoint="make ${MAKEFLAGS} job" job
run-service:
$(DOCKER_COMPOSE) up -d server
restart-service:
$(DOCKER_COMPOSE) restart service server
call-service:
echo "Requesting daily driven km for vehicle bern-2, between the dates 2023-03-29 and 2023-03-31."
echo ""
curl 'http://localhost:8000/api/driving-distances?vehicle_id=bern-2&start_date=2023-03-29&end_date=2023-03-31'
echo ""
echo ""
echo "Try also on browser with: http://localhost:8000/api/driving-distances?vehicle_id=bern-2&start_date=2023-03-29&end_date=2023-03-31"
clean:
rm -rf output/*
touch output/.keep
$(DOCKER_COMPOSE) down -v
%.out.csv : ../input/%.csv
cd $(ROOT_DIR)/job
python main.py -o "$@" -f "$<"
%.out : ../input/%.csv
cd $(ROOT_DIR)/job
python main.py -o "$@" -f "$<" --loader=mysql