-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
145 lines (126 loc) · 4.68 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
-include .envrc
export
uname_OS := $(shell uname -s)
user_UID := $(shell id -u)
user_GID := $(shell id -g)
current_uid ?= "${user_UID}:${user_GID}"
ifeq ($(uname_OS),Darwin)
user_UID := 1001
user_GID := 1001
endif
# Passing the >_ options option
options := $(if $(options),$(options),--env-file ./docker/.env)
# Passing the >_ up_options option
up_options := $(if $(up_options),$(up_options),--force-recreate --no-build --no-deps --detach)
# Passing the >_ common_options option
common_options := $(if $(common_options),$(common_options),--compatibility --ansi=auto)
# ==================================================================================== #
# HELPERS
# ==================================================================================== #
# internal functions
define message_failure
"\033[1;31m ❌$(1)\033[0m"
endef
define message_success
"\033[1;32m ✅$(1)\033[0m"
endef
define message_info
"\033[0;34m❕$(1)\033[0m"
endef
## help: print this help message
.PHONY: help
help:
@echo 'Usage:'
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
# ==================================================================================== #
# DOCKER
# ==================================================================================== #
.PHONY: docker/config-env
docker/config-env:
@cd docker && cp -n .env.compose .env || true
@cd docker && sed -i "/^# PWD/c\PWD=$(shell pwd)" .env
@cd docker && sed -i "/^# ROOT_PATH/c\ROOT_PATH=$(shell pwd)" .env
@cd docker && sed -i "/# USER_UID=.*/c\USER_UID=$(user_UID)" .env
@cd docker && sed -i "/# USER_GID=.*/c\USER_GID=$(user_GID)" .env
@cd docker && sed -i "/^# CURRENT_UID/c\CURRENT_UID=${current_uid}" .env
@echo
@echo $(call message_success, Run \`make docker/config-env\` successfully executed)
.PHONY: docker/healthcheck
docker/healthcheck:
# make docker/healthcheck container=app_database
@timeout=60; counter=0; \
printf "\n\033[3;33mEsperando healthcheck do container de banco de dados \"$${container}\" = \"healthy\" ⏳ \033[0m\n" ; \
until [[ "$$(docker container inspect -f '{{.State.Health.Status}}' $${container})" == "healthy" ]] ; do \
printf '.' ; \
if [[ $${timeout} -lt $${counter} ]]; then \
printf "\n\033[1;31mERROR: Timed out waiting for \"$${container}\" to come up/healthy ❌\033[0m\n\n" ; \
exit 1 ; \
fi ; \
\
printf "\n\033[35mWaiting for \"$${container}\" to be ready/healthy ($${counter}/$${timeout}) ⏱ \033[0m\n" ; \
sleep 5s; counter=$$((counter + 5)) ; \
done
@echo
@echo $(call message_success, HEALTHCHECK do Container \"$${container}\" OK)
.PHONY: docker/build/app
docker/build/app:
@echo
@echo $(call message_info, Build an image APP... 🏗)
@echo
docker-compose \
-f ./docker/php/services/app/docker-compose.yml \
--ansi=auto \
--env-file ./docker/.env \
build --progress=plain app
.PHONY: docker/app/up
docker/app/up:
@echo
@echo $(call message_info, Running APP Container... 🚀)
@echo
@$(MAKE) --no-print-directory docker/service/up context="php/services/app" up_options="--force-recreate --no-deps"
.PHONY: docker/queue/up
docker/queue/up:
@echo
@echo $(call message_info, Running QUEUE Container... 🚀)
@echo
@$(MAKE) --no-print-directory docker/service/up context="php/services/queue"
.PHONY: docker/scheduler/up
docker/scheduler/up:
@echo
@echo $(call message_info, Running SCHEDULER Container... 🚀)
@echo
@$(MAKE) --no-print-directory docker/service/up context="php/services/scheduler"
.PHONY: docker/database/up
docker/database/up:
@echo
@echo $(call message_info, Running Docker Database... 🚀)
@echo
@$(MAKE) --no-print-directory docker/service/up context=mysql
.PHONY: docker/redis/up
docker/redis/up:
@echo
@echo $(call message_info, Running Docker Redis... 🚀)
@echo
@$(MAKE) --no-print-directory docker/service/up context=redis
# make docker/service/up \
context=FOLDER_IN_SERVICES \
options=--verbose \
up_options="--force-recreate" \
services="services_in_docker_compose"
.PHONY: docker/service/up
docker/service/up:
@docker-compose --log-level=ERROR -f ./docker/$(context)/docker-compose.yml \
$(options) $(common_options) \
up $(up_options) \
$(if $(services),$(services),)
.PHONY: docker/up
docker/up:
@echo
@echo $(call message_info, Running Docker Application... 🚀)
@echo
@docker-compose --log-level=ERROR -f ./docker/docker-compose.yml up
@$(MAKE) --no-print-directory docker/database/up
@$(MAKE) --no-print-directory docker/healthcheck container=$(if $(database_container),$(database_container),currency_database)
@$(MAKE) --no-print-directory docker/redis/up
@$(MAKE) --no-print-directory docker/healthcheck container=$(if $(redis_container),$(redis_container),currency_redis)
@$(MAKE) --no-print-directory docker/app/up