-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
103 lines (84 loc) · 2.53 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
91
92
93
94
95
96
97
98
99
100
101
102
103
-include .env
export
DEV_DOMAIN ?= dev.jkldsa.com
DOMAINS ?= epfl.cz dev.jkldsa.com
MKCERT_DOMAINS ?= local
# KEYBASE_USER ?= $(shell /usr/local/bin/keybase whoami)
# CRTDIR ?= /keybase/private/$(KEYBASE_USER)/certbot/etc/live/
CRTDIR ?= /keybase/team/epfl_idevfsd/certs
# The certs that are not found in CRTDIR, will be created with mkcert.
CERTS = $(addprefix certs/,$(DOMAINS)) $(addprefix certs/,$(MKCERT_DOMAINS))
DYNCONFIGS = $(addprefix config/,$(addsuffix .yml,$(DOMAINS)))
DOP ?= $(shell if which -s podman ; then echo "podman" ; else echo "docker" ; fi)
all:
@echo "DOP: $(DOP)"
@echo "DOMAINS: $(DOMAINS)"
@echo "MKCERT_DOMAINS: $(MKCERT_DOMAINS)"
@echo "CRTDIR: $(CRTDIR)"
@echo "CERTS: $(CERTS)"
@echo "DYNCONFIGS: $(DYNCONFIGS)"
.PHONY: up down logs ps network clean
up: $(CERTS) $(DYNCONFIGS) config/traefik.yml podman.yml docker-compose.yml network
ifeq ($(DOP),podman)
podman play kube podman.yml
else
docker compose up -d
endif
down: podman.yml
ifeq ($(DOP),podman)
podman play kube podman.yml --down
else
docker compose down
endif
rm -rf $(CERTS)
logs:
ifeq ($(DOP),docker)
docker compose logs -f
endif
ps:
ifeq ($(DOP),podman)
podman ps
else
docker compose ps
endif
console:
docker compose exec proxy /bin/sh
network:
ifeq ($(DOP),docker)
docker network ls --format "{{.ID}} {{.Name}}" --filter "name=traefik" | grep -q ' traefik$$' || docker network create --subnet=192.168.129.0/24 traefik
endif
clean: down
ifeq ($(DOP),docker)
docker network inspect traefik --format='{{ range $$key, $$value := .Containers}}{{ $$key }} {{ end }}' | xargs docker stop | xargs docker rm
docker network rm traefik
endif
$(CERTS): certs
src=$(CRTDIR)/$(notdir $@);\
echo "src=$$src";\
if keybase fs stat $$src 2>/dev/null | cut -f 2 | grep -q DIR ; then \
if [ -d $@ ] ; then \
echo "Certs dir for $@ is already present. Skipping but this will possibly end up in expired certs";\
else \
echo "CERT: $@ $$src -> certs/";\
echo keybase fs cp -r $$src $(dir $@)/;\
keybase fs cp -r $$src $(dir $@)/;\
fi \
else \
mkdir $@;\
mkcert --cert-file $@/fullchain.pem --key-file $@/privkey.pem "*.$(notdir $@)";\
fi
$(DYNCONFIGS): config
@echo "tls:" > $@
@echo " certificates:" >> $@
@echo " - certFile: /certs/$$(basename $@ .yml)/fullchain.pem" >> $@
@echo " keyFile: /certs/$$(basename $@ .yml)/privkey.pem" >> $@
certs:
mkdir -p $@
config:
mkdir -p $@
podman.yml: podman.yml.erb
erb -T 2 $< >$@
docker-compose.yml: docker-compose.yml.erb
erb -T 2 $< >$@
config/traefik.yml: service.yml.erb
erb -T 2 $< >$@