-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
70 lines (51 loc) · 1.53 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
.PHONY: dev test deploy
COMPOSE=docker compose
define gen_compose_flags
--profile $(1)
endef
define gen_compose_command
PROFILE=$(strip $(1)) $(COMPOSE) $(call gen_compose_flags,$(1))
endef
COMPOSE_DEPLOY_COMMAND=$(call gen_compose_command,$(profile))
UP_FLAGS_DEV=--build
UP_FLAGS_DEPLOY=-d --force-recreate
DEV_HOST=host: localhost
PROD_HOST=host: $(BASE_HOST)
DEV_PORT=3040
PROD_PORT=3030
DEV_PROFILE=dev
TEST_PROFILE=test
PROD_PROFILE=prod
SWAGGER_DOC=docs/swagger.yml
all:
@echo "Usage: make BUILD_TARGET"
@echo ""
@echo "BUILD_TARGET:"
@echo "\ttest\t\t-\tproduction test build"
@echo "\tdev\t\t-\tbuild with hot-reload"
@echo "\tdeploy profile=\t-\tdeploy with profile prod or test"
dev:
$(call gen_compose_command,$(DEV_PROFILE)) up $(UP_FLAGS_DEV)
test:
$(call gen_compose_command,$(TEST_PROFILE)) up $(UP_FLAGS_DEV)
deploy: prepare_swagger_to_deploy
$(COMPOSE_DEPLOY_COMMAND) pull
$(COMPOSE_DEPLOY_COMMAND) up $(UP_FLAGS_DEPLOY)
prepare_swagger_to_deploy: check_deploy_environment
ifeq ($(profile),$(TEST_PROFILE))
sed -i 's/$(DEV_HOST)/$(PROD_HOST)/g' $(SWAGGER_DOC)
endif
ifeq ($(profile),$(DEV_PROFILE))
sed -i 's/$(DEV_HOST)/$(PROD_HOST)/g' $(SWAGGER_DOC)
endif
check_deploy_environment: check_profile_exists check_base_host_exists
check_profile_exists:
ifeq ($(profile),)
(error profile argument not set)
endif
check_base_host_exists:
ifeq ($(profile),$(TEST_PROFILE))
ifeq ($(BASE_HOST),)
(BASE_HOST environment variable not set)
endif
endif