-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
128 lines (99 loc) · 5.07 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
# This Makefile requires GNU Make.
MAKEFLAGS += --silent
# Settings
C_BLU='\033[0;34m'
C_GRN='\033[0;32m'
C_RED='\033[0;31m'
C_YEL='\033[0;33m'
C_END='\033[0m'
include ../../.env
DOCKER_TITLE=$(PROJECT_TITLE)
DOCKER_ABBR=$(PROJECT_ABBR)
DOCKER_CAAS=$(PROJECT_CAAS)
DOCKER_HOST=$(PROJECT_HOST)
DOCKER_PORT=$(PROJECT_PORT)
DOCKER_PATH=$(PROJECT_PATH)
CURRENT_DIR=$(patsubst %/,%,$(dir $(realpath $(firstword $(MAKEFILE_LIST)))))
DIR_BASENAME=$(shell basename $(CURRENT_DIR))
ROOT_DIR=$(CURRENT_DIR)
DOCKER_COMPOSE?=$(DOCKER_USER) docker compose
DOCKER_COMPOSE_RUN=$(DOCKER_COMPOSE) run --rm
DOCKER_EXEC_TOOLS_APP=$(DOCKER_USER) docker exec -it $(DOCKER_CAAS) sh
APPLICATION_UPDATE="composer update"
APPLICATION_INSTALL=''
help: ## shows this Makefile help message
echo 'usage: make [target]'
echo
echo 'targets:'
egrep '^(.+)\:\ ##\ (.+)' ${MAKEFILE_LIST} | column -t -c 2 -s ':#'
# -------------------------------------------------------------------------------------------------
# System
# -------------------------------------------------------------------------------------------------
.PHONY: port-check
port-check: ## shows this project port availability on local machine
echo "Checking configuration for "${C_YEL}"$(DOCKER_TITLE)"${C_END}" container:";
if [ -z "$$($(DOCKER_USER) lsof -i :$(DOCKER_PORT))" ]; then \
echo ${C_BLU}"$(DOCKER_TITLE)"${C_END}" > port:"${C_GRN}"$(DOCKER_PORT) is free to use."${C_END}; \
else \
echo ${C_BLU}"$(DOCKER_TITLE)"${C_END}" > port:"${C_RED}"$(DOCKER_PORT) is busy. Update ./.env file."${C_END}; \
fi
# -------------------------------------------------------------------------------------------------
# Enviroment
# -------------------------------------------------------------------------------------------------
.PHONY: env env-set
env: ## checks if docker .env file exists
if [ -f ./docker/.env ]; then \
echo ${C_BLU}$(DOCKER_TITLE)${C_END}" docker-compose.yml .env file "${C_GRN}"is set."${C_END}; \
else \
echo ${C_BLU}$(DOCKER_TITLE)${C_END}" docker-compose.yml .env file "${C_RED}"is not set."${C_END}" \
Create it by executing "${C_YEL}"$$ make env-set"${C_END}; \
fi
env-set: ## sets docker .env file
echo "COMPOSE_PROJECT_ABBR=\"$(DOCKER_ABBR)\"\
\nCOMPOSE_PROJECT_NAME=\"$(DOCKER_CAAS)\"\
\nCOMPOSE_PROJECT_HOST=$(DOCKER_HOST)\
\nCOMPOSE_PROJECT_PORT=$(DOCKER_PORT)\
\nCOMPOSE_PROJECT_PATH=\"$(DOCKER_PATH)\"" > ./docker/.env; \
echo ${C_BLU}"$(DOCKER_TITLE)"${C_END}" docker-compose.yml .env file "${C_GRN}"has been set."${C_END};
# -------------------------------------------------------------------------------------------------
# Container
# -------------------------------------------------------------------------------------------------
.PHONY: ssh build install-app update-app dev up start first stop restart clear
ssh: ## enters the container shell
$(DOCKER_EXEC_TOOLS_APP)
build: ## builds the container from Dockerfile
cd docker && $(DOCKER_COMPOSE) up --build --no-recreate -d
up: ## attaches to containers for a service and also starts any linked services
cd docker && $(DOCKER_COMPOSE) up -d
start: ## starts the container running
cd docker && $(DOCKER_COMPOSE) start
stop: ## stops the container running - data won't be destroyed
cd docker && $(DOCKER_COMPOSE) stop
restart: ## execute this Makefile "stop" & "start" recipes
$(MAKE) stop start
clear: ## removes container from Docker running containers
cd docker && $(DOCKER_COMPOSE) kill || true
cd docker && $(DOCKER_COMPOSE) rm --force || true
cd docker && $(DOCKER_COMPOSE) down -v --remove-orphans || true
destroy: ## delete container image from Docker - Docker prune commands still needed to be applied manually
cd docker && $(DOCKER_USER) docker rmi $(DOCKER_CAAS):$(DOCKER_ABBR)-nginx-php
dev: ## set a development enviroment
echo ${C_YEL}"\"dev\" recipe has not usage in this project"${C_END};
# -------------------------------------------------------------------------------------------------
# Container Application
# -------------------------------------------------------------------------------------------------
.PHONY: app-install app-update
app-install: ## installs the application an dependencies packages
echo "none";
app-update: ## updates dependencies packages
cd docker && $(DOCKER_EXEC_TOOLS_APP) -c $(APPLICATION_UPDATE)
# -------------------------------------------------------------------------------------------------
# Container update on the run
# -------------------------------------------------------------------------------------------------
.PHONY: nginx-conf php-conf php-fpm-conf
nginx-conf: ## updates any configuration NGINX changes while container is running
$(DOCKER_USER) docker run -v "`pwd`/nginx-server.conf:/etc/nginx/conf.d/server.conf" $(DOCKER_CAAS):$(DOCKER_ABBR)-nginx-php
php-conf: ## updates any configuration PHP changes while container is running
$(DOCKER_USER) docker run -v "`pwd`/php-setting.ini:/etc/php83/conf.d/settings.ini" $(DOCKER_CAAS)
php-fpm-conf: ## updates any configuration PHP-FPM changes while container is running
$(DOCKER_USER) docker run -v "`pwd`/php-fpm-settings.conf:/etc/php83/php-fpm.d/server.conf" $(DOCKER_CAAS)