-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
71 lines (53 loc) · 1.64 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
# Always use bash as the shell.
SHELL:=bash
# Enable bash strict mode.
.SHELLFLAGS:=-eu -o pipefail -c
# Delete it's target file if a Make rule fails.
.DELETE_ON_ERROR:
MAKEFLAGS += --no-builtin-rules
DC:=docker compose
SERVICES:=nginx1 nginx2
.PHONY: ps ps-a
ps ps-a: ps%:
@ARGS=; \
[[ "$(strip $(subst -, ,$*))" = "a" ]] && ARGS="$$ARGS --all"; \
$(DC) ps --format 'table {{.ID}}\t{{.Name}}\t{{.Image}}\t{{.Command}}\t{{.Service}}\t{{.RunningFor}}\t{{.State}}' $$ARGS
.PHONY: up up-build
up up-build: up%:
@ARGS=; \
[[ "$(strip $(subst -, ,$*))" = "build" ]] && ARGS="$$ARGS --build"; \
$(DC) up -d $$ARGS
DOWN_PREFIX:=down
DOWN_TARGETS=$(DOWN_PREFIX) $(addprefix $(DOWN_PREFIX)-,15 20 30 60 90)
.PHONY: $(DOWN_TARGETS)
$(DOWN_TARGETS): $(DOWN_PREFIX)%:
@MATCH=$*; \
TIMEOUT="$${MATCH:1}"; \
[[ -n $$TIMEOUT ]] && ARGS="-t $$TIMEOUT"; \
$(DC) down -v $${ARGS:-}
STOP_PREFIX:=stop
STOP_TARGETS:=$(STOP_PREFIX) $(addprefix $(STOP_PREFIX)-,$(SERVICES))
.PHONY: $(STOP_TARGETS)
$(STOP_TARGETS): $(STOP_PREFIX)%:
@MATCH=$*; \
SVC="$${MATCH:1}"; \
$(DC) stop -t 30 $$SVC
.PHONY: build build-nc
build build-nc: build%:
@ARGS=; \
[[ "$(strip $(subst -, ,$*))" = "nc" ]] && ARGS="$$ARGS --no-cache"; \
$(DC) build --progress=plain $$ARGS
SH-PREFIX:=sh-
SH-TARGETS:=$(addprefix $(SH-PREFIX),$(SERVICES))
.PHONY: $(SH-TARGETS)
$(SH-TARGETS): $(SH-PREFIX)%:
@$(DC) exec $* sh
LOG_PREFIX:=logs-4-
LOG_TARGETS:=$(addprefix $(LOG_PREFIX),$(SERVICES))
.PHONY: $(LOG_TARGETS)
$(LOG_TARGETS): $(LOG_PREFIX)%:
@trap "exit 0" INT EXIT SIGTERM; \
$(DC) logs -f $*
.PHONY: kill-containers
kill-containers:
@docker container rm -f $$(docker container ls -aq)