-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
231 lines (191 loc) Β· 6.86 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
.PHONY: setup test
export MIX_ENV ?= dev
LOCAL_ENV_FILE = .env
PROD_ENV_FILE = .env.prod
APP_NAME = `grep 'APP_NAME=' .env | sed -e 's/\[//g' -e 's/ //g' -e 's/APP_NAME=//'`
DOCKERFILE_DIR = devops/builder/
CONTAINER_NAME = ex_commerce_app
IMAGE_NAME = ex_commerce_app
# Add env variables if needed
ifneq (,$(wildcard ${LOCAL_ENV_FILE}))
include ${LOCAL_ENV_FILE}
export
endif
export GREEN=\033[0;32m
export NOFORMAT=\033[0m
default: help
#π check: @ Runs all code verifications
check: check.lint check.dialyzer test
#π check.dialyzer: @ Runs a static code analysis
check.dialyzer: SHELL:=/bin/bash
check.dialyzer:
@source ${LOCAL_ENV_FILE} && mix check.dialyzer
#π check.lint: @ Strictly runs a code formatter
check.lint: SHELL:=/bin/bash
check.lint:
@source ${LOCAL_ENV_FILE} && mix check.format
@source ${LOCAL_ENV_FILE} && mix check.credo
#π§Ή clean.uploads: @ Removes all files from the uploads dir
clean.uploads: SHELL:=/bin/bash
clean.uploads:
@source ${LOCAL_ENV_FILE} && \
find ${UPLOADS_PATH} -path ${UPLOADS_PATH}/.gitkeep -prune -o -name "*.*" -exec /bin/rm -f {} \;
#π³ docker.build: @ Builds a new image for the service.
docker.build:
@docker build \
./ \
--build-arg UPLOADS_PATH=${UPLOADS_PATH} \
--build-arg RECAPTCHA_PUBLIC_KEY=${RECAPTCHA_PUBLIC_KEY} \
--build-arg RECAPTCHA_SECRET=${RECAPTCHA_SECRET} \
-f $(DOCKERFILE_DIR)/Dockerfile \
-t $(CONTAINER_NAME)
#π³ docker.connect: @ Connect to the running container
docker.connect:
@docker exec -it $(CONTAINER_NAME) /bin/sh
#π³ docker.delete: @ Delete the docker container
docker.delete: CONTAINER_NAME:=$(CONTAINER_NAME)
docker.delete:
@docker rm $(CONTAINER_NAME) 2> /dev/null || true
#π³ docker.logs: @ Show logs for the docker container
docker.logs: CONTAINER_NAME:=$(CONTAINER_NAME)
docker.logs:
@docker logs $(CONTAINER_NAME) -f
#π³ docker.release: @ Re-create a docker image and run it
docker.release: PORT:=5000
docker.release: INTERNAL_PORT:=5001
docker.release: docker.stop docker.delete docker.build docker.run
#π³ docker.rerun: @ Stops and deletes old container to re-run a fresh new container
docker.rerun: PORT:=5000
docker.rerun: INTERNAL_PORT:=5001
docker.rerun: docker.stop docker.delete docker.run
#π³ docker.run: @ Run the docker container
docker.run: PORT:=5000
docker.run: INTERNAL_PORT:=5001
docker.run: CONTAINER_NAME:=$(CONTAINER_NAME)
docker.run: IMAGE_NAME:=$(IMAGE_NAME)
docker.run:
@docker run --detach --name $(CONTAINER_NAME) --network devops_ex_commerce_storage -p $(PORT):$(INTERNAL_PORT) --env PORT=$(INTERNAL_PORT) --env-file .env.prod $(IMAGE_NAME)
#π³ docker.stop: @ Stop the docker container
docker.stop: CONTAINER_NAME:=$(CONTAINER_NAME)
docker.stop:
@docker container stop $(CONTAINER_NAME) 2> /dev/null || true
#π docs: @ Generates HTML documentation
docs:
@mix docs
#β help: @ Displays this message
help:
@echo ""
@echo "List of available MAKE targets for development usage."
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Examples:"
@echo ""
@echo " make ${GREEN}start${NOFORMAT} - Starts docker services"
@echo " make ${GREEN}setup${NOFORMAT} - Set up the whole project and database"
@echo " make ${GREEN}server${NOFORMAT} - Starts a development server"
@echo " make ${GREEN}stop${NOFORMAT} - Stops docker services"
@echo ""
@grep -E '[a-zA-Z\.\-]+:.*?@ .*$$' $(firstword $(MAKEFILE_LIST))| tr -d '#' | awk 'BEGIN {FS = ":.*?@ "}; {printf "${GREEN}%-30s${NOFORMAT} %s\n", $$1, $$2}'
#π» lint: @ Formats code
lint: SHELL:=/bin/bash
lint: MIX_ENV=dev
lint:
@mix format
@mix check.credo
#π£ reset: @ Cleans dependencies then re-installs and compiles them for all envs
reset: SHELL:=/bin/bash
reset: reset.dev reset.test
#π£ reset.dev: @ Cleans dependencies then re-installs and compiles them1 for dev env
reset.dev: SHELL:=/bin/bash
reset.dev: MIX_ENV=dev
reset.dev:
@echo "π§Ή Cleaning db and dependencies for dev..."
@mix reset
#π£ reset.test: @ Cleans dependencies then re-installs and compiles them1 for test env
reset.test: SHELL:=/bin/bash
reset.test: MIX_ENV=test
reset.test:
@echo "π§Ή Cleaning db and dependencies for test..."
@mix reset
#π£ reset.ecto: @ Resets database for all envs
reset.ecto: SHELL:=/bin/bash
reset.ecto: reset.ecto.dev reset.ecto.test
#π£ reset.ecto.dev: @ Resets database for dev env
reset.ecto.dev: SHELL:=/bin/bash
reset.ecto.dev: MIX_ENV=dev
reset.ecto.dev:
@echo "π§Ή Cleaning db for dev env..."
@mix reset.ecto
#π£ reset.ecto.test: @ Resets database for test env
reset.ecto.test: SHELL:=/bin/bash
reset.ecto.test: MIX_ENV=test
reset.ecto.test:
@echo "π§Ή Cleaning db for test env..."
@mix reset.ecto
#π¦ setup: @ Installs dependencies and set up database for dev and test envs
setup: SHELL:=/bin/bash
setup: setup.dev setup.test
#π¦ setup.dev: @ Installs dependencies and set up database for dev env
setup.dev: SHELL:=/bin/bash
setup.dev: MIX_ENV=dev
setup.dev:
@mix setup
@mix git_hooks.install
#π¦ setup.test: @ Installs dependencies and set up database for test env
setup.test: SHELL:=/bin/bash
setup.test: MIX_ENV=test
setup.test:
@mix setup
#π¦ setup.deps: @ Installs dependencies for development
setup.deps: setup.deps.dev setup.deps.test
#π¦ setup.deps.ci: @ Installs dependencies for the CI environment
setup.deps.ci:
@mix install
#π¦ setup.deps.dev: @ Installs dependencies only for dev env
setup.deps.dev: SHELL:=/bin/bash
setup.deps.dev: MIX_ENV=dev
setup.deps.dev:
@mix install
#π¦ setup.deps.test: @ Installs dependencies only for test env
setup.deps.test: SHELL:=/bin/bash
setup.deps.test: MIX_ENV=test
setup.deps.test:
@mix install
#π» server: @ Starts a server with an interactive elixir shell.
server: SHELL:=/bin/bash
server:
@iex --name ${APP_NAME}@127.0.0.1 -S mix phx.server
#π§ͺ test: @ Runs all test suites
test: SHELL:=/bin/bash
test: MIX_ENV=test
test:
@mix test
#π§ͺ test.cover: @ Runs all tests and generates a coverage report
test.cover: SHELL:=/bin/bash
test.cover: MIX_ENV=testMIX_ENV=test
test.cover:
@mix coveralls.html
#π§ͺ test.watch: @ Runs and watches all test suites
test.watch: SHELL:=/bin/bash
test.watch: MIX_ENV=test
test.watch:
@echo "π§ͺποΈ Watching all test suites..."
@mix test.watch
#π§ͺ test.wip: @ Runs test suites that match the wip tag
test.wip: SHELL:=/bin/bash
test.wip: MIX_ENV=test
test.wip:
@mix test --only wip
#π§ͺ test.wip.watch: @ Runs and watches test suites that match the wip tag
test.wip.watch: SHELL:=/bin/bash
test.wip.watch: MIX_ENV=test
test.wip.watch:
@echo "π§ͺποΈ Watching test suites tagged with wip..."
@mix test.watch --only wip
#π translations: @ Extract new untranslated phrases and merge translations to avaialble languages. This command uses fuzzy auto-generated transaltions, it generally needs a manual update to each language afterwards.
translations: SHELL:=/bin/bash
translations:
@mix gettext.extract
@mix gettext.merge priv/gettext --locale es
@mix gettext.merge priv/gettext --locale en