forked from rtyler/uplink
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
88 lines (68 loc) · 2.79 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
# Root Makefile to make the building and testing of this project easier
# regardless of *nix based platform
PATH:=$(PWD)/tools:$(PATH)
TSC=$(PWD)/node_modules/typescript/bin/tsc
JEST=$(PWD)/node_modules/jest/bin/jest.js
SEQUELIZE=$(PWD)/node_modules/sequelize-cli/lib/sequelize
COMPOSE:=./tools/docker-compose
IMAGE_NAME=jenkinsciinfra/uplink
IMAGE_TAG:=$(shell git rev-parse HEAD)
JEST_ARGS=--runInBand --bail --forceExit --detectOpenHandles
# Cute hack thanks to:
# https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
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}'
all: build check container
container: Dockerfile depends ## Build the Docker container
docker build -t $(IMAGE_NAME):$(IMAGE_TAG) .
docker tag $(IMAGE_NAME):$(IMAGE_TAG) $(IMAGE_NAME):latest
publish: ## Publish the Docker container to docker hub
docker push ${IMAGE_NAME}:$(IMAGE_TAG)
docker push $(IMAGE_NAME):latest
version:
npm version
depends: version package.json package-lock.json ## Install node dependencies
if [ ! -d node_modules ]; then npm ci; fi;
build: depends ## Compile TypeScript
$(TSC)
check: build depends migrate ## Run all tests
# Running with docker-compose since our tests require a database to be
# present
$(COMPOSE) run --rm \
-e NODE_ENV=test \
node \
/usr/local/bin/node $(JEST) $(JEST_ARGS)
clean: ## Remove node_modules and clean up
$(COMPOSE) down || true
rm -rf node_modules
debug-jest: ## Launch jest with debugger on port 9229
node --inspect-brk=0.0.0.0:9229 $(JEST)
debug-db:
$(COMPOSE) run --rm db psql -h db -U postgres uplink_development
generate-event: ## Send a sample event to a service running on localhost:3030
curl -d '{"type":"stapler", "correlator" : "86e3f00d-b12a-4391-bbf2-6f01c1606e17", "payload" : {"timestamp" : "$(shell date)", "hi" : "there"}}' \
-H "Content-Type: application/json" \
http://localhost:3030/events
migrate: depends ## Run migrations against the local development database
$(COMPOSE) up -d db
@echo ">> waiting a moment to make sure the database comes online.."
@sleep 3
$(COMPOSE) run --rm node \
/usr/local/bin/node $(SEQUELIZE) db:migrate && \
$(COMPOSE) run --rm node \
/usr/local/bin/node $(SEQUELIZE) db:seed:all
watch: migrate ## Run the tests in "watch" mode
# Running with docker-compose since our tests require a database to be
# present
$(COMPOSE) run --rm \
-e NODE_ENV=test \
node \
/usr/local/bin/node $(JEST) $(JEST_ARGS) --watch --coverage=false
watch-compile: ## Run the TypeScript compiler in "watch' mode
$(TSC) -w
run: build ## Run the uplink service first
@echo ">> Make sure you run migrations first!"
@sleep 1
$(COMPOSE) up
.PHONY: all depends build clean check help run watch
# vim: set et