forked from oligus/schema
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
132 lines (105 loc) · 3.41 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
# The default lumen directory
PROJECT_DIRECTORY=$(shell pwd)/src
# Available docker containers
CONTAINERS=php-cli
#####################################################
# #
# #
# RUNTIME TARGETS #
# #
# #
#####################################################
default: run
# Start the containers
run: prerequisite build
# Start individual container
start: prerequisite valid-container
- docker-compose -f docker-compose.yml up -d --build $(filter-out $@,$(MAKECMDGOALS))
# 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-project update-project launch-dependencies
# Build and launch the containers
build-containers:
- docker-compose -f docker-compose.yml up -d --build
# Build the project
build-project: prepare-containers
# Update the project and the dependencies
update-project:
# Update the composer dependencies
- docker-compose exec php-cli composer --ansi install
# Remove the docker containers and deletes project dependencies
clean: prerequisite prompt-continue
# Remove the dependencies
- rm -rf src/vendor
# Remove the docker containers
- docker-compose down --rmi all -v --remove-orphans
# Remove all unused volumes
- docker volume prune -f
# Remove all unused images
- docker images prune -a
# Echos the container status
status: prerequisite
- docker-compose -f docker-compose.yml ps
#####################################################
# #
# #
# BASH CLI TARGETS #
# #
# #
####################################################
# Opens a bash prompt to the php cli container
bash: prerequisite
- docker-compose exec --env COLUMNS=`tput cols` --env LINES=`tput lines` php-cli bash
#####################################################
# #
# #
# TEST TARGETS #
# #
# #
####################################################
# Launch the unit tests
test-php:
- @echo "Start the phpunit cli tests";
- docker-compose exec php-cli bash -c "cd /var/www/html && composer test"
#####################################################
# #
# #
# INTERNAL TARGETS #
# #
# #
####################################################
# 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
%:
@: