2020-09-05 14:19:12 +00:00
|
|
|
|
SHELL = /bin/bash
|
|
|
|
|
|
2021-02-18 09:29:34 +00:00
|
|
|
|
NAME ?= mailserver-testing:ci
|
|
|
|
|
VCS_REF = $(shell git rev-parse --short HEAD)
|
|
|
|
|
VCS_VER = $(shell git describe --tags --contains --always)
|
2015-10-18 19:02:46 +00:00
|
|
|
|
|
2021-02-18 09:29:34 +00:00
|
|
|
|
HADOLINT_VERSION = 1.19.0
|
|
|
|
|
SHELLCHECK_VERSION = 0.7.1
|
|
|
|
|
ECLINT_VERSION = 2.3.1
|
|
|
|
|
|
|
|
|
|
export CDIR = $(shell pwd)
|
2021-01-16 09:16:05 +00:00
|
|
|
|
|
|
|
|
|
# –––––––––––––––––––––––––––––––––––––––––––––––
|
|
|
|
|
# ––– Generic Build Targets –––––––––––––––––––––
|
|
|
|
|
# –––––––––––––––––––––––––––––––––––––––––––––––
|
|
|
|
|
|
|
|
|
|
all: lint build backup generate-accounts tests clean
|
2016-04-13 19:43:25 +00:00
|
|
|
|
|
2015-10-18 19:02:46 +00:00
|
|
|
|
build:
|
2021-01-16 09:16:05 +00:00
|
|
|
|
docker build -t $(NAME) . --build-arg VCS_VER=$(VCS_VER) --build-arg VCS_REF=$(VCS_REF)
|
2015-10-18 19:02:46 +00:00
|
|
|
|
|
2018-03-21 18:55:41 +00:00
|
|
|
|
backup:
|
2020-09-05 14:19:12 +00:00
|
|
|
|
# if backup directories exist, clean hasn't been called, therefore
|
|
|
|
|
# we shouldn't overwrite it. It still contains the original content.
|
2021-01-16 09:16:05 +00:00
|
|
|
|
-@ [[ ! -d config.bak ]] && cp -rp config config.bak || :
|
|
|
|
|
-@ [[ ! -d testconfig.bak ]] && cp -rp test/config testconfig.bak || :
|
|
|
|
|
|
|
|
|
|
clean:
|
|
|
|
|
# remove running and stopped test containers
|
|
|
|
|
-@ [[ -d config.bak ]] && { rm -rf config ; mv config.bak config ; } || :
|
|
|
|
|
-@ [[ -d testconfig.bak ]] && { sudo rm -rf test/config ; mv testconfig.bak test/config ; } || :
|
2021-01-18 19:51:56 +00:00
|
|
|
|
-@ docker ps -a | grep -E "mail|ldap_for_mail|mail_overri.*" | cut -f 1-1 -d ' ' | xargs --no-run-if-empty docker rm -f
|
2021-01-16 09:16:05 +00:00
|
|
|
|
-@ 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 test/alias/config/postfix-virtual.cf test/quota/config/dovecot-quotas.cf test/quota/config/postfix-accounts.cf test/relay/config/postfix-relaymap.cf test/relay/config/postfix-sasl-password.cf test/duplicate_configs/
|
|
|
|
|
|
|
|
|
|
# –––––––––––––––––––––––––––––––––––––––––––––––
|
|
|
|
|
# ––– Tests –––––––––––––––––––––––––––––––––––––
|
|
|
|
|
# –––––––––––––––––––––––––––––––––––––––––––––––
|
2018-03-21 18:55:41 +00:00
|
|
|
|
|
2016-04-25 14:00:39 +00:00
|
|
|
|
generate-accounts:
|
2020-09-05 14:19:12 +00:00
|
|
|
|
@ 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
|
2021-02-07 18:02:09 +00:00
|
|
|
|
@ docker run --rm -e MAIL_USER=user3@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)|userdb_mail=mbox:~/mail:INBOX=~/inbox"' >> test/config/postfix-accounts.cf
|
2020-09-05 14:19:12 +00:00
|
|
|
|
@ 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
|
2016-08-21 20:13:13 +00:00
|
|
|
|
|
2015-10-18 19:02:46 +00:00
|
|
|
|
tests:
|
2021-02-18 09:40:35 +00:00
|
|
|
|
@ NAME=$(NAME) ./test/bats/bin/bats test/*.bats
|
2019-08-07 00:24:56 +00:00
|
|
|
|
|
|
|
|
|
.PHONY: ALWAYS_RUN
|
|
|
|
|
test/%.bats: ALWAYS_RUN
|
2021-01-16 09:16:05 +00:00
|
|
|
|
@ ./test/bats/bin/bats $@
|
2020-09-05 14:19:12 +00:00
|
|
|
|
|
2020-10-04 17:34:15 +00:00
|
|
|
|
lint: eclint hadolint shellcheck
|
|
|
|
|
|
|
|
|
|
hadolint:
|
|
|
|
|
@ ./test/linting/lint.sh hadolint
|
|
|
|
|
|
2020-09-05 14:19:12 +00:00
|
|
|
|
shellcheck:
|
2020-10-04 17:34:15 +00:00
|
|
|
|
@ ./test/linting/lint.sh shellcheck
|
2020-09-24 12:54:21 +00:00
|
|
|
|
|
|
|
|
|
eclint:
|
2020-10-04 17:34:15 +00:00
|
|
|
|
@ ./test/linting/lint.sh eclint
|
2021-01-16 09:16:05 +00:00
|
|
|
|
|
|
|
|
|
install_linters:
|
2021-02-23 10:03:14 +00:00
|
|
|
|
@ mkdir -p tools
|
|
|
|
|
@ curl -S -L \
|
|
|
|
|
"https://github.com/hadolint/hadolint/releases/download/v$(HADOLINT_VERSION)/hadolint-$(shell uname -s)-$(shell uname -m)" -o tools/hadolint
|
|
|
|
|
@ curl -S -L \
|
2021-01-16 09:16:05 +00:00
|
|
|
|
"https://github.com/koalaman/shellcheck/releases/download/v$(SHELLCHECK_VERSION)/shellcheck-v$(SHELLCHECK_VERSION).linux.x86_64.tar.xz" | tar -xJ
|
2021-02-23 10:03:14 +00:00
|
|
|
|
@ curl -S -L \
|
2021-01-16 09:16:05 +00:00
|
|
|
|
"https://github.com/editorconfig-checker/editorconfig-checker/releases/download/$(ECLINT_VERSION)/ec-linux-amd64.tar.gz" | tar -xaz
|
2021-02-23 10:03:14 +00:00
|
|
|
|
@ chmod +rx tools/hadolint
|
|
|
|
|
@ mv "shellcheck-v$(SHELLCHECK_VERSION)/shellcheck" tools/
|
|
|
|
|
@ mv bin/ec-linux-amd64 tools/eclint
|
|
|
|
|
@ chmod +x tools/eclint
|
|
|
|
|
@ rm -rf "shellcheck-v$(SHELLCHECK_VERSION)" bin
|