From b329283ab78a6debb78baf94ada5f284f69d6ae1 Mon Sep 17 00:00:00 2001 From: Jason Sherman Date: Tue, 4 Jul 2023 12:48:30 -0700 Subject: [PATCH] add docker-in-docker to devcontainer Signed-off-by: Jason Sherman --- .devcontainer/Dockerfile | 5 ++++ .devcontainer/devcontainer.json | 43 +++++++++++++++++++++------------ .devcontainer/post-install.sh | 12 +++++++++ devcontainer.md | 20 ++++++++++++++- 4 files changed, 64 insertions(+), 16 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/post-install.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000000..f1650dcb21 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,5 @@ +# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.134.0/containers/python-3/.devcontainer/base.Dockerfile +ARG VARIANT="3.9" +FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT} + +# if we need to enhance this image we can do it in this dockerfile or the post-install.sh script diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 6a1acc4a81..549fa49a4b 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,18 +2,13 @@ // README at: https://github.com/devcontainers/templates/tree/main/src/python { "name": "aries_cloudagent", - // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "mcr.microsoft.com/devcontainers/python:0-3.9-buster", - // Features to add to the dev container. More info: https://containers.dev/features. - // "features": {}, - // Use 'forwardPorts' to make a list of ports inside the container available locally. - "forwardPorts": [ - 9060, - 9061 - ], - // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "python -m pip install --upgrade pip && pip3 install -r requirements.txt -r requirements.askar.txt -r requirements.bbs.txt -r requirements.dev.txt -r requirements.indy.txt && pip3 install black", - // Configure tool-specific properties. + "build": { + "dockerfile": "Dockerfile", + "context": "..", + "args": { + "VARIANT": "3.9-buster" + } + }, "customizations": { "vscode": { "extensions": [ @@ -38,7 +33,25 @@ "python.formatting.blackArgs": [] } } - } - // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. - // "remoteUser": "root" + }, + + "features": { + "docker-in-docker": "latest", + }, + + // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode", + + "remoteEnv": { + //"PATH": "${containerEnv:PATH}:${workspaceRoot}/.venv/bin" + }, + + "mounts": [], + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [ + 9060, + 9061 + ], + "postCreateCommand": "bash ./.devcontainer/post-install.sh" + } \ No newline at end of file diff --git a/.devcontainer/post-install.sh b/.devcontainer/post-install.sh new file mode 100644 index 0000000000..28a32368da --- /dev/null +++ b/.devcontainer/post-install.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -ex + +# Convenience workspace directory for later use +WORKSPACE_DIR=$(pwd) + +# install all ACA-Py requirements +python -m pip install --upgrade pip +pip3 install -r requirements.txt -r requirements.askar.txt -r requirements.bbs.txt -r requirements.dev.txt -r requirements.indy.txt + +# install black for formatting +pip3 install black \ No newline at end of file diff --git a/devcontainer.md b/devcontainer.md index 51f6d6d13e..d3aed89483 100644 --- a/devcontainer.md +++ b/devcontainer.md @@ -10,7 +10,25 @@ By no means is ACA-Py limited to these tools; they are merely examples. The primary use case for this `devcontainer` is for developing, debugging and unit testing (pytest) the [aries_cloudagent](./aries_cloudagent) source code. -There are limitations running this devcontainer, such as not being able to select the docker network. Also, we are not expecting developers to run the [demos](./demo) or other docker based scripts within this container. +There are limitations running this devcontainer, such as all networking is within this container. This container has [docker-in-docker](https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/docker-in-docker.md) which allows running demos, building docker images, running `docker compose` all within this container. + +### Files +The `.devcontainer` folder contains the `devcontainer.json` file which defines this container. We are using a `Dockerfile` and `post-install.sh` to build and configure the container run image. The `Dockerfile` is simple but in place for simplifying image enhancements (ex. adding `poetry` to the image). The `post-install.sh` will install all the ACA-Py requirements and any additional steps (ex. adding additional development libraries). + +### Running docker-in-docker demos +The following is an example of running the demos in this container using a local [von-network](https://github.com/bcgov/von-network/tree/main). You will have to connect to the local von-network using `host.docker.internal` not `localhost`. + +Assumes von-network is running outside of VS Code and this container at the default port (9000). + +```sh +# open a terminal in VS Code... +cd demo +LEDGER_URL=http://host.docker.internal:9000 ./run_demo faber +# open a second terminal in VS Code... +cd demo +LEDGER_URL=http://host.docker.internal:9000 ./run_demo alice +# follow the script... +``` ## Further Reading and Links