Skip to content

Commit

Permalink
Merge pull request #798 from nodlesh/feature-aath-dev-containers
Browse files Browse the repository at this point in the history
AATH Dev Container Support
  • Loading branch information
swcurran authored Apr 26, 2024
2 parents fa24184 + fc03f3e commit 63d7fa3
Show file tree
Hide file tree
Showing 16 changed files with 306 additions and 5 deletions.
51 changes: 51 additions & 0 deletions .devcontainer/AATH-container/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
{
"name": "AATH Test Dev",
// Use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"build": {
// Path is relative to the devcontainer.json file.
"context": "../../aries-test-harness",
"dockerfile": "../../aries-test-harness/Dockerfile.dev-harness"
},

"workspaceMount": "source=${localWorkspaceFolder}/aries-test-harness,target=/aries-test-harness,type=bind",

"workspaceFolder": "/aries-test-harness",
// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"docker-from-docker": "latest"
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

"runArgs": [
"--network=aath_network",
"--name=aath_test_dev"
],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pip install --upgrade pip && \
pip install --no-cache-dir aiohttp behave allure-behave",

// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
"settings": {
"extensions.verifySignature": false
},
"extensions": [
"ms-python.python",
"ms-python.debugpy",
"ms-python.vscode-pylance",
"alexkrechik.cucumberautocomplete",
"zainchen.json"
]
}
},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root"
}
68 changes: 68 additions & 0 deletions .devcontainer/ACA-Py-container/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
{
"name": "ACA-Py Backchannel Dev",
// Use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
//"dockerFile": "../../aries-backchannels/acapy/Dockerfile.dev-acapy-main",
"build": {
// Path is relative to the devcontainer.json file.
"context": "../../aries-backchannels",
"dockerfile": "../../aries-backchannels/acapy/Dockerfile.dev-acapy-main"
},

"workspaceMount": "source=${localWorkspaceFolder}/aries-backchannels/acapy,target=/aries-backchannels/acapy,type=bind",

"mounts": [
{ "source": "${localWorkspaceFolder}/aries-backchannels/python", "target": "/aries-backchannels/python", "type": "bind" },
{ "source": "${localWorkspaceFolder}/aries-backchannels/data", "target": "/aries-backchannels/data", "type": "bind" }
],

"workspaceFolder": "/aries-backchannels/acapy",

// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"docker-from-docker": "latest"
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [9020],

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root",

"runArgs": [
"--network=aath_network",
"--name=acme_agent"
],

"updateContentCommand": "apt-get update && \
apt-get install -y git gnupg2 software-properties-common curl && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys CE7709D068DB5E88 && \
add-apt-repository 'deb https://repo.sovrin.org/sdk/deb bionic stable' && \
apt-get update && \
apt-get install -y libindy libnullpay",

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pip install --upgrade pip && \
pip install -r /aries-backchannels/python/requirements.txt && \
pip install -r /aries-backchannels/acapy/requirements-main.txt && \
chmod +x ./bin/aca-py && \
./bin/aca-py --version > acapy-version.txt && \
mkdir -p /data-mount/ && \
cp /aries-backchannels/acapy/.build/acapy-main.data/plugin-config.yml /data-mount/plugin-config.yml",

// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
"settings": {
"extensions.verifySignature": false
},
"extensions": [
"ms-python.python",
"ms-python.debugpy",
"ms-python.vscode-pylance"
]
}
}
}
44 changes: 44 additions & 0 deletions .devcontainer/AFJ-container/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
{
"name": "AFJ Backchannel Dev",
// Use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"build": {
"context": "../../aries-backchannels",
"dockerFile": "../../aries-backchannels/javascript/Dockerfile.javascript"
},

"workspaceFolder": "/aries-backchannels/javascript",
// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"docker-from-docker": "latest"
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [9020],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "uname -a",

"runArgs": [
"--network=aath_network",
"--name=acme_agent"
],

// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
"settings": {
"extensions.verifySignature": false
},
"extensions": [
"dzannotti.vscode-babel-coloring"
]
}
},


// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root"
}
54 changes: 54 additions & 0 deletions AATH_DEV_CONTAINERS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Working with Dev Containers in AATH<!-- omit in toc -->

## Contents<!-- omit in toc -->
- [Dev Containers in AATH](#dev-containers-in-aath)
- [Getting Started](#getting-started)
- [Dev Container Configuration](#dev-container-configuration)

## Dev Containers in AATH

The Aries Agent Test Harness defines multiple [Dev Containers](https://code.visualstudio.com/docs/devcontainers/tutorial) to aid the test developer and the Backchannel/Controller developer. This allows the developers to write code for these areas without having to install all libraries and configure your local dev machine to write these tests or update an Aries Framework Backchannel.

At the time of writing this document there are three Dev Containers in AATH.
- A Test Development Dev Container
- An ACA-Py Backchannel Development Dev Container
- An Aries Framework Javascript/CREDO-TS Backchannel Dev Container (Dev Container still in development)

## Getting Started

To get started make sure you have installed the [Dev Containers VSCode extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) in VSCode.

Clone the Aries Agent Test Harness repository and open the root folder in VS Code. Once opened, VS Code will detect the available dev containers and prompt you to open them. Selecting this option will display all the dev containers that you can choose from.

![Open Dev Container](docs/assets/images/open_dev_container.png)

The other way to open the Dev Container is to select the `Open a Remote Window` option in the bottom of VSCode.

![Open a Remote Window](docs/assets/images/open_a_remote_window.png)

Then select `Reopen in Container`

![Open a Remote Window](docs/assets/images/reopen_in_container.png)

At the first time of opening a specific Dev Container, the container will be built. If a change is made in any of the dev containers configurations, the dev container will have to be rebuilt. VSCode should sense a change to these files and prompt a rebuild, but if not, or you don't accept the rebuild prompt at the time it appears, a rebuild can be initiated in VSCode within the dev container by clicking on the dev container name in the bottom left corner of VSCode and selecting Rebuild.

## Dev Container Configuration

The dev container json files are located in `.devcontainer\`. This is where enhancements to existing dev containers and adding new dev containers for other Aries Frameworks would take place following the conventions already laid out in that folder.

The dev containers use an existing Dockerfile to build the image. These are not the regular docker files that are build with the AATH manage script. There are specific Dockerfiles for each dev container that are based on those original docker files but needed to be modified to work better with the dev container configurations. The Dockerfiles are named the same as the original files except with `dev` in the name. for example, the `Dockerfile.dev-acapy-main` was based off of `Dockerfile.acapy-main`.

These dev containers are named in Docker to allow for identification and better communications between agents. If you want an agent dev container to represent one of acme, bob, faber, or mallory, make sure the devcontainer.json is changed to name you want the agent to represent.

```
"runArgs": [
"--network=aath_network",
"--name=acme_agent"
],
```

All dev containers are on the `aath_network` in docker which corresponds to the network that the regular agent containers are on when running the manage script. This allows the developer to run tests in a dev container against agents ran by the manage script, along with an agent running in a dev container communicating with other agents ran buy the manage script.




1 change: 1 addition & 0 deletions TEST_DEV_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ See the [README](../aries-agent-test-harness/aries-backchannels/README.md) in th

## Diving Deeper

- [Developing Tests and Backchannels in Dev Containers](AATH_DEV_CONTAINERS.md)
- [Accessing Connection ID in Test Code](ACCESS-CONNECTION-IDS.md)
- [Configuring Tests with Credential Types and Proofs](CONFIGURE-CRED-TYPES.md)
- [Debugging a Backchannel Running Inside a Docker Container](DEBUGGING.md)
Expand Down
33 changes: 33 additions & 0 deletions aries-backchannels/acapy/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File with Arguments",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"args": "${command:pickArgs}"
},
{
"name": "Python: Current File",
"type": "debugpy",
"request": "launch",
//"program": "${file}",
"console": "integratedTerminal",
// "cwd": "${workspaceFolder}",
"module": "acapy_backchannel",
"args" : ["-p", "9020"],
"env": {
"LEDGER_URL": "http://test.bcovrin.vonx.io",
"TAILS_SERVER_URL": "http://tails.bcovrin.vonx.io",
"DOCKERHOST": "acme_agent",
//"ACAPY_LOG_LEVEL": "debug",
//"ACAPY_LOG_FILE": "/aries-backchannels/acapy/acapy.log"
},
},
]
}
15 changes: 15 additions & 0 deletions aries-backchannels/acapy/Dockerfile.dev-acapy-main
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM python:3.9-slim-bullseye

WORKDIR /aries-backchannels

ADD https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 ./jq
RUN chmod +x ./jq


# The Backchannel is looking for it in ./bin, copy a file that invokes the ACA-Py installed script in /usr/local/bin
RUN mkdir -p ./bin
COPY acapy/bin/aca-py ./bin/aca-py

ENV PYTHONPATH=/aries-backchannels
ENV RUNMODE=docker

3 changes: 2 additions & 1 deletion aries-backchannels/acapy/acapy_backchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ def get_agent_args(self):

result.append(("--universal-resolver"))

result.append(("--plugin", "redis_queue.v1_0.events"))
#result.append(("--plugin", "redis_queue.v1_0.events"))
result.append(("--plugin", "redis_events.v1_0.redis_queue.events"))
result.append(("--plugin-config", "/data-mount/plugin-config.yml"))

# This code for log level is included here because aca-py does not support the env var directly yet.
Expand Down
1 change: 1 addition & 0 deletions aries-backchannels/acapy/requirements-main.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
aries-cloudagent[indy, bbs, askar]@git+https://github.com/hyperledger/aries-cloudagent-python@main
git+https://github.com/hyperledger/aries-acapy-plugins@main#subdirectory=redis_events
4 changes: 1 addition & 3 deletions aries-backchannels/python/agent_backchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
import os
import random
import traceback
import debugpy
from dataclasses import dataclass
from typing import Any, Optional, Tuple

import ptvsd
from aiohttp import ClientSession, web
from aiohttp.typedefs import Handler
from typing_extensions import Literal, TypedDict

from .utils import log_msg

ptvsd.enable_attach()

LOGGER = logging.getLogger(__name__)

DEFAULT_POSTGRES = bool(os.getenv("POSTGRES"))
Expand Down
2 changes: 1 addition & 1 deletion aries-backchannels/python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pygments
git+https://github.com/webpy/webpy.git#egg=web.py
python3-indy
pyyaml
ptvsd
debugpy
aiohttp>=3.8.1
ConfigArgParse
typing_extensions
Expand Down
29 changes: 29 additions & 0 deletions aries-test-harness/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": "Python: Behave current file",
"type": "debugpy",
"request": "launch",
"module": "behave",
"console": "integratedTerminal",
"cwd": "/aries-test-harness",
"args": [
"${file}",
"--tags=@T001-RFC0160",
"-k",
"-D",
"Acme=http://acme_agent:9020",
"-D",
"Bob=http://bob_agent:9030",
"-D",
"Faber=http://faber_agent:9040",
"-D",
"Mallory=http://mallory_agent:9050"
]
}
]
}
6 changes: 6 additions & 0 deletions aries-test-harness/Dockerfile.dev-harness
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM python:3.7-buster

RUN \
echo "==> Install stuff not in the requirements..." && \
pip install --no-cache-dir \
aiohttp behave allure-behave
Binary file added docs/assets/images/open_a_remote_window.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/open_dev_container.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/reopen_in_container.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 63d7fa3

Please sign in to comment.