-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
215 lines (167 loc) · 6.56 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
-include .env
ifeq ($(COMPOSE_PROJECT_NAME),)
COMPOSE_PROJECT_NAME=wod
endif
# BuildKit enables higher performance docker builds and caching possibility
# to decrease build times and increase productivity for free.
export DOCKER_BUILDKIT ?= 1
export COMPOSE_PROJECT_NAME_SLUG = $(subst $e.,-,$(COMPOSE_PROJECT_NAME))
export COMPOSE_PROJECT_NAME_SAFE = $(subst $e.,_,$(COMPOSE_PROJECT_NAME))
export SHARED_SERVICES_NETWORK = $(addsuffix _network,$(subst $e.,_,$(SHARED_SERVICES_NAMESPACE)))
DOCKER ?= docker
DOCKER_COMPOSE ?= docker compose
# Support image with all needed binaries, like envsubst, mkcert, wait4x
SUPPORT_IMAGE ?= wayofdev/build-deps:alpine-latest
BUILDER_PARAMS ?= docker run --rm -i \
--env-file ./.env \
--env COMPOSE_PROJECT_NAME_SLUG=$(COMPOSE_PROJECT_NAME_SLUG) \
--env COMPOSE_PROJECT_NAME_SAFE=$(COMPOSE_PROJECT_NAME_SAFE) \
--env SHARED_SERVICES_NETWORK=$(SHARED_SERVICES_NETWORK)
BUILDER ?= $(BUILDER_PARAMS) $(SUPPORT_IMAGE)
# Shorthand wait4x command, executed through build-deps
WAITER ?= $(BUILDER) wait4x
# Shorthand envsubst command, executed through build-deps
ENVSUBST ?= $(BUILDER) envsubst
EXPORT_VARS = '\
$${SHARED_SERVICES_NETWORK} \
$${COMPOSE_PROJECT_NAME} \
$${COMPOSE_PROJECT_NAME_SLUG} \
$${COMPOSE_PROJECT_NAME_SAFE}'
.EXPORT_ALL_VARIABLES:
ifneq ($(TERM),)
BLACK := $(shell tput setaf 0)
RED := $(shell tput setaf 1)
GREEN := $(shell tput setaf 2)
YELLOW := $(shell tput setaf 3)
LIGHTPURPLE := $(shell tput setaf 4)
PURPLE := $(shell tput setaf 5)
BLUE := $(shell tput setaf 6)
WHITE := $(shell tput setaf 7)
RST := $(shell tput sgr0)
else
BLACK := ""
RED := ""
GREEN := ""
YELLOW := ""
LIGHTPURPLE := ""
PURPLE := ""
BLUE := ""
WHITE := ""
RST := ""
endif
MAKE_LOGFILE = /tmp/docker-project-services.log
MAKE_CMD_COLOR := $(BLUE)
default: all
help:
@echo 'Management commands for package:'
@echo 'Usage:'
@echo ' ${MAKE_CMD_COLOR}make${RST} Creates containers, spins up project'
@grep -E '^[a-zA-Z_0-9%-]+:.*?## .*$$' Makefile | awk 'BEGIN {FS = ":.*?## "}; {printf " ${MAKE_CMD_COLOR}make %-21s${RST} %s\n", $$1, $$2}'
@echo
@echo ' 📑 Logs are stored in $(MAKE_LOGFILE)'
@echo
@echo ' 📦 Package docker-project-services (github.com/wayofdev/docker-project-services)'
@echo ' 🤠 Author Andrij Orlenko (github.com/lotyp)'
@echo ' 🏢 ${YELLOW}Org wayofdev (github.com/wayofdev)${RST}'
.PHONY: help
all: hooks env mkcert up
PHONY: all
# System Actions
# ------------------------------------------------------------------------------------
override-create: ## Generate override file from dist
cp -v docker-compose.override.yaml.dist docker-compose.override.yaml
.PHONY: override-create
env: ## Generate .env file from example
$(ENVSUBST) '$${COMPOSE_PROJECT_NAME} $${COMPOSE_PROJECT_NAME_SAFE}' < .env.example > .env
.PHONY: env
# Docker and Docker compose Actions
# ------------------------------------------------------------------------------------
up: ## Fire up project
$(DOCKER_COMPOSE) up --remove-orphans -d
make _kc-wait kc-configure kc-update
.PHONY: up
down: ## Stops and destroys running containers
$(DOCKER_COMPOSE) down --remove-orphans
.PHONY: down
stop: ## Stops all containers, without removing them
$(DOCKER_COMPOSE) stop
.PHONY: stop
restart: ## Restart all containers, running in this project
$(DOCKER_COMPOSE) restart
.PHONY: restart
logs: ## Show logs for running containers in this project
$(DOCKER_COMPOSE) logs -f
.PHONY: logs
logs-keycloak: ## Show logs for running containers in this project
$(DOCKER_COMPOSE) logs keycloak -f
.PHONY: logs
ps: ## List running containers in this project
$(DOCKER_COMPOSE) ps
.PHONY: ps
pull: ## Pull upstream images, specified in docker-compose.yml file
$(DOCKER_COMPOSE) pull
.PHONY: pull
clean:
$(DOCKER_COMPOSE) rm --force --stop
.PHONY: clean
# Testing
# ------------------------------------------------------------------------------------
# dcgoss binary is used for testing — https://github.com/aelsabbahy/goss/tree/master/extras/dcgoss
test: ## Run self-tests using dcgoss
dcgoss run rabbitmq
.PHONY: test
# Git Actions
# ------------------------------------------------------------------------------------
hooks: ## Install git hooks from pre-commit-config
pre-commit install
pre-commit autoupdate
.PHONY: hooks
# Yaml Actions
# ------------------------------------------------------------------------------------
lint: ## Lints yaml files inside project
yamllint .
.PHONY: lint
# RabbitMQ Actions
# ------------------------------------------------------------------------------------
rabbit-up: ## Create and start rabbitmq container
$(DOCKER_COMPOSE) up -d rabbitmq
.PHONY: rabbit-up
rabbit-recreate: rabbit-clean rabbit-up _rabbit-wait ## Stop, delete container and volume, then create and start new one
.PHONY: rabbit-recreate
rabbit-clean: ## Removes container and its volume
$(DOCKER_COMPOSE) rm -svf rabbitmq
$(DOCKER) volume rm -f $(COMPOSE_PROJECT_NAME_SAFE)_rabbitmq_data
.PHONY: rabbit-clean
_rabbit-wait:
wait4x rabbitmq 'amqp://rabbitmq.$(COMPOSE_PROJECT_NAME).docker:5672'
.PHONY: _rabbit-wait
# Keycloak Actions
# ------------------------------------------------------------------------------------
kc-up: ## Create and start keycloak container
$(DOCKER_COMPOSE) up -d keycloak
.PHONY: kc-up
kc-recreate: kc-clean kc-get-theme kc-up _kc-wait kc-configure kc-update ## Stop, delete container and volume, then create and start new one
.PHONY: kc-recreate
kc-clean: ## Removes keycloak, keycloak database containers and their volumes
$(DOCKER_COMPOSE) rm -svf keycloak-database keycloak
$(DOCKER) volume rm -f $(COMPOSE_PROJECT_NAME)_keycloak_data
.PHONY: kc-clean
_kc-wait:
@$(DOCKER) run --rm --net=host --name='wait4x' atkrad/wait4x:latest \
http $(shell docker inspect --format 'http://127.0.0.1:{{ (index (index .NetworkSettings.Ports "8080/tcp") 0).HostPort }}' $(COMPOSE_PROJECT_NAME)_keycloak) \
-t 2m
.PHONY: _kc-wait
kc-configure: kc-get-theme
$(DOCKER_COMPOSE) exec -T keycloak sh /tmp/setup/setup-master-realm.sh
$(DOCKER_COMPOSE) exec -T keycloak sh /tmp/setup/setup-client-realm.sh
$(DOCKER_COMPOSE) exec -T keycloak sh /tmp/setup/setup-operations-realm.sh
.PHONY: kc-configure
kc-update:
$(DOCKER_COMPOSE) exec -T keycloak sh /tmp/setup/update-realms.sh
.PHONY: kc-update
kc-get-theme:
wget https://github.com/$(KC_THEME_REPOSITORY)/releases/latest/download/keywind.jar -O keycloak/themes/keywind.jar
.PHONE: kc-get-theme
mkcert:
mkcert -key-file keycloak/certs/key.pem -cert-file keycloak/certs/cert.pem auth.wod.docker *.wod.docker
.PHONY: mkcert