-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathdocker-test.sh
executable file
·64 lines (52 loc) · 1.57 KB
/
docker-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
#!/bin/bash
set -euo pipefail
NETWORK_NAME=mqtt-ts
MOSQUITTO_IMAGE=eclipse-mosquitto:2
MOSQUITTO_NAME=mosquitto
DENO_IMAGE=denoland/deno
SUBSCRIBER_NAME=subscriber
if ! docker network inspect $NETWORK_NAME &> /dev/null; then
printf "creating docker network $NETWORK_NAME\n"
docker network create $NETWORK_NAME
fi
if ! docker container inspect $MOSQUITTO_NAME &> /dev/null; then
printf "starting $MOSQUITTO_NAME\n"
docker run -d --rm \
--name $MOSQUITTO_NAME \
--net $NETWORK_NAME \
-v $PWD/mosquitto-docker.conf:/mosquitto/config/mosquitto.conf \
$MOSQUITTO_IMAGE
fi
# Give mosquitto time to start:
sleep 1
printf "\npublishing with mosquitto_pub:\n\n"
docker exec $MOSQUITTO_NAME mosquitto_pub -t foo/bar -m baz -d
if ! docker container inspect $SUBSCRIBER_NAME &> /dev/null; then
printf "\nstarting $SUBSCRIBER_NAME\n"
docker run -d --rm \
--name $SUBSCRIBER_NAME \
--net $NETWORK_NAME \
-v $PWD:/mqtt.ts \
-v $PWD/cache:/deno-dir \
$DENO_IMAGE \
run --allow-net \
/mqtt.ts/tools/sub.ts -u mqtt://$MOSQUITTO_NAME -L debug -t "foo/#" -v
fi
function cleanup {
printf "\nstopping containers\n\n"
docker stop $MOSQUITTO_NAME
docker stop $SUBSCRIBER_NAME
}
trap cleanup EXIT
# Give subscriber time to connect and subscribe:
sleep 1
printf "\nrunning publisher:\n\n"
docker run -it --rm \
--net $NETWORK_NAME \
-v $PWD:/mqtt.ts \
-v $PWD/cache:/deno-dir \
$DENO_IMAGE \
run --allow-net \
/mqtt.ts/tools/pub.ts -u mqtt://$MOSQUITTO_NAME -L debug -t "foo/bar" -m "baz"
printf "\nsubscriber logs:\n\n"
docker logs $SUBSCRIBER_NAME