-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
100 lines (85 loc) · 3.54 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
IMAGE_TAG ?= docker-mailserver
TEST_ADDR ?= mailserver
# All: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6
PLATFORM ?= linux/amd64
ACTION ?= load
PROGRESS_MODE ?= plain
ACME_DOMAIN = emails.mail-server.intranet
DKIM_DOMAIN = mail-server.intranet
.PHONY: docker-build docker-test run-test cleanup-test test
all: docker-build docker-test
docker-build:
# https://github.com/docker/buildx#building
docker buildx build \
--build-arg VCS_REF="$(shell git rev-parse HEAD)" \
--build-arg BUILD_DATE="$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")" \
--tag $(IMAGE_TAG) \
--progress $(PROGRESS_MODE) \
--platform $(PLATFORM) \
--pull \
--$(ACTION) \
./docker
docker-test: test
test: setup-test run-test cleanup-test
setup: setup-test
check-env:
$(eval TEMP_DIR ?= $(shell cat /tmp/current-temp-env))
if [ -z "$(TEMP_DIR)" ]; then echo 'Missing TEMP_DIR env !'; exit 1; fi
run-test: check-env
# Run phpunit test suite
IMAGE_TAG="${IMAGE_TAG}" \
$(TEMP_DIR)/dockerl -f $(TEMP_DIR)/tests/php/docker-compose.yml up --exit-code-from=sut --abort-on-container-exit
cleanup-test: check-env
@echo "Stopping and removing the container"
IMAGE_TAG="${IMAGE_TAG}" \
$(TEMP_DIR)/dockerl down
sudo rm -rf $(TEMP_DIR)
rm -v /tmp/current-temp-env
create-temp-env:
mktemp -d -t desportes_infra_tests.XXXXXX > /tmp/current-temp-env
setup-test-files: check-env
set -eu
cp -rv docker-compose.yml dockerl config.toml docker internal-dns $(TEMP_DIR)
cp tests/.env.test1 $(TEMP_DIR)/.env
rm -vf tests/data/acme.sh/*/*.csr
rm -vf tests/data/acme.sh/*/*.cer
rm -vf tests/data/acme.sh/*/ca.*
mkdir $(TEMP_DIR)/tests
mkdir -p $(TEMP_DIR)/tests/data/acme.sh/$(ACME_DOMAIN)
mkdir -p $(TEMP_DIR)/tests/data/maildata
mkdir $(TEMP_DIR)/tests/data/maildata/queue $(TEMP_DIR)/tests/data/maildata/reports $(TEMP_DIR)/tests/data/maildata/data $(TEMP_DIR)/tests/data/maildata/data/blobs
cp tests/make-certs.sh $(TEMP_DIR)/tests/
cp -rp tests/php $(TEMP_DIR)/tests/
cp -rp tests/seeding $(TEMP_DIR)/tests/
cp -v tests/data/acme.sh/$(ACME_DOMAIN)/*.*nf $(TEMP_DIR)/tests/data/acme.sh/$(ACME_DOMAIN)
# Generate opendkim keys
mkdir -p $(TEMP_DIR)/tests/data/mailconfig/opendkim/keys/$(DKIM_DOMAIN)/
openssl genrsa -out $(TEMP_DIR)/tests/data/mailconfig/opendkim/keys/$(DKIM_DOMAIN)/mail.private 2048
openssl rsa -in $(TEMP_DIR)/tests/data/mailconfig/opendkim/keys/$(DKIM_DOMAIN)/mail.private -pubout -out $(TEMP_DIR)/tests/data/mailconfig/opendkim/keys/$(DKIM_DOMAIN)/mail.txt
cp -rp scripts $(TEMP_DIR)
chmod 777 -R $(TEMP_DIR)/tests/data/acme.sh
$(TEMP_DIR)/tests/make-certs.sh
# rxrxrx
chmod 555 -R $(TEMP_DIR)/tests/data/acme.sh
@cd $(TEMP_DIR)
@echo "Running in $(PWD)"
mkdir -p $(TEMP_DIR)/tests/data/phpldapadmin
openssl req -nodes -x509 -newkey rsa:4096 -keyout $(TEMP_DIR)/tests/data/phpldapadmin/phpldapadmin-certificate.key \
-out $(TEMP_DIR)/tests/data/phpldapadmin/phpldapadmin-certificate.crt -days 15 \
-subj "/C=FR/O=Wdes SAS/OU=Test/CN=phpldapadmin/emailAddress=williamdes@wdes.fr"
setup-test: create-temp-env check-env setup-test-files
set -eu
# Build images
$(TEMP_DIR)/dockerl build
# Build images
$(TEMP_DIR)/dockerl pull
# Bring down just in case
$(TEMP_DIR)/dockerl down || echo 'maybe already down'
# Bring up
$(TEMP_DIR)/dockerl up -d --remove-orphans || $(TEMP_DIR)/dockerl up -d --remove-orphans
# Sleep 10 sec
@sleep 10
# Seed ldap test users
$(TEMP_DIR)/tests/seeding/seed-ldap.sh
# Build phpunit test suite
$(TEMP_DIR)/dockerl -f $(TEMP_DIR)/tests/php/docker-compose.yml build