This repository has been archived by the owner on Mar 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
163 lines (117 loc) · 4.11 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
SHELL := /bin/bash
NAME := saffron
ORG := studioaquatan
# Calyx container image
API_SRC_DIR := ./calyx
API_IMAGE := $(ORG)/$(NAME)-calyx
API_IMAGE_VERSION := dev
ARGS := "-h"
# Petals container image
FRONT_SRC_DIR := ./petals
FRONT_IMAGE := $(ORG)/$(NAME)-petals
FRONT_IMAGE_VERSION := dev
# Bulb container image
DB_DIR := ./bulb
DB_IMAGE := $(ORG)/mysql-utf8mb4
DB_IMAGE_VERSION := latest
$(FRONT_SRC_DIR)/build/index.html:
cd $(FRONT_SRC_DIR) && yarn build
build: $(FRONT_SRC_DIR)/build/index.html
node_modules:
cd $(FRONT_SRC_DIR) && yarn install
venv:
cd $(API_SRC_DIR)/src && PIPENV_VENV_IN_PROJECT=true pipenv install --dev
calyx-image:
docker build $(API_SRC_DIR) -t $(API_IMAGE):$(API_IMAGE_VERSION)
petals-image:
docker build $(FRONT_SRC_DIR) -t $(FRONT_IMAGE):$(FRONT_IMAGE_VERSION)
image: calyx-image petals-image
pull:
docker pull $(DB_IMAGE):$(DB_IMAGE_VERSION)
docker pull $(API_IMAGE):$(API_IMAGE_VERSION)
docker pull $(FRONT_IMAGE):$(FRONT_IMAGE_VERSION)
deps: venv pull node_modules
db:
@docker-compose -f docker-compose.dev.yml up -d bulb
guard-env-%:
@if [ ! -n "${*}" ]; then \
echo "Please specify environment, 'dev' or 'qa' or 'prod'."; \
exit 1; \
elif [ "${*}" != "dev" ] && [ "${*}" != "prod" ] && [ "${*}" != "qa" ]; then \
echo "Environment is only accepted 'dev' or 'qa' or 'prod'."; \
exit 1; \
fi
# Manage frontend application container and database container only for backend development.
build-client-%: guard-env-%
@if [ "${*}" == "dev" ]; then \
docker-compose -f docker-compose.${*}.yml build petals; \
else \
make petals-image; \
fi
start-client-%: guard-env-%
@echo "Run frontend application container (Petals)"
@echo "Run database container (Bulb)"
@docker-compose -f docker-compose.${*}.yml up -d petals bulb
stop-client-%: stop-%
clean-client-%: clean-%
restart-client-%: guard-env-%
@docker-compose -f docker-compose.${*}.yml restart petals bulb
# Shortcut for update backends
update-client-%: guard-env-% build-client-% start-client-% prune
@echo "Petals container is now up-to-date."
# To keep compatibility
migrate-client-%: migrate-%
manage-client-%: manage-%
# Manage backend application container and database container only for frontend development.
build-api-%: guard-env-% calyx-image
start-api-%: guard-env-%
@echo "Run backend application container (Calyx)"
@echo "Run database container (Bulb)"
@docker-compose -f docker-compose.${*}.yml up -d calyx bulb
stop-api-%: stop-%
clean-api-%: clean-%
restart-api-%: guard-env-%
@docker-compose -f docker-compose.${*}.yml restart calyx bulb
# Shortcut for update backends
update-api-%: guard-env-% calyx-image start-api-% migrate-% prune
@echo "Calyx container is now up-to-date."
# To keep compatibility
migrate-api-%: migrate-%
manage-api-%: manage-%
# General commands for development.
build-%: guard-env-%
@docker-compose -f docker-compose.${*}.yml build
start-%: guard-env-%
@docker-compose -f docker-compose.${*}.yml up -d
stop-%: guard-env-%
@docker-compose -f docker-compose.${*}.yml stop
clean-%: guard-env-% stop-%
@docker-compose -f docker-compose.${*}.yml rm
restart-%: guard-env-%
@docker-compose -f docker-compose.${*}.yml restart
test-petals:
cd $(FRONT_SRC_DIR) && yarn test
test-calyx:
cd $(API_SRC_DIR)/src && pipenv run python manage.py test -v 2
test: test-petals test-calyx
lint:
cd $(FRONT_SRC_DIR) && yarn tslint
# Run schema migration for backend api
migrate-%: guard-env-%
@docker-compose -f docker-compose.${*}.yml exec calyx python manage.py migrate
# Run manage command of django
# ex) make manage-dev args=createsuperuser
manage-%: guard-env-%
@docker-compose -f docker-compose.${*}.yml exec calyx python manage.py $(args)
# Clean docker images which has no tags.
prune:
@docker image prune
$(API_SRC_DIR)/.env.%: guard-env-%
cp $(API_SRC_DIR)/.env.sample $(API_SRC_DIR)/.env.${*}
$(DB_DIR)/.env.%: guard-env-%
cp $(DB_DIR)/.env.sample $(DB_DIR)/.env.${*}
env-%:
make $(API_SRC_DIR)/.env.${*}
make $(DB_DIR)/.env.${*}
env: env-qa env-dev env-prod
.PHONY: venv image pull db deps dev dev-clean dev-stop guard-env-% start-% stop-% clean-% manage-% migrate-% prune env-% env update-% ;