-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
90 lines (74 loc) · 2.91 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
prod_docker_compose_file=./docker/docker-compose.yml
dev_docker_compose_file=./docker/dev/docker-compose.yml
dev_override_docker_compose_file=./docker/dev/docker-compose.override.yml
test_docker_compose_file=./docker/test/docker-compose.yml
prod_docker_file=./docker/prod/Dockerfile
NODE_MODULES_DIR = './node_modules'
default: build test
# builds the project into the dist folder
build:
npm run build
# builds the docker image
build-docker:
@echo "=============building hs_application============="
docker build -f $(prod_docker_file) -t hs_application .
# sets up the hacker suite docker network
setup-network:
@echo "=============setting up the hacker suite network============="
docker network create --driver bridge hacker_suite || echo "This is most likely fine, it just means that the network has already been created"
# starts the app and MySQL in docker containers
up: export ENVIRONMENT=production
up: build-docker setup-network
@echo "=============starting hs_application============="
docker-compose -f $(prod_docker_compose_file) up -d
# starts the app in local environment and DB in container
up-dev: export ENVIRONMENT=dev
up-dev: export DB_HOST=localhost
up-dev: setup-network
@echo "=============starting hs_application (dev)============="
docker-compose -f $(dev_docker_compose_file) -f $(dev_override_docker_compose_file) up -d
if [ ! -d $(NODE_MODULES_DIR) ]; then \
@echo "node_modules does not exist, installing dependencies..."; \
npm i; \
else \
npm run start:watch; \
fi
# run all tests
tests:
docker-compose -f $(test_docker_compose_file) up -d
while ! docker exec mysql_db_test mysql --user=root -e "SELECT 1" >/dev/null 2>&1; do \
sleep 5; \
done
npm run test && (docker-compose -f $(test_docker_compose_file) down -v; exit) || (docker-compose -f $(test_docker_compose_file) down -v; exit 1)
ci:
docker-compose -f $(test_docker_compose_file) up -d
while ! docker exec mysql_db_test mysql --user=root -e "SELECT 1" >/dev/null 2>&1; do \
sleep 10; \
done
docker exec mysql_db_test mysql --user=root -e "CREATE DATABASE IF NOT EXISTS hs_applications;"
npm run test:coverage && (docker-compose -f $(test_docker_compose_file) down -v; exit) || (docker-compose -f $(test_docker_compose_file) down -v; exit 1)
# prints the logs from all containers
logs:
ifeq ($(ENV), dev)
docker-compose -f $(dev_docker_compose_file) logs -f
else
docker-compose -f $(prod_docker_compose_file) logs -f
endif
# prints the logs only from the app
logs-app:
docker logs hs_application
# prints the logs only from the database
logs-db:
docker logs mysql_db
# shuts down the containers
down:
docker-compose -f $(prod_docker_compose_file) down
docker-compose -f $(dev_docker_compose_file) down
# cleans up unused images, networks and containers
clean: down
@echo "=============cleaning up============="
rm -f hs_application
docker container prune -f
docker network prune -f
docker system prune -f
docker volume prune -f