forked from hyperledger-labs/business-partner-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start-with-tunnels.sh
executable file
·99 lines (83 loc) · 2.5 KB
/
start-with-tunnels.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env bash
# THIS IS FOR TESTING ONLY!
# Script starts ngrok https tunnels defined in ngrok.yml
# Or alternatively diode (when started with --diode)
# and sets the public endpoint as ACA-Py endpoint.
# If ngrok is used, ngrok should be locally installed and an account with ngrok should be setup.
# Options
# - set custom docker compose file with option -f
# - diode mode with -d
DOCKERFILE="docker-compose.yml"
MODE="ngrok"
while getopts "df:" opt; do
echo ${opt}
case ${opt} in
d ) MODE="diode"
;;
f ) DOCKERFILE=$OPTARG
;;
\? )
#print option error
echo "Invalid option: $OPTARG" 1>&2
exit 1
;;
: )
esac
done
# Check if web mode is enabled in .env
eval $(grep -i 'BPA_WEB_MODE' .env)
if [[ "$BPA_WEB_MODE" = "" ]]; then
BPA_WEB_MODE=false
fi
echo "Web Mode: $BPA_WEB_MODE"
if [ "$MODE" = "diode" ]; then
echo "Use diode"
if ! command -v diode &> /dev/null
then
echo "diode could not be found, start "
curl -Ssf https://diode.io/install.sh | sh
fi
diode publish -public 8030:8030 -public 8080:80 >/dev/null 2>&1 &
ACAPY_ENDPOINT=https://$(diode config 2>&1 | awk '/Client address/ { print $5 }').diode.link:8030
BPA_HOST=$(diode config 2>&1 | awk '/Client address/ { print $5 }').diode.link
else
echo "Use ngrok"
NGROK_TUNNELS="acapyendpoint businesspartner"
echo "Starting ngrok..."
if ! command -v ngrok &> /dev/null
then
echo "ngrok could not be found"
exit
fi
# Get public ip
function getTunnels () {
TUNNELS=$(curl --silent http://127.0.0.1:4040/api/tunnels | jq -c .tunnels[])
if [[ "$TUNNELS" == "" ]]; then
sleep 2
getTunnels
fi
}
if ngrok start --config ngrok.yml $NGROK_TUNNELS >/dev/null 2>&1 & then
echo "ngrok started successfully"
getTunnels
for TUNNEL in $TUNNELS
do
TUNNEL_NAME=$( echo $TUNNEL | jq -r .name)
if [[ "$TUNNEL_NAME" == "acapyendpoint" ]]; then
ACAPY_ENDPOINT=$( echo $TUNNEL | jq -r .public_url )
fi
if [[ "$TUNNEL_NAME" == "businesspartner" ]]; then
BPA_HOST=$( echo $TUNNEL | jq -r .public_url | sed 's/.*https:\/\///')
fi
done
else
echo "Could not start ngrok."
fi
fi
# write public ip to env
export BPA_HOST=$BPA_HOST
export ACAPY_ENDPOINT=$ACAPY_ENDPOINT
echo "Business Partner Agent Public URL: https://$BPA_HOST"
echo "Public ACA-PY Endpoint: $ACAPY_ENDPOINT"
# Start agent
docker-compose -f $DOCKERFILE up