-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
144 lines (121 loc) · 5.13 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
MAKEFLAGS += --silent --keep-going
OS_TYPE = $(shell uname)
# CURR_PATH = $(shell pwd)
ENV_FILE = $(shell echo "./app/.env")
DEFAULT_ENV_FILE = $(shell echo "./app/.env.example")
SERVICE_NAME = $(shell echo "cx-traefik-forward-auth")
DOCKER_COMPOSE_DEV = $(shell echo "docker-compose.yml")
DOCKER_COMPOSE_PROD = $(shell echo "docker-compose.yml")
########################################################################################
#### Auxiliary Functions ####
########################################################################################
.PHONY: check-env-file setup-env-file copy-env-os-save import-or-setup-env-file import-env-file
define import_env
$(eval include $(ENV_FILE))
$(eval export)
endef
check-env-file:
ifeq ("$(wildcard $(ENV_FILE))","")
@echo "[ERRR] Missing environmental file: $(ENV_FILE)! Aborting..."
exit 1
endif
setup-env-file:
ifeq ("$(wildcard $(ENV_FILE))","")
@echo "[WARN] Mising environmental file: $(ENV_FILE). Using default $(DEFAULT_ENV_FILE)"
@make copy-env-os-save
endif
copy-env-os-save:
ifeq ($(OS_TYPE),)
@echo "[INFO] Recognized Windows machine - copying $(DEFAULT_ENV_FILE) in Windows fashion... "
@echo "[INFO] Please ignore non-exiting error messages "
powershell cp $(DEFAULT_ENV_FILE) $(ENV_FILE)
# Additionally, for Windows (docker-compose) the .env file has to be present in the project root dir...
# https://github.com/docker/compose/issues/6965
powershell cp $(DEFAULT_ENV_FILE) .env
@echo "[WARN] On Windows machine the .env file doesn't get imported into Makefile!"
@echo "[WARN] And in addition the $(DEFAULT_ENV_FILE) will be copied each time you run Makefile"
else
@echo "[INFO] Recognized Linux/MacOS machine - copying $(DEFAULT_ENV_FILE) in Unix fashion... "
cp $(DEFAULT_ENV_FILE) $(ENV_FILE)
endif
import-or-setup-env-file: setup-env-file
$(import_env)
@echo "[INFO] Successfully imported '$(APP_NAME)' .env file"
import-env-file: check-env-file
$(import_env)
@echo "[INFO] Successfully imported '$(APP_NAME)' .env file"
########################################################################################
#### Development Environment ####
########################################################################################
.PHONY: build-dev-env run-dev-env down-dev-env
.PHONY: run-unit-tests run-ut-coverage-html run-lint-check
# Build DEV service(s) instance(s) on your machine
build-dev-env: import-or-setup-env-file
@docker-compose \
--file $(DOCKER_COMPOSE_DEV) \
build
@echo "[INFO] $(APP_NAME):$(APP_VERSION) dev instance was successfully built"
# Run DEV service(s) instance(s)
run-dev-env: import-or-setup-env-file
@docker-compose \
--file $(DOCKER_COMPOSE_DEV) up \
--detach
@echo "[INFO] $(APP_NAME):$(APP_VERSION) dev instance was successfully started!"
# Run unit tests on DEV instance
run-unit-tests: import-or-setup-env-file
@docker-compose \
--file $(DOCKER_COMPOSE_DEV) run \
--rm \
$(SERVICE_NAME) \
yarn test:unit
@echo "[INFO] Unit Tests on $(APP_NAME):$(VERSION) dev instance was successfully run!"
# Run unit tests on DEV instance with coverage report in HTML
run-ut-coverage-html: import-or-setup-env-file
@docker-compose \
--file $(DOCKER_COMPOSE_DEV) run \
--rm \
$(SERVICE_NAME) \
yarn test:coverage
@echo "[INFO] Unit Tests on $(APP_NAME):$(VERSION) dev instance was successfully run! Preview report in ./app/coverage/index.html"
# Run lint check on DEV instance
run-lint-check: import-or-setup-env-file
@docker-compose \
--file $(DOCKER_COMPOSE_DEV) run \
--rm \
$(SERVICE_NAME) \
yarn lint
@echo "[INFO] Lint Check on $(APP_NAME):$(VERSION) dev instance was successfully run!"
# Stop and clear DEV service(s) instance(s)
down-dev-env: import-or-setup-env-file
@docker-compose \
--file $(DOCKER_COMPOSE_DEV) \
down --remove-orphans
@echo "[INFO] $(APP_NAME):$(APP_VERSION) dev instance was successfully downed."
########################################################################################
#### Production Environment ####
########################################################################################
.PHONY: build-prod-env pull-prod-env run-prod-env down-prod-env
# Build prod service(s) instance(s) on your machine
build-prod-env: import-env-file
@docker-compose \
--file $(DOCKER_COMPOSE_PROD) \
build
@echo "[INFO] $(APP_NAME):$(APP_VERSION) prod instance was successfully built!"
# Pull prod service(s) instance(s) to your machine
pull-prod-env: import-env-file
@docker-compose \
--file $(DOCKER_COMPOSE_PROD) \
pull
@echo "[INFO] $(APP_NAME):$(APP_VERSION) prod instance was successfully pulled!"
# Run prod service(s) instance(s)
run-prod-env: import-env-file
@docker-compose \
--file $(DOCKER_COMPOSE_PROD) up \
--detach
@echo "[INFO] $(APP_NAME):$(APP_VERSION) prod instance was successfully started!"
# Stop and clear service(s) instance(s)
down-prod-env: import-env-file
@docker-compose \
--file $(DOCKER_COMPOSE_PROD) \
down --remove-orphans
@echo "[INFO] $(APP_NAME):$(APP_VERSION) prod instance was successfully downed."