-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
118 lines (88 loc) · 4.38 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
.DEFAULT_GOAL := help
ENVIRO = test
export SHELL=/bin/bash
CONTAINER_BIN = podman
PROJECT = organology
PROJECT_VERSION = latest
PROJECT_NETWORK = $(PROJECT)-network
DB = $(PROJECT)
TAG = $(PROJECT)
# Database Configurations
DBTAG = $(TAG)-database
DBVERSION = 14
DBIMAGE = docker.io/library/postgres:$(DBVERSION)
export DBHOST = localhost
export DBUSER = postgres
export DBPASSWORD = postgres
export PGPASSWORD = $(DBPASSWORD)
export DBPORT = 5432
# Portal Configurations
PORTALVERSION = 8.4.0
PORTALTAG = $(TAG)-portal
PORTALIMAGE = docker.io/library/node:$(PORTALVERSION)
PORTALIMAGE = docker.io/library/python:latest
pull-db:
@${CONTAINER_BIN} pull $(DBIMAGE)
database-build: pull-db ## build database image
@${CONTAINER_BIN} tag $(DBIMAGE) $(DBTAG)
database-up: | database-build ## bring database engine up
@cd ./docker && \
DOCKER_BUILDKIT=1 ${CONTAINER_BIN} compose up -d $(PROJECT)-database
database-down: ## bring database engine down
@cd ./docker && \
DOCKER_BUILDKIT=1 ${CONTAINER_BIN} compose down
database-create: database-up ## create project's databaseq
@sleep 10
@psql -h $(DBHOST) -U $(DBUSER) -p $(DBPORT) -tc "SELECT 1 FROM pg_database WHERE datname = '$(DB)'" \
| grep -q 1 || psql -h $(DBHOST) -U $(DBUSER) -p $(DBPORT) -c "CREATE DATABASE $(DB);"
database-drop: database-up ## delete project's database (NON-RECOVERABLE)
@sleep 10
@psql -h $(DBHOST) -U $(DBUSER) -p $(DBPORT) -c "DROP DATABASE IF EXISTS $(DB) WITH (FORCE);"
database-configure: | database-drop database-create ## configure project's database
@psql -h $(DBHOST) -U $(DBUSER) -p $(DBPORT) -d $(DB) < ./db/create_db.sql
database-generate-ipn: ## generate notes and international pitch notation database records
@cd ./utils && ./generate_notes_ipn.sh
database-insert-music-records: | database-configure database-generate-ipn ## insert music schema records into project's database
@psql -h $(DBHOST) -U $(DBUSER) -p $(DBPORT) -d $(DB) < ./db/insert_music.octaves.sql && \
psql -h $(DBHOST) -U $(DBUSER) -p $(DBPORT) -d $(DB) < ./db/insert_music.notes.sql && \
psql -h $(DBHOST) -U $(DBUSER) -p $(DBPORT) -d $(DB) < ./db/insert_music.international_pitch_notations.sql
database-insert-records: database-insert-music-records ## insert non-music records into project's database
@psql -h $(DBHOST) -U $(DBUSER) -p $(DBPORT) -d $(DB) < ./db/insert_records.sql
generate-strings: ## generate SQL insert statements from csv
./utils/read_strings.pl < ./sources/daadario/classical_guitar.csv > ./db/insert_strings.sql
database-insert-strings: database-insert-records ## insert string records into project's database
@psql -h $(DBHOST) -U $(DBUSER) -p $(DBPORT) -d $(DB) < ./db/insert_strings.sql
database-test: database-insert-strings ## test inserted database records
@psql -h $(DBHOST) -U $(DBUSER) -p $(DBPORT) -d $(DB) < ./tests/db/tests.sql > ./tests/db/results/run.txt && \
diff ./tests/db/results/run.txt ./tests/db/results/expected/run.txt
portal-pull:
@${CONTAINER_BIN} pull $(PORTALIMAGE) && \
${CONTAINER_BIN} tag $(PORTALIMAGE) $(PORTALTAG)
portal-build: portal-pull ## build portal image
@cd ./www/flask && \
${CONTAINER_BIN} tag $(PORTALIMAGE) $(PORTALTAG) && \
${CONTAINER_BIN} build -t $(PORTALTAG) .
portal-up: | portal-down database-down portal-build database-test ## bring portal up
@cd ./docker && \
DOCKER_BUILDKIT=1 ${CONTAINER_BIN} compose up -d
portal-down: ## bring portal down
@cd ./docker && \
DOCKER_BUILDKIT=1 ${CONTAINER_BIN} compose down
podman-up: podman-down ## start podman
podman machine init
podman machine start
podman-down: ## stop podman
podman machine stop
clean:
${CONTAINER_BIN} rm -f $(DBTAG) || true && \
yes yes | ${CONTAINER_BIN} system prune -a || true && \
${CONTAINER_BIN} pod rm -f pod_docker || true
.PHONY: help
help: ## That's me!
@printf "\033[37m%-30s\033[0m %s\n" "#----------------------------------------------------------------------------------"
@printf "\033[37m%-30s\033[0m %s\n" "# Makefile targets |"
@printf "\033[37m%-30s\033[0m %s\n" "#----------------------------------------------------------------------------------"
@printf "\033[37m%-30s\033[0m %s\n" "#-target-----------------------description-----------------------------------------"
@grep -E '^[a-zA-Z0-9].+:.*?## .*$$' Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
print-%:
@echo $* = $($*)