You've already forked docker-mailserver
mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2025-08-08 23:06:49 +02:00
changes from tomav#1599 without start-mailserver.sh
included all changes from the work on refactoring all scripts, but excluded one big script to make merging easier; replaced mapfile with read
This commit is contained in:
88
Makefile
88
Makefile
@ -1,9 +1,14 @@
|
||||
SHELL = /bin/bash
|
||||
|
||||
NAME = tvial/docker-mailserver:testing
|
||||
VCS_REF := $(shell git rev-parse --short HEAD)
|
||||
VCS_VERSION := $(shell git describe --tags --contains --always)
|
||||
|
||||
SLEEP = 15s
|
||||
|
||||
all: build backup generate-accounts run generate-accounts-after-run fixtures tests clean
|
||||
no-build: backup generate-accounts run generate-accounts-after-run fixtures tests clean
|
||||
complete_test: lint build generate-accounts run generate-accounts-after-run fixtures tests
|
||||
|
||||
build:
|
||||
docker build \
|
||||
@ -12,22 +17,24 @@ build:
|
||||
-t $(NAME) .
|
||||
|
||||
backup:
|
||||
# if backup directories exist, clean hasn't been called, therefore we shouldn't overwrite it. It still contains the original content.
|
||||
@if [ ! -d config.bak ]; then\
|
||||
cp -rp config config.bak; \
|
||||
# if backup directories exist, clean hasn't been called, therefore
|
||||
# we shouldn't overwrite it. It still contains the original content.
|
||||
@ if [ ! -d config.bak ]; then\
|
||||
cp -rp config config.bak;\
|
||||
fi
|
||||
@if [ ! -d testconfig.bak ]; then\
|
||||
cp -rp test/config testconfig.bak ;\
|
||||
@ if [ ! -d testconfig.bak ]; then\
|
||||
cp -rp test/config testconfig.bak;\
|
||||
fi
|
||||
|
||||
generate-accounts:
|
||||
docker run --rm -e MAIL_USER=user1@localhost.localdomain -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' > test/config/postfix-accounts.cf
|
||||
docker run --rm -e MAIL_USER=user2@otherdomain.tld -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' >> test/config/postfix-accounts.cf
|
||||
echo "# this is a test comment, please don't delete me :'(" >> test/config/postfix-accounts.cf
|
||||
echo " # this is also a test comment, :O" >> test/config/postfix-accounts.cf
|
||||
@ docker run --rm -e MAIL_USER=user1@localhost.localdomain -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' > test/config/postfix-accounts.cf
|
||||
@ docker run --rm -e MAIL_USER=user2@otherdomain.tld -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' >> test/config/postfix-accounts.cf
|
||||
@ echo "# this is a test comment, please don't delete me :'(" >> test/config/postfix-accounts.cf
|
||||
@ echo " # this is also a test comment, :O" >> test/config/postfix-accounts.cf
|
||||
|
||||
run:
|
||||
# Run containers
|
||||
# run containers
|
||||
-@ echo "Sleeping $(SLEEP) after each container"
|
||||
docker run --rm -d --name mail \
|
||||
-v "`pwd`/test/config":/tmp/docker-mailserver \
|
||||
-v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \
|
||||
@ -50,14 +57,14 @@ run:
|
||||
-e PERMIT_DOCKER=host \
|
||||
-e DMS_DEBUG=0 \
|
||||
-h mail.my-domain.com -t $(NAME)
|
||||
sleep 15
|
||||
-@ sleep $(SLEEP)
|
||||
docker run --rm -d --name mail_smtponly_without_config \
|
||||
-e SMTP_ONLY=1 \
|
||||
-e ENABLE_LDAP=1 \
|
||||
-e PERMIT_DOCKER=network \
|
||||
-e OVERRIDE_HOSTNAME=mail.mydomain.com \
|
||||
-t $(NAME)
|
||||
sleep 15
|
||||
-@ sleep $(SLEEP)
|
||||
docker run --rm -d --name mail_override_hostname \
|
||||
-v "`pwd`/test/config":/tmp/docker-mailserver \
|
||||
-v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \
|
||||
@ -67,7 +74,7 @@ run:
|
||||
-e OVERRIDE_HOSTNAME=mail.my-domain.com \
|
||||
-h unknown.domain.tld \
|
||||
-t $(NAME)
|
||||
sleep 15
|
||||
-@ sleep $(SLEEP)
|
||||
docker run --rm -d --name mail_domainname \
|
||||
-v "`pwd`/test/config":/tmp/docker-mailserver \
|
||||
-v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \
|
||||
@ -77,7 +84,7 @@ run:
|
||||
-e DOMAINNAME=my-domain.com \
|
||||
-h unknown.domain.tld \
|
||||
-t $(NAME)
|
||||
sleep 15
|
||||
-@ sleep $(SLEEP)
|
||||
docker run --rm -d --name mail_srs_domainname \
|
||||
-v "`pwd`/test/config":/tmp/docker-mailserver \
|
||||
-v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \
|
||||
@ -88,7 +95,7 @@ run:
|
||||
-e DOMAINNAME=my-domain.com \
|
||||
-h unknown.domain.tld \
|
||||
-t $(NAME)
|
||||
sleep 15
|
||||
-@ sleep $(SLEEP)
|
||||
docker run --rm -d --name mail_disabled_clamav_spamassassin \
|
||||
-v "`pwd`/test/config":/tmp/docker-mailserver \
|
||||
-v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \
|
||||
@ -96,19 +103,19 @@ run:
|
||||
-e ENABLE_SPAMASSASSIN=0 \
|
||||
-e DMS_DEBUG=0 \
|
||||
-h mail.my-domain.com -t $(NAME)
|
||||
sleep 15
|
||||
-@ sleep $(SLEEP)
|
||||
|
||||
generate-accounts-after-run:
|
||||
docker run --rm -e MAIL_USER=added@localhost.localdomain -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' >> test/config/postfix-accounts.cf
|
||||
docker exec mail addmailuser pass@localhost.localdomain 'may be \a `p^a.*ssword'
|
||||
|
||||
sleep 10
|
||||
@ docker run --rm -e MAIL_USER=added@localhost.localdomain -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' >> test/config/postfix-accounts.cf
|
||||
@ docker exec mail addmailuser pass@localhost.localdomain 'may be \a `p^a.*ssword'
|
||||
@ sleep $(SLEEP)
|
||||
|
||||
fixtures:
|
||||
# Setup sieve
|
||||
# setup sieve
|
||||
docker cp "`pwd`/test/config/sieve/dovecot.sieve" mail:/var/mail/localhost.localdomain/user1/.dovecot.sieve
|
||||
sleep 30
|
||||
# Sending test mails
|
||||
sleep $(SLEEP)
|
||||
sleep $(SLEEP)
|
||||
# sending test mails
|
||||
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-spam.txt"
|
||||
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-virus.txt"
|
||||
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-alias-external.txt"
|
||||
@ -126,35 +133,44 @@ fixtures:
|
||||
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/non-existing-user.txt"
|
||||
docker exec mail_disabled_clamav_spamassassin /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt"
|
||||
docker exec mail /bin/sh -c "sendmail root < /tmp/docker-mailserver-test/email-templates/root-email.txt"
|
||||
# postfix virtual transport lmtp
|
||||
# postfix virtual transport lmtp
|
||||
docker exec mail_override_hostname /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt"
|
||||
# Wait for mails to be analyzed
|
||||
# wait for mails to be analyzed
|
||||
sleep 80
|
||||
|
||||
tests:
|
||||
# Start tests
|
||||
./test/bats/bin/bats test/*.bats
|
||||
|
||||
.PHONY: ALWAYS_RUN
|
||||
|
||||
test/%.bats: ALWAYS_RUN
|
||||
./test/bats/bin/bats $@
|
||||
|
||||
lint:
|
||||
# List files which name starts with 'Dockerfile'
|
||||
# eg. Dockerfile, Dockerfile.build, etc.
|
||||
git ls-files --exclude='Dockerfile*' --ignored | xargs --max-lines=1 hadolint
|
||||
# List files which name starts with 'Dockerfile'
|
||||
# eg. Dockerfile, Dockerfile.build, etc.
|
||||
-@ git ls-files --exclude='Dockerfile*' --ignored | xargs --max-lines=1 hadolint
|
||||
|
||||
clean:
|
||||
# Remove running and stopped test containers
|
||||
-docker ps -a | grep -E "docker-mailserver:testing|ldap_for_mail" | cut -f 1-1 -d ' ' | xargs --no-run-if-empty docker rm -f
|
||||
|
||||
@if [ -d config.bak ]; then\
|
||||
# remove running and stopped test containers
|
||||
-@ docker ps -a | grep -E "docker-mailserver:testing|ldap_for_mail" | cut -f 1-1 -d ' ' | xargs --no-run-if-empty docker rm -f
|
||||
-@ if [ -d config.bak ]; then\
|
||||
rm -rf config ;\
|
||||
mv config.bak config ;\
|
||||
fi
|
||||
@if [ -d testconfig.bak ]; then\
|
||||
-@ if [ -d testconfig.bak ]; then\
|
||||
sudo rm -rf test/config ;\
|
||||
mv testconfig.bak test/config ;\
|
||||
fi
|
||||
-sudo rm -rf test/onedir test/alias test/quota test/relay test/config/dovecot-lmtp/userdb test/config/key* test/config/opendkim/keys/domain.tld/ test/config/opendkim/keys/example.com/ test/config/opendkim/keys/localdomain2.com/ test/config/postfix-aliases.cf test/config/postfix-receive-access.cf test/config/postfix-receive-access.cfe test/config/dovecot-quotas.cf test/config/postfix-send-access.cf test/config/postfix-send-access.cfe test/config/relay-hosts/chksum test/config/relay-hosts/postfix-aliases.cf test/config/dhparams.pem
|
||||
-@ sudo rm -rf test/onedir test/alias test/quota test/relay test/config/dovecot-lmtp/userdb test/config/key* test/config/opendkim/keys/domain.tld/ test/config/opendkim/keys/example.com/ test/config/opendkim/keys/localdomain2.com/ test/config/postfix-aliases.cf test/config/postfix-receive-access.cf test/config/postfix-receive-access.cfe test/config/dovecot-quotas.cf test/config/postfix-send-access.cf test/config/postfix-send-access.cfe test/config/relay-hosts/chksum test/config/relay-hosts/postfix-aliases.cf test/config/dhparams.pem test/config/dovecot-lmtp/dh.pem test/config/relay-hosts/dovecot-quotas.cf test/config/user-patches.sh
|
||||
|
||||
shellcheck:
|
||||
@ echo -e "Testing shell / bash scripts with shellcheck\n"
|
||||
@ shellcheck --version
|
||||
@ echo ''
|
||||
# currently without `start-mailserver` as this is to be merged separately
|
||||
@ if find -iname "*.sh" -not -path "./test/*" -not -path "./target/docker-configomat/*" -not -wholename ./target/start-mailserver.sh -exec shellcheck -S style -Cauto -e SC2250,SC2154,SC2248 -W 50 {} \; | grep .; then\
|
||||
echo -e "\nError" ;\
|
||||
exit 1 ;\
|
||||
else\
|
||||
echo -e '\nSuccess' ;\
|
||||
fi
|
||||
|
Reference in New Issue
Block a user