-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
157 lines (117 loc) · 4.83 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
#####################################################
# Make variables #
#####################################################
# The default environment file
ENVIRONMENT_FILE=$(shell pwd)/.env
# Available docker containers
CONTAINERS=app mariadb rabbitmq postgres
# Default environment variables
DB_ROOT_PASSWORD ?= secret
DB_DATABASE ?= go_template
#####################################################
# RUNTIME TARGETS #
#####################################################
default: run
# Start the containers
run: prerequisite build
# Start individual container
start: prerequisite valid-container
- docker-compose -f docker-compose.yml up --build $(filter-out $@,$(MAKECMDGOALS))
# Start individual container in the background
silent-start: prerequisite valid-container
- docker-compose -f docker-compose.yml up -d --build $(filter-out $@,$(MAKECMDGOALS))
# Quick start the containers, no preparation will be done
quick-start: prerequisite build-containers
# Quick start of dependencies
start-dependencies:
- docker-compose -f docker-compose.yml up -d --build mariadb rabbitmq
# Apply prerequisites such as database schema
rollup: database-truncate-and-apply
- @echo "TODO";
# Stop individual container
stop: prerequisite valid-container
- docker-compose -f docker-compose.yml stop $(filter-out $@,$(MAKECMDGOALS))
# Halts the docker containers
halt: prerequisite
- docker-compose -f docker-compose.yml kill
#####################################################
# SETUP AND BUILD TARGETS #
#####################################################
# Build and prepare the docker containers and the project
build: prerequisite build-containers
# Build and launch the containers
build-containers:
- docker-compose -f docker-compose.yml up --build
# Remove the docker containers
clean: prerequisite prompt-continue
# Remove the docker containers, networks and volumes
- docker-compose -f docker-compose.yml rm -svf
- docker-compose -f docker-compose.yml down -v --remove-orphans
# Echos the container status
status: prerequisite
- docker-compose -f docker-compose.yml ps
# Drop and creates a new database in MariaDB
database-setup-mariadb:
- mysql -u root -p$(DB_ROOT_PASSWORD) -h 127.0.0.1 -e "DROP DATABASE IF EXISTS ${DB_DATABASE}; CREATE DATABASE ${DB_DATABASE};"
# TODO, apply migration and seed
# Drop and creates a new test database in MariaDB
database-test-setup-mariadb:
- mysql -u root -p$(DB_ROOT_PASSWORD) -h 127.0.0.1 -e "DROP DATABASE IF EXISTS ${DB_DATABASE}_test; CREATE DATABASE ${DB_DATABASE}_test;"
#####################################################
# BASH CLI TARGETS #
#####################################################
# Opens a bash prompt to the app cli container
bash-app: prerequisite
- docker-compose -f docker-compose.yml exec --env COLUMNS=`tput cols` --env LINES=`tput lines` app bash
# Opens a bash prompt to the mariadb container
bash-mariadb: prerequisite
- docker-compose -f docker-compose.yml exec --env COLUMNS=`tput cols` --env LINES=`tput lines` mariadb bash
# Opens a bash prompt to the postgres container
bash-postgres: prerequisite
- docker-compose -f docker-compose.yml exec --env COLUMNS=`tput cols` --env LINES=`tput lines` postgres bash
# Opens the rabbitmq bash cli
bash-rabbitmq: prerequisite
- docker-compose -f docker-compose.yml exec --env COLUMNS=`tput cols` --env LINES=`tput lines` rabbitmq bash
#####################################################
# APPLICATION CLI TARGETS #
#####################################################
# Opens the mysql cli
cli-mariadb:
- docker-compose -f docker-compose.yml exec mariadb mysql -u root -p$(DB_ROOT_PASSWORD)
# Opens the mysql cli
cli-psql:
- docker-compose -f docker-compose.yml exec postgres psql -d ${DB_DATABASE}
#####################################################
# TEST TARGETS #
#####################################################
#####################################################
# INTERNAL TARGETS #
#####################################################
# Validates the prerequisites such as environment variables
prerequisite: check-environment
- @echo "pwd "$(shell pwd)
-include .env
export ENV_FILE = $(ENVIRONMENT_FILE)
# Validates the environment variables
check-environment:
@echo "Validating the environment";
# Check whether the docker binary is available
ifeq (, $(shell which docker-compose))
$(error "No docker-compose in $(PATH), consider installing docker")
endif
# Validates the containers
valid-container:
ifeq ($(filter $(filter-out $@,$(MAKECMDGOALS)),$(CONTAINERS)),)
$(error Invalid container provided "$(filter-out $@,$(MAKECMDGOALS))")
endif
# Prompt to continue
prompt-continue:
@while [ -z "$$CONTINUE" ]; do \
read -r -p "Would you like to continue? [y]" CONTINUE; \
done ; \
if [ ! $$CONTINUE == "y" ]; then \
echo "Exiting." ; \
exit 1 ; \
fi
%:
@: