Skip to content

Commit

Permalink
add docker-in-docker to devcontainer
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Sherman <[email protected]>
  • Loading branch information
usingtechnology committed Jul 4, 2023
1 parent a654e64 commit b329283
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
43 changes: 28 additions & 15 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -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"

}
12 changes: 12 additions & 0 deletions .devcontainer/post-install.sh
Original file line number Diff line number Diff line change
@@ -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
20 changes: 19 additions & 1 deletion devcontainer.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b329283

Please sign in to comment.