-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
88 lines (72 loc) · 2.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
# -*- coding: utf-8 -*-
#
# Copyright 2021 Huseyin Alecakir <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
SHELL = /bin/bash
#######################################################
# load all config variables as env variables
include config/.env.dev
export
# check whether the correct python version is available
ifeq (, $(shell which python3 ))
$(error "python3 not found in $(PATH)")
endif
VENV := "venv/bin/activate"
PRICE_PAID_FILE := "price_paid.csv"
venv/bin/activate: requirements.txt
@echo -e "\e[0;32mINFO Creating virtual environment and installing requirements...\e[0m"
test -d venv || python3 -m venv venv
. $(VENV) && pip3 install -Ur requirements.txt
@touch venv/bin/activate
data:
@echo -e "\e[0;32mINFO Creating data folder...\e[0m"
@mkdir data
data/price_paid.csv: data
@echo -e "\e[0;32mINFO Fetching price paid data...\e[0m"
@wget -O "./data/$(PRICE_PAID_FILE)" $(PP_DATA)
@touch data/price_paid.csv
.PHONY: up
up:
@echo -e "\e[0;32mINFO Starting containers...\e[0m"
@cd api && docker-compose down
@cd api && docker-compose up -d --build
@docker ps
.PHONY: down
down:
@cd api && docker-compose down
.PHONY: create-db
create-db: up
@echo -e "\e[0;32mINFO Making database migrations...\e[0m"
@cd api && docker-compose exec web python manage.py makemigrations
@cd api && docker-compose exec web python manage.py migrate
.PHONY: populate-data
populate-data: data/price_paid.csv venv/bin/activate create-db
@echo -e "\e[0;32mINFO Populating database...\e[0m"
@. $(VENV) && python3 scripts/populate_db.py --price-paid-data="./data/$(PRICE_PAID_FILE)" \
--db-table-name=$(DB_TABLE_NAME) \
--db-name=$(POSTGRES_DB) \
--db-user=$(POSTGRES_USER) \
--db-pass=$(POSTGRES_PASSWORD) \
--db-host=$(POSTGRES_HOST)
.PHONY: test
test: up
@echo -e "\e[0;32mINFO Testing REST endpoints...\e[0m"
@cd api && docker-compose exec web python manage.py test
.PHONY: all
all: populate-data
.PHONY: clean
clean:
@rm -rf data venv
@cd api && docker-compose down
@docker volume rm api_postgres_data || true