-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
test.sh
executable file
·78 lines (60 loc) · 1.91 KB
/
test.sh
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
#!/bin/sh
set -e
cleanup_mailer=0
cleanup_mailhog=0
cleanup_docker=0
cleanup_network=0
cleanup() {
set +e
if [ "$cleanup_mailer" -ne 0 ]; then
echo "Logs mailer"
docker logs mailer
echo "Stopping mailer Docker image"
docker stop mailer
docker rm -f mailer
fi
if [ "$cleanup_mailhog" -ne 0 ]; then
echo "Logs mailhog"
docker logs mailhog
echo "Stopping mailhog Docker image"
docker stop mailhog
docker rm -f mailhog
fi
if [ "$cleanup_docker" -ne 0 ]; then
echo "Logs"
docker logs test
echo "Stopping Docker image"
docker stop test
docker rm -f test
fi
if [ "$cleanup_network" -ne 0 ]; then
echo "Removing Docker network"
docker network rm testnet
fi
}
trap cleanup EXIT
echo "Creating Docker network"
time docker network create testnet
cleanup_network=1
echo "Preparing"
apk add --no-cache jq
export MAILNAME=test
export MY_NETWORKS="$(docker network inspect testnet | jq -r '.[0].IPAM.Config[0].Subnet') 127.0.0.0/8"
echo "Running Docker image"
docker run -d --name test --network testnet -e MAILNAME -e MY_NETWORKS -e LOG_TO_STDOUT=1 "${CI_REGISTRY_IMAGE}:${TAG}"
cleanup_docker=1
echo "Running mailhog Docker image"
docker run -d --name mailhog --network testnet -p 8025:8025 mailhog/mailhog:v1.0.1 -hostname mailhog -smtp-bind-addr :25
cleanup_mailhog=1
echo "Running mailer Docker image"
docker run -d --name mailer --network testnet -e LOG_TO_STDOUT=1 -e REMOTES=test registry.gitlab.com/tozd/docker/mailer:ubuntu-jammy
cleanup_mailer=1
echo "Sleeping"
sleep 20
echo "Testing"
# We inside mailer container use sendmail to send an e-mail to mailhog.
# Mailer container first sends it to test container which then in turn sends it to mailhog.
/bin/echo -e "Subject: test\nTo: test@mailhog" | docker exec -i mailer sendmail -t
sleep 10
wget -q -O - http://docker:8025/api/v2/messages | jq -r .items[0].Raw.To[0] | grep -F test@mailhog
echo "Success"