-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
93 lines (74 loc) · 3.14 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
# Mailz, lots of mailz
# General notes.
#
# The start of all containers is always done after regenerating all
# configurations, this is done in a dedicated temporary container:
# 'sync', which parses config.ini, and exports generated
# configurations to the mails/data/confs directory. Configurations
# files are then mounted read-only in all containers.
CONFIG ?= config.ini
# Here we attempt to resolve the privkey/cert path from config.ini so
# we can mount them in the 'sync' container. This is required so the
# 'sync' script can decide wether or not we need to regenerate
# certicates.
SYNC_PRIVKEY = $(shell awk -F '=' '// { if ($$1 == "privkey") { print $$2; } }' < $(CONFIG))
SYNC_CERT = $(shell awk -F '=' '// { if ($$1 == "cert") { print $$2; } }' < $(CONFIG))
ifneq ($(SYNC_PRIVKEY),)
EXTRA_VOLUMES += -v $(shell readlink -f $(SYNC_PRIVKEY)):/privkey.pem
endif
ifneq ($(SYNC_CERT),)
EXTRA_VOLUMES += -v $(shell readlink -f $(SYNC_CERT)):/cert.pem
endif
# We attempt to extract the backup directory specified in the
# configuration file, if none, use a default one.
BACKUP = $(shell awk -F '=' '// { if ($$1 == "backup") { print $$2; } }' < $(CONFIG))
ifeq ($(BACKUP),)
BACKUP=mailz/backups
endif
# Enough for the trickeries.
help:
@echo "Mailz, lots of mailz."
@echo ""
@echo "All configuration is done via config.ini, enjoy."
@echo ""
@echo "spawn sync configuration and respawn all containers"
@echo "logs print containers logs"
@echo "backup backup mail data"
@echo "stop stop all containers"
@echo "encrypt encrypt a password"
@echo "status show status of containers"
@echo "help print this help"
@echo ""
spawn: sync
# we need to explicitely stop here because we want the regenerate configuration to be taken into account
docker-compose -f mailz/data/confs/docker-compose.yml -p mailz build
docker-compose -f mailz/data/confs/docker-compose.yml -p mailz stop
docker-compose -f mailz/data/confs/docker-compose.yml -p mailz up -d
sync:
docker build -t mailz_sync mailz/dockerfiles/sync
docker run \
-v $(shell pwd)/mailz/data/confs:/confs \
-v $(shell pwd)/$(CONFIG):/config.ini \
-v $(shell pwd)/mailz/templates:/templates \
$(EXTRA_VOLUMES) \
-e DEFAULT_HOSTNAME=$(shell hostname -f) \
-e DATA_DIR=$(shell pwd)/mailz/data/ \
-e CONF_DIR=$(shell pwd)/mailz/data/confs/ \
--rm --name mailz_sync_run mailz_sync
encrypt:
docker build -t mailz_crypt mailz/dockerfiles/crypt
docker run \
-i -t --rm --name mailz_crupt_run mailz_crypt
stop:
docker-compose -f mailz/data/confs/docker-compose.yml -p mailz stop
logs:
docker-compose -f mailz/data/confs/docker-compose.yml -p mailz logs
status:
docker-compose -f mailz/data/confs/docker-compose.yml -p mailz ps
backup:
docker-compose -f mailz/data/confs/docker-compose.yml -p mailz stop
mkdir -p $(BACKUP)
# hack to be root without using sudo, we need this because permissions of some files have special rights.
docker run --rm -v $(shell pwd)/mailz/data:/data alpine tar -zcf - /data > $(BACKUP)/docker-mailz-backup-$(shell date +%s).tar.gz
docker-compose -f mailz/data/confs/docker-compose.yml -p mailz up -d
.PHONY: all sync spawn logs backup stop encrypt status