-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
114 lines (83 loc) · 2.87 KB
/
Makefile
File metadata and controls
114 lines (83 loc) · 2.87 KB
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
IMAGE_NAME=nestjs-example
# Set environment variable(s) to allow for multiple containers [e.g. export CONTAINER_NAME_WORKER_SUFFIX=_d]
CONTAINER_NAME_WORKER:=nestjs-dev-worker$(CONTAINER_NAME_WORKER_SUFFIX)
CONTAINER_NAME_SERVICE:=nestjs-prod-service$(CONTAINER_NAME_SERVICE_SUFFIX)
CONTAINER_NAME_POSTMAN:=postman-newman-test-api$(CONTAINER_NAME_POSTMAN_SUFFIX)
WORKER=docker-compose run --name $(CONTAINER_NAME_WORKER) --service-ports --rm worker
SERVICE=docker-compose run -d --name $(CONTAINER_NAME_SERVICE) --service-ports --rm nestjs-example-api
POSTMAN=docker-compose run --name $(CONTAINER_NAME_POSTMAN) --service-ports --rm postman-newman
YARNPKG=
# Tell Make, that these are commands, not files. This is needed when there're files with the same name.
# Based on: https://stackoverflow.com/questions/2145590/what-is-the-purpose-of-phony-in-a-makefile
.PHONY: install add build test dev debug lint audit clean sweep
install:
$(WORKER) make _install
_install:
yarn install
# Adds a NPM package (to package.json and yarn.lock)
add:
$(WORKER) make _add YARNPKG=$(YARNPKG)
_add:
if test -z ${YARNPKG}; then \
echo "No package provided."; \
echo "Usage/example: make add YARNPKG=typescript"; \
else \
yarn add $(YARNPKG); \
fi
build:
$(WORKER) make _build
_build:
yarn build
test:
$(WORKER) make _test
_test:
yarn test:report
dev:
$(WORKER) make _dev
_dev:
yarn start:dev
debug:
echo $(CONTAINER_NAME_WORKER_SUFFIX)
echo $(CONTAINER_NAME_WORKER)
$(WORKER) make _debug
_debug:
yarn start:debug
lint:
$(WORKER) make _lint
_lint:
yarn lint
audit:
$(WORKER) make _audit
_audit:
yarn audit
# Postman / Newman Test API
test_api:
$(POSTMAN) run nestjs.postman_collection.json --environment=nestjs.postman_environment.json --reporters cli,junit --reporter-junit-export="newman-report.xml"
# Starts Mongo Express (Web Based Mongo Admin Interface)
mongo_express:
docker-compose up -d mongo-express
# Builds a production container. You can change via the IMAGE_NAME var.
# e.g. make build_container IMAGE_NAME=my-container
build_container:
docker build --target production -t $(IMAGE_NAME) .
# Build / Re-build the Service (production)
build_service:
docker-compose build nestjs-example-api
# Build / Re-build the Worker (development)
build_worker:
docker-compose build worker
# Starts the app (background) in a prod container. Uses env vars from .env
start_container:
$(SERVICE)
# Opens a shell to the app's prod container. Uses env vars from .env
debug_container:
$(SERVICE) /bin/sh
# Shuts down all docker-compose instances & cleans the local images.
# Based on https://vsupalov.com/cleaning-up-after-docker/
clean:
docker-compose down --rmi local --remove-orphans
# Shuts down all docker-compose instances, volumes, deletes images etc.
# This will make subsequent 3M runs significantly slower
sweep:
docker-compose down -v --rmi all --remove-orphans
# docker system prune