-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
90 lines (72 loc) · 2.15 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
REGISTRY = docker.io
USERNAME = expelledboy
NAME = $(shell basename $(CURDIR))
IMAGE = $(REGISTRY)/$(USERNAME)/$(NAME)
.EXPORT_ALL_VARIABLES:
.DEFAULT: help
## ==
.PHONY: help build lint unit test clean
help: ## Print help messages
@sed -n 's/^\([a-zA-Z_-]*\):.*## \(.*\)$$/\1 -- \2/p' Makefile
build: ## Build docker image
docker build -t $(IMAGE) .
test: ## Run simple unit test
docker run -d --rm \
--name $(NAME) \
-v $(PWD):/webhooks/ \
-p 3000:3000 \
$(IMAGE)
sleep 5
-curl http://localhost:3000/help
docker stop $(NAME)
# ==
.PHONY: dev
dev:
npm run dev
# ==
.PHONY: on-tag bump publish
on-tag:
@git describe --exact-match --tags $$(git log -n1 --pretty='%h')
bump: IMPACT = patch
bump:
npm version $(IMPACT)
publish: VERSION = $(shell git describe --always | tr -d v)
publish: MINOR = $(shell echo $(VERSION) | sed -n 's/^\(.\..\).*/\1/p')
publish: on-tag build ## Push docker image to $(REGISTRY)
docker tag $(IMAGE):latest $(IMAGE):$(VERSION)
docker tag $(IMAGE):latest $(IMAGE):$(MINOR)
docker push $(IMAGE):$(VERSION)
docker push $(IMAGE):$(MINOR)
docker rmi $(IMAGE):$(VERSION)
docker rmi $(IMAGE):$(MINOR)
docker push $(IMAGE):latest
# ==
.PHONY: web intro start-webhooks hello-world crash run-webhook
intro:
@cat ./docs/welcome.md
web: ## Run webhooks interactively in docker.
docker run -it --rm \
--name $(NAME) \
--volume $(PWD):/webhooks \
--publish 80:3000 \
expelledboy/make-webhooks
start-webhooks: env-HOSTNAME ## Deploy as service into docker swarm with traefik.
docker service create \
--name make-webhooks \
--mode global \
--network web \
--mount src="$(PWD)",target=/webhooks,type=bind \
--mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \
--label traefik.enable=true \
--label traefik.docker.network=web \
--label traefik.port=3000 \
--label traefik.frontend.rule=Host:$(HOSTNAME) \
$(IMAGE)
hello-world: GREET ?= "World"
hello-world: ## Example target using environment variables.
@echo "Hello, $(GREET)!"
crash: ## Target that always fails.
exit 10
run-webhook: HOOK = hello-world
run-webhook: ## Run webhook from Makefile and fail on error
curl -fs http://localhost/$(HOOK)