This repository has been archived by the owner on May 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
124 lines (94 loc) · 3.44 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
.DEFAULT_GOAL = help
.PHONY: help install gitmodules build start start-db init-db stop wait-healthy sh exec logs watch lint fix test unit-test integration-test api-validate api-test run dev prod
SHELL = /usr/bin/env bash
ifneq (${TARGET}, prod)
TARGET = dev
INITDB = initdb:dev
else
INITDB = initdb
endif
DOCKER_COMPOSE = docker-compose --file .docker/docker-compose.yml --file .docker/docker-compose.${TARGET}.yml
ifeq (${HYDRA_CONSOLE}, true)
DOCKER_COMPOSE := ${DOCKER_COMPOSE} --file .docker/docker-compose.console.yml
endif
STOP = exit=$$?; $(MAKE) stop; exit $$exit
STOP_WITH_LOGS = exit=$$?; $(MAKE) logs; $(MAKE) stop; exit $$exit
export IMAGE_TAG
export TARGET
help: ## Display this help text
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
install: node_modules gitmodules ## Install dependencies locally
node_modules: package.json package-lock.json
npm install
touch node_modules
gitmodules:
git submodule update --init --recursive
build: ## Build the containers
${DOCKER_COMPOSE} build
start: ## Start the containers
$(MAKE) init-db
${DOCKER_COMPOSE} up --detach
start-db:
${DOCKER_COMPOSE} up --detach db
init-db:
$(MAKE) start-db wait-healthy
${DOCKER_COMPOSE} run --rm app npm run ${INITDB}
stop: ## Stop the containers
${DOCKER_COMPOSE} down
wait-healthy: ## Wait for the containers to be healthy
@services=($$(${DOCKER_COMPOSE} ps --quiet)); \
if [ $${#services[@]} -eq 0 ]; then \
echo "No containers running"; \
exit 1; \
fi; \
for service in $${services[@]}; do \
.scripts/docker/wait-healthy.sh "$${service}"; \
done
sh: ## Open a shell on the app container
$(MAKE) exec command="sh"
tty = 1
exec: ## Run a command on the app container
@if [ -z "$(command)" ]; then \
echo "No command provided"; \
exit 1; \
fi;
${DOCKER_COMPOSE} exec $(if $(tty),,-T) app $(command)
logs: ## Show the containers' logs
${DOCKER_COMPOSE} logs
watch: ## Follow the containers' logs
${DOCKER_COMPOSE} logs --follow
lint: export TARGET = dev
lint: ## Lint the code
${DOCKER_COMPOSE} run --rm app npm run lint
fix: export TARGET = dev
fix: ## Fix linting issues in the code
${DOCKER_COMPOSE} run --rm app npm run lint:fix
test: export TARGET = dev
test: ## Run all the Jest tests
$(MAKE) start-db wait-healthy
${DOCKER_COMPOSE} run --rm app npm run test; ${STOP}
unit-test: export TARGET = dev
unit-test: ## Run the unit tests
${DOCKER_COMPOSE} run --rm app npm run test:unit
integration-test: export TARGET = dev
integration-test: ## Run the integration tests
$(MAKE) start-db wait-healthy
${DOCKER_COMPOSE} run --rm app npm run test:integration; ${STOP}
api-validate: ## Run the API analysis
$(MAKE) start wait-healthy
docker run --rm --network host hydrofoil/hydra-analyser:0.2.0 http://localhost:8080/; ${STOP}
api-test: ## Run the API tests
$(MAKE) start wait-healthy
docker run --rm --init --network host --mount "type=bind,source=$(CURDIR)/test/hypertest/,destination=/tests" hydrofoil/hypertest:_0.4.1 --baseUri http://localhost:8080/; ${STOP_WITH_LOGS}
run:
$(MAKE) init-db
${DOCKER_COMPOSE} up --abort-on-container-exit --exit-code-from app; ${STOP}
dev: export TARGET = dev
dev: export HYDRA_CONSOLE = true
dev: ## Build and runs the container and Hydra console for development
$(MAKE) --jobs=4 install build stop
$(MAKE) run
prod: export TARGET = prod
prod: ## Builds and runs the container for production
$(MAKE) --jobs=2 build stop
$(MAKE) run