-
Notifications
You must be signed in to change notification settings - Fork 526
/
Copy pathrun_demo
executable file
·318 lines (296 loc) · 10.3 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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#!/bin/bash
shopt -s nocasematch
cd $(dirname $0)
RESOLUTION="$1"
# Check if RESOLUTION is not provided or not a valid option
if [ -z "$RESOLUTION" ] || [ "$RESOLUTION" != "build" -a "$RESOLUTION" != "run" ]; then
echo "Resolution not specified or invalid."
AGENT="$1" # If RESOLUTION is not provided or invalid, assume argument is AGENT
else
shift # Shift only if RESOLUTION is provided and valid
AGENT="$1"
fi
shift # Shift again to remove AGENT from the arguments
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=""
# Set default platform to linux/amd64 when running on Arm based MAC since there are no arm based images available currently.
# Must also use the Rosetta 2 software, which can be installed by running `softwareupdate --install-rosetta` from the Mac command line
if [[ $OSTYPE == 'darwin'* ]]; then
architecture=$(uname -m)
if [[ "${architecture}" == 'arm'* ]] || [[ "${architecture}" == 'aarch'* ]]; then
export DOCKER_DEFAULT_PLATFORM=linux/amd64
fi
fi
j=1
for i in "$@"
do
((j++))
# Demo agent with --multitenant requires the ../log dir to exist and write access to it
if [ ! -d "../log" ]; then
mkdir ../log && chmod -R uga+rws ../log
DOCKER_VOL="${DOCKER_VOL} -v /$(pwd)/../log:/home/aries/log"
fi
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=${!j}
SKIP=1
continue
;;
--debug-pycharm-agent-port)
PYDEVD_PYCHARM_AGENT_PORT=${!j}
SKIP=1
continue
;;
--timing)
if [ "$(ls -ld ../log | grep dr..r..rwx)" == "" ]; then
echo "Error: To use the --timing parameter, the directory '../log' 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 ../log; chmod uga+rws ../log'"
exit 1
fi
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 <resolution> <agent> [OPTIONS]
- <resolution> is one of the docker option to build or run.
- <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 [ -z "$RESOLUTION" ]; then
echo "Resolution not specified."
elif [ "$RESOLUTION" = "build" ]; then
DOCKER_RESOLUTION="build"
echo "Agent will be build."
elif [ "$RESOLUTION" = "run" ]; then
DOCKER_RESOLUTION="run"
echo "Agent will be run."
else
echo "You can utilize the 'build' option to build the agent or the 'run' option to run the agent."
fi
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
# allow override for agent ports
if [ ! -z "$AGENT_PORT_OVERRIDE" ]; then
AGENT_PORT=$AGENT_PORT_OVERRIDE
AGENT_PORT_END=$(expr $AGENT_PORT_OVERRIDE + 9)
AGENT_PORT_RANGE="$AGENT_PORT-$AGENT_PORT_END"
fi
# 1. Build the agent image
if [ -z "$DOCKER_RESOLUTION" ] || [ "$DOCKER_RESOLUTION" = "build" ]; then
echo "Preparing agent image..."
docker build -t acapy-base -f ../docker/Dockerfile .. || exit 1
docker build -t faber-alice-demo -f ../docker/Dockerfile.demo --build-arg from_image=acapy-base .. || exit 1
fi
if [ "$DOCKER_RESOLUTION" = "build" ]; then
exit 1
else
echo "You can utilize the 'build' option to build the agent or the 'run' option to run the agent."
fi
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=$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 ! [ -z "$ACAPY_DEBUG_WEBHOOKS" ]; then
DOCKER_ENV="${DOCKER_ENV} -e ACAPY_DEBUG_WEBHOOKS=${ACAPY_DEBUG_WEBHOOKS}"
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 "$DEMO_EXTRA_AGENT_ARGS" ]; then
DOCKER_ENV="${DOCKER_ENV} -e DEMO_EXTRA_AGENT_ARGS=${DEMO_EXTRA_AGENT_ARGS}"
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
echo "DOCKER_ENV=$DOCKER_ENV"
# 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} \
$(if [ "$DOCKER_RESOLUTION" = "run" ]; then
echo "-v $(pwd)/../aries_cloudagent:/home/aries/aries_cloudagent \
-v $(pwd)/../scripts:/home/aries/scripts \
-v $(pwd)/../demo:/home/aries/demo"
fi) \
$DOCKER_ENV \
faber-alice-demo $AGENT_MODULE --port $AGENT_PORT $ARGS