Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality for building and running agents seprately #2845

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 47 additions & 11 deletions demo/run_demo
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ shopt -s nocasematch

cd $(dirname $0)

AGENT="$1"
shift
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=""
Expand Down Expand Up @@ -107,8 +115,9 @@ do
cat <<EOF

Usage:
./demo_run <agent> [OPTIONS]
./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.
Expand All @@ -128,6 +137,19 @@ EOF
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
Expand Down Expand Up @@ -155,9 +177,18 @@ if [ ! -z "$AGENT_PORT_OVERRIDE" ]; then
AGENT_PORT_RANGE="$AGENT_PORT-$AGENT_PORT_END"
fi

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
# 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
Expand Down Expand Up @@ -263,8 +294,13 @@ 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
--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
12 changes: 12 additions & 0 deletions docs/demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,18 @@ To pass extra arguements to the agent (for example):
DEMO_EXTRA_AGENT_ARGS="[\"--emit-did-peer-2\"]" ./run_demo faber --did-exchange --reuse-connections
```

Additionally, separating the build and run functionalities in the script allows for smoother development and debugging processes. With the mounting of volumes from the host into the Docker container, code changes can be automatically reloaded without the need to repeatedly build the demo.

Build Command:
```bash
./demo/run_demo build alice --wallet-type askar-anoncreds --events
```

Run Command:
```bash
./demo/run_demo run alice --wallet-type askar-anoncreds --events
```

## Learning about the Alice/Faber code

These Alice and Faber scripts (in the `demo/runners` folder) implement the controller and run the agent as a sub-process (see the documentation for `aca-py`). The controller publishes a REST service to receive web hook callbacks from their agent. Note that this architecture, running the agent as a sub-process, is a variation on the documented architecture of running the controller and agent as separate processes/containers.
Expand Down