forked from openwallet-foundation/acapy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_demo
executable file
·255 lines (238 loc) · 7.87 KB
/
run_demo
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#!/bin/bash
shopt -s nocasematch
cd $(dirname $0)
AGENT="$1"
shift
ARGS=""
TRACE_ENABLED=""
TRACE_TAG=acapy.events
if ! [ -z "$TRACE_TARGET_URL" ]; then
TRACE_TARGET=http://${TRACE_TARGET_URL}/
else
TRACE_TARGET=log
fi
WEBHOOK_TARGET=""
if [ -z "$DOCKER_NET" ]; then
DOCKER_NET="bridge"
fi
DOCKER_VOL=""
for i in "$@"
do
if [ ! -z "$SKIP" ]; then
SKIP=""
continue
fi
case $i in
--events)
if [ "${AGENT}" = "performance" ]; then
echo -e "\nIgnoring the \"--events\" option when running the ${AGENT} agent.\n"
else
EVENTS=1
fi
continue
;;
--self-attested)
SELF_ATTESTED=1
continue
;;
--trace-log)
TRACE_ENABLED=1
TRACE_TARGET=log
TRACE_TAG=acapy.events
continue
;;
--trace-http)
TRACE_ENABLED=1
TRACE_TARGET=http://${TRACE_TARGET_URL}/
TRACE_TAG=acapy.events
continue
;;
--webhook-url)
WEBHOOK_TARGET=http://${WEBHOOK_URL}
continue
;;
--debug-ptvsd)
ENABLE_PTVSD=1
continue
;;
--debug-pycharm)
ENABLE_PYDEVD_PYCHARM=1
continue
;;
--debug-pycharm-controller-port)
PYDEVD_PYCHARM_CONTROLLER_PORT=$2
SKIP=1
continue
;;
--debug-pycharm-agent-port)
PYDEVD_PYCHARM_AGENT_PORT=$2
SKIP=1
continue
;;
--timing)
if [ ! -d "../logs" ]; then
mkdir ../logs && chmod -R uga+rws ../logs
fi
if [ "$(ls -ld ../logs | grep dr..r..rwx)" == "" ]; then
echo "Error: To use the --timing parameter, the directory '../logs' must exist and all users must be able to write to it."
echo "For example, to create the directory and then set the permissions use: 'mkdir ../logs; chmod uga+rws ../logs'"
exit 1
fi
DOCKER_VOL="${DOCKER_VOL} -v /$(pwd)/../logs:/home/indy/logs"
continue
;;
--bg)
if [ "${AGENT}" = "alice" ] || [ "${AGENT}" = "faber" ] || [ "${AGENT}" = "acme" ]; then
DOCKER_OPTS="-d"
echo -e "\nRunning in ${AGENT} in the background. Note that you cannot use the command line console in this mode."
echo To see the logs use: \"docker logs ${AGENT}\".
echo While viewing logs, hit CTRL-C to return to the command line.
echo To stop the agent, use: \"docker stop ${AGENT}\". The docker environment will
echo -e "be removed on stop.\n\n"
else
echo The "bg" option \(for running docker in detached mode\) is only for agents Alice, Faber and Acme.
echo Ignoring...
fi
continue
;;
--help)
cat <<EOF
Usage:
./demo_run <agent> [OPTIONS]
- <agent> is one of alice, faber, acme, performance.
- Options:
--events - display on the terminal the webhook events from the ACA-Py agent.
--timing - at the end of the run, display timing; relevant to the "performance" agent.
--bg - run the agent in the background; for use when using OpenAPI/Swagger interface
--trace-log - log trace events to the standard log file
--trace-http - log trace events to an http endpoint specified in env var TRACE_TARGET_URL
--self-attested - include a self-attested attribute in the proof request/response
--webhook-url - send events to an http endpoint specified in env var WEBHOOK_URL
debug options: --debug-pycharm-agent-port <port>; --debug-pycharm-controller-port <port>
--debug-pycharm; --debug-ptvsd
EOF
exit 0
;;
esac
ARGS="${ARGS:+$ARGS }$i"
done
if [ "$AGENT" = "faber" ]; then
AGENT_MODULE="faber"
AGENT_PORT=8020
AGENT_PORT_RANGE=8020-8029
elif [ "$AGENT" = "alice" ]; then
AGENT_MODULE="alice"
AGENT_PORT=8030
AGENT_PORT_RANGE=8030-8039
elif [ "$AGENT" = "acme" ]; then
AGENT_MODULE="acme"
AGENT_PORT=8040
AGENT_PORT_RANGE=8040-8049
elif [ "$AGENT" = "performance" ]; then
AGENT_MODULE="performance"
AGENT_PORT=8050
AGENT_PORT_RANGE=8050-8069
else
echo "Please specify which agent you want to run. Choose from 'faber', 'alice', 'acme', or 'performance'."
exit 1
fi
echo "Preparing agent image..."
docker build -q -t faber-alice-demo -f ../docker/Dockerfile.demo .. || exit 1
if [ ! -z "$DOCKERHOST" ]; then
# provided via APPLICATION_URL environment variable
export RUNMODE="docker"
elif [ -z "${PWD_HOST_FQDN}" ]; then
# getDockerHost; for details refer to https://github.com/bcgov/DITP-DevOps/tree/main/code/snippets#getdockerhost
. /dev/stdin <<<"$(cat <(curl -s --raw https://raw.githubusercontent.com/bcgov/DITP-DevOps/main/code/snippets/getDockerHost))"
export DOCKERHOST=$(getDockerHost)
export RUNMODE="docker"
else
PWD_HOST="${PWD_HOST_FQDN}"
if [ "$PWD_HOST_FQDN" = "labs.play-with-docker.com" ]; then
export ETH_CONFIG="eth1"
elif [ "$PWD_HOST_FQDN" = "play-with-docker.vonx.io" ]; then
export ETH_CONFIG="eth0"
else
export ETH_CONFIG="eth0"
fi
MY_HOST=`ifconfig ${ETH_CONFIG} | grep inet | cut -d':' -f2 | cut -d' ' -f1 | sed 's/\./\-/g'`
export DOCKERHOST="ip${MY_HOST}-${SESSION_ID}-{PORT}.direct.${PWD_HOST_FQDN}"
export RUNMODE="pwd"
fi
# check if ngrok is running on our $AGENT_PORT (don't override if AGENT_ENDPOINT is already set)
if [ -z "$AGENT_ENDPOINT" ] && [ "$RUNMODE" == "docker" ]; then
echo "Trying to detect ngrok service endpoint"
JQ=${JQ:-`which jq`}
if [ -x "$JQ" ]; then
NGROK_ENDPOINT=$(curl --silent localhost:4040/api/tunnels | $JQ -r '.tunnels[0].public_url')
if [ -z "$NGROK_ENDPOINT" ] || [ "$NGROK_ENDPOINT" = "null" ]; then
echo "ngrok not detected for agent endpoint"
else
export AGENT_ENDPOINT=$NGROK_ENDPOINT
echo "Detected ngrok agent endpoint [$AGENT_ENDPOINT]"
fi
else
echo "jq not found"
fi
fi
echo $DOCKERHOST
DOCKER_ENV="-e LOG_LEVEL=${LOG_LEVEL} -e RUNMODE=${RUNMODE} -e DOCKERHOST=${DOCKERHOST}"
if ! [ -z "$AGENT_PORT" ]; then
DOCKER_ENV="${DOCKER_ENV} -e AGENT_PORT=${AGENT_PORT}"
fi
if ! [ -z "$POSTGRES" ]; then
DOCKER_ENV="${DOCKER_ENV} -e POSTGRES=1 -e RUST_BACKTRACE=1"
fi
if ! [ -z "$LEDGER_URL" ]; then
GENESIS_URL="${LEDGER_URL}/genesis"
DOCKER_ENV="${DOCKER_ENV} -e LEDGER_URL=${LEDGER_URL}"
fi
if ! [ -z "$GENESIS_URL" ]; then
DOCKER_ENV="${DOCKER_ENV} -e GENESIS_URL=${GENESIS_URL}"
fi
if ! [ -z "$AGENT_ENDPOINT" ]; then
DOCKER_ENV="${DOCKER_ENV} -e AGENT_ENDPOINT=${AGENT_ENDPOINT}"
fi
if ! [ -z "$EVENTS" ]; then
DOCKER_ENV="${DOCKER_ENV} -e EVENTS=1"
fi
if ! [ -z "$SELF_ATTESTED" ]; then
DOCKER_ENV="${DOCKER_ENV} -e SELF_ATTESTED=${SELF_ATTESTED}"
fi
if ! [ -z "$TRACE_TARGET" ]; then
DOCKER_ENV="${DOCKER_ENV} -e TRACE_TARGET=${TRACE_TARGET}"
DOCKER_ENV="${DOCKER_ENV} -e TRACE_TAG=${TRACE_TAG}"
DOCKER_ENV="${DOCKER_ENV} -e TRACE_ENABLED=${TRACE_ENABLED}"
fi
if ! [ -z "$WEBHOOK_TARGET" ]; then
DOCKER_ENV="${DOCKER_ENV} -e WEBHOOK_TARGET=${WEBHOOK_TARGET}"
fi
# if $TAILS_NETWORK is specified it will override any previously specified $DOCKER_NET
if ! [ -z "$TAILS_NETWORK" ]; then
DOCKER_NET="${TAILS_NETWORK}"
DOCKER_ENV="${DOCKER_ENV} -e TAILS_NETWORK=${TAILS_NETWORK}"
DOCKER_ENV="${DOCKER_ENV} -e TAILS_NGROK_NAME=ngrok-tails-server"
fi
if ! [ -z "$PUBLIC_TAILS_URL" ]; then
DOCKER_ENV="${DOCKER_ENV} -e PUBLIC_TAILS_URL=${PUBLIC_TAILS_URL}"
fi
if ! [ -z "$TAILS_FILE_COUNT" ]; then
DOCKER_ENV="${DOCKER_ENV} -e TAILS_FILE_COUNT=${TAILS_FILE_COUNT}"
fi
if ! [ -z "$ACAPY_ARG_FILE" ]; then
DOCKER_ENV="${DOCKER_ENV} -e ACAPY_ARG_FILE=${ACAPY_ARG_FILE}"
fi
if ! [ -z "${ENABLE_PYDEVD_PYCHARM}" ]; then
DOCKER_ENV="${DOCKER_ENV} -e ENABLE_PYDEVD_PYCHARM=${ENABLE_PYDEVD_PYCHARM} -e PYDEVD_PYCHARM_CONTROLLER_PORT=${PYDEVD_PYCHARM_CONTROLLER_PORT} -e PYDEVD_PYCHARM_AGENT_PORT=${PYDEVD_PYCHARM_AGENT_PORT}"
fi
# on Windows, docker run needs to be prefixed by winpty
if [ "$OSTYPE" = "msys" ]; then
DOCKER="winpty docker"
fi
DOCKER=${DOCKER:-docker}
$DOCKER run --name $AGENT --rm -it ${DOCKER_OPTS} \
--network=${DOCKER_NET} \
-p 0.0.0.0:$AGENT_PORT_RANGE:$AGENT_PORT_RANGE \
${DOCKER_VOL} \
$DOCKER_ENV \
faber-alice-demo $AGENT_MODULE --port $AGENT_PORT $ARGS