diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 0f02e5455..000000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - // 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: FastAPI", - "type": "python", - "request": "launch", - "module": "uvicorn", - "args": [ - "main:app", - ], - "jinja": true - } - ] -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 6935f5542..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "git.alwaysSignOff": true, - "python.testing.pytestArgs": [ - "." - ], - "python.testing.unittestEnabled": false, - "python.testing.pytestEnabled": true, - "sqltools.connections": [ - { - "previewLimit": 50, - "server": "localhost", - "port": 5432, - "driver": "PostgreSQL", - "name": "docker-traction", - "username": "postgres", - "password": "postgresPass", - "database": "traction" - } - ], - "python.analysis.extraPaths": ["./plugins", "./services"] -} \ No newline at end of file diff --git a/README.md b/README.md index a4be51ead..7d7e8dcc6 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,32 @@ If you would like to contribute to Traction, please review the following: - [Code of Conduct](./CODE_OF_CONDUCT.md) - [Compliance](./COMPLIANCE.yaml) +## Developers: devcontainers +To aid in developers, there are 2 `devcontainers`: [plugins](./plugins/.devcontainer/devcontainer.json) and [tenant-ui](./services/tenant-ui/.devcontainer/devcontainer.json). + +The devcontainers and associated vscode launch files are for convenience only, they are not mandatory for developing and debugging. Please feel free to develop anyway you choose. + +1. In VS code, open `plugins`. +2. Follow all prompts to open the devcontainer. +3. In a second VS Code window, open `services/tenant-ui` +4. Follow all prompts to open the devcontainer. +5. in `plugins`, start up the ACA-Py / Traction instance: Run and Debug view, "Run/Debug Plugin", start/F5 +6. in `services/tenant-ui`, start up the backend api: Run and Debug view, "backend - run dev", start/F5 +7. in `services/tenant-ui`, start up the frontend api: Run and Debug view, "frontend - run dev", start/F5 +8. in `services/tenant-ui`, load a Chrome browser for debugging frontend: Run and Debug view, "frontend - chrome", start/F5 + +If all starts up without a hitch, then you should be able to breakpoint the tenant-ui frontend (Vue/Chrome), tenant-ui backend api (Node.js) and traction plugins (Python) for local debugging. + +Out of the box, the above will use the following ports: + +- ACA-Py/Traction Plugins: 3000, 3001 (admin) +- Tenant Proxy: 8032 +- Traction DB: 5432 +- Tenant UI backend server: 8080 +- Tenant UI frontend server: 5173 + +Note that Tenant Proxy and Traction DB are startec via docker compose when starting ACA-Py/Traction Plugins + ### Repository workflow Currently authorized users can create a branch and run a pull request to merge in changes. Unauthorized can always create a fork. diff --git a/plugins/.devcontainer/Dockerfile b/plugins/.devcontainer/Dockerfile new file mode 100644 index 000000000..df0d9dfde --- /dev/null +++ b/plugins/.devcontainer/Dockerfile @@ -0,0 +1,7 @@ +# 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} + +# Poetry +ARG POETRY_VERSION="none" +RUN if [ "${POETRY_VERSION}" != "none" ]; then su vscode -c "umask 0002 && pip3 install poetry==${POETRY_VERSION}"; fi diff --git a/plugins/.devcontainer/devcontainer.json b/plugins/.devcontainer/devcontainer.json new file mode 100644 index 000000000..bc90cf9bd --- /dev/null +++ b/plugins/.devcontainer/devcontainer.json @@ -0,0 +1,71 @@ +{ + "name": "traction_plugins", + "build": { + "dockerfile": "Dockerfile", + "context": "..", + "args": { + "VARIANT": "3.9-bullseye", + "POETRY_VERSION": "1.4.2" + } + }, + "customizations": { + "vscode": { + "settings": { + "python.pythonPath": "/usr/local/bin/python", + "python.linting.enabled": true, + "python.linting.pylintEnabled": true, + "python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8", + "python.formatting.blackPath": "/usr/local/py-utils/bin/black", + "python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf", + "python.linting.banditPath": "/usr/local/py-utils/bin/bandit", + "python.linting.flake8Path": "/usr/local/py-utils/bin/flake8", + "python.linting.mypyPath": "/usr/local/py-utils/bin/mypy", + "python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle", + "python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle", + "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint", + "python.testing.pytestArgs": [ + ".", + "--no-cov" + ], + "python.testing.unittestEnabled": false, + "python.testing.pytestEnabled": true, + "python.testing.pytestPath": "pytest", + "editor.defaultFormatter": null, + "editor.formatOnSave": false, // enable per language + "[python]": { + "editor.formatOnSave": true + }, + "python.formatting.provider": "black", + "python.formatting.blackArgs": [], + "python.venvFolders": ["~.cache/virtualenvs"] + }, + "extensions": [ + "ms-python.python", + "ms-python.pylint", + "ms-python.vscode-pylance" + ] + } + }, + + "features": { + "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {} + }, + + // 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": ["source=${localWorkspaceFolder}/demo/configs,target=/configs,type=bind,consistency=cached"], + // Use 'forwardPorts' to make a list of ports inside the container available locally. + + "forwardPorts": [ + 3000,3001,3002, + 8032 + ], + + "postCreateCommand": "bash ./.devcontainer/post-install.sh" + +} diff --git a/plugins/.devcontainer/post-install.sh b/plugins/.devcontainer/post-install.sh new file mode 100644 index 000000000..5f9215c8a --- /dev/null +++ b/plugins/.devcontainer/post-install.sh @@ -0,0 +1,28 @@ +#!/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 + +# Change some Poetry settings to better deal with working in a container +poetry config cache-dir ${WORKSPACE_DIR}/.cache +poetry config virtualenvs.in-project true +# Now install all dependencies +poetry install + +export PATH=${PATH}:${WORKSPACE_DIR}/.venv/bin + +# add all the requirements to the default python +poetry export --without-hashes --format=requirements.txt > requirements.txt +pip install -r requirements.txt + +# install black for formatting +pip3 install black + +# cleanup +rm poetry.lock +rm requirements.txt diff --git a/plugins/.gitignore b/plugins/.gitignore new file mode 100644 index 000000000..7c4ce200a --- /dev/null +++ b/plugins/.gitignore @@ -0,0 +1,3 @@ +.cache +.venv +poetry.lock \ No newline at end of file diff --git a/plugins/.vscode/launch.json b/plugins/.vscode/launch.json new file mode 100644 index 000000000..545e7b84f --- /dev/null +++ b/plugins/.vscode/launch.json @@ -0,0 +1,23 @@ +{ + // 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": "Run/Debug Plugin", + "type": "python", + "request": "launch", + "preLaunchTask": "docker-compose-start", + "module": "poetry", + "justMyCode": false, + "args": [ + "run", + "python", + "-m", + "aries_cloudagent", + "start", + "--arg-file=${workspaceRoot}/demo/configs/devcontainer.yml" + ] + }] +} \ No newline at end of file diff --git a/plugins/.vscode/tasks.json b/plugins/.vscode/tasks.json new file mode 100644 index 000000000..d474af2d2 --- /dev/null +++ b/plugins/.vscode/tasks.json @@ -0,0 +1,23 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "docker-compose-start", + "type": "shell", + "command": "docker compose -f ${workspaceRoot}/demo/docker-compose.devcontainer.yml up --build -d", + "isBackground": true, + "problemMatcher": [ + { + "pattern": [{ "regexp": ".", "file": 1, "location": 2, "message": 3, }], + "background": { + "activeOnStart": true, + "beginsPattern": "^Container demo-tenant-proxy-1$", + "endsPattern": "^Container demo-traction-db-1$", + } + }, + ] + }, + ] +} \ No newline at end of file diff --git a/plugins/demo/configs/devcontainer.yml b/plugins/demo/configs/devcontainer.yml new file mode 100644 index 000000000..bd08cfb9f --- /dev/null +++ b/plugins/demo/configs/devcontainer.yml @@ -0,0 +1,83 @@ +label: acapy-traction-plugins + +# Admin +admin: [0.0.0.0, 3001] +admin-insecure-mode: false +admin-api-key: change-me +jwt-secret: change-me + + +# Transport +inbound-transport: + - [http, 0.0.0.0, 3000] + - [ws, 0.0.0.0, 3002] +outbound-transport: http +endpoint: + - http://host.docker.internal:3000 + +# webhook: http://host.docker.internal:3000 + +# enable-undelivered-queue: true + +# plugins +plugin: + - aries_cloudagent.messaging.jsonld + - traction_innkeeper.v1_0 + - basicmessage_storage.v1_0 + - connection_update.v1_0 + - multitenant_provider.v1_0 + +# block-plugin: + + +plugin-config-value: + # - multitenant_provider.manager.class_name="traction_plugins.multitenant_provider.v1_0.manager.BasicMultitokenMultitenantManager" + - multitenant_provider.manager.class_name="multitenant_provider.v1_0.manager.AskarMultitokenMultitenantManager" + - multitenant_provider.manager.always_check_provided_wallet_key=true + - multitenant_provider.errors.on_unneeded_wallet_key=false + - multitenant_provider.token_expiry.units=days + - multitenant_provider.token_expiry.amount=1 + - traction_innkeeper.innkeeper_wallet.tenant_id=innkeeper + - traction_innkeeper.innkeeper_wallet.wallet_name=traction_innkeeper + - traction_innkeeper.innkeeper_wallet.wallet_key=change-me + - traction_innkeeper.innkeeper_wallet.print_key=true + - traction_innkeeper.innkeeper_wallet.print_token=true + - traction_innkeeper.reservation.expiry_minutes=2880 + +# invite: true +# invite-label: ACA-Py (Traction Plugins) + +#config +genesis-url: http://test.bcovrin.vonx.io/genesis + +# wallet-type: indy +wallet-type: askar +wallet-name: traction-wallet +wallet-key: 'insecure-change-me' +wallet-storage-type: postgres_storage +wallet-storage-config: '{"url":"host.docker.internal:5432","max_connections":5,"wallet_scheme":"DatabasePerWallet"}' +wallet-storage-creds: '{"account":"postgres","password":"postgresPass","admin_account":"postgres","admin_password":"postgresPass"}' +multitenancy-config: '{"wallet-type":"askar-profile","wallet-name":"askar-wallet"}' + +log-level: info + +multitenant: true +multitenant-admin: true + +emit-new-didcomm-prefix: true +emit-new-didcomm-mime-type: true + +auto-accept-invites: true +auto-accept-requests: true +auto-respond-messages: false +auto-respond-credential-proposal: true +auto-respond-credential-offer: true +auto-respond-credential-request: true +auto-respond-presentation-proposal: true +auto-respond-presentation-request: true +auto-store-credential: true +auto-verify-presentation: true +auto-ping-connection: true +auto-provision: true +monitor-ping: true +public-invites: true \ No newline at end of file diff --git a/plugins/demo/docker-compose.devcontainer.yml b/plugins/demo/docker-compose.devcontainer.yml new file mode 100644 index 000000000..e81b0fa74 --- /dev/null +++ b/plugins/demo/docker-compose.devcontainer.yml @@ -0,0 +1,31 @@ +version: "3.9" +services: + traction-db: + image: "postgres:12" + environment: + - POSTGRES_PASSWORD=postgresPass + ports: + - 5432:5432 + volumes: + - traction-wallet:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 10s + timeout: 5s + retries: 5 + + tenant-proxy: + build: + context: .. + dockerfile: ./docker/Dockerfile.tenant-proxy + restart: unless-stopped + environment: + - ACAPY_ADMIN_URL=http://host.docker.internal:3001 + - ACAPY_ADMIN_URL_API_KEY=change-me + ports: + - 8032:8080 + extra_hosts: + - host.docker.internal:host-gateway + +volumes: + traction-wallet: \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/services/tenant-ui/.devcontainer/devcontainer.json similarity index 77% rename from .devcontainer/devcontainer.json rename to services/tenant-ui/.devcontainer/devcontainer.json index 61b20c4af..de8a912c6 100644 --- a/.devcontainer/devcontainer.json +++ b/services/tenant-ui/.devcontainer/devcontainer.json @@ -1,22 +1,30 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the -// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node { - "name": "Node.js & TypeScript", + "name": "tenant-ui", // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile "image": "mcr.microsoft.com/devcontainers/typescript-node:0-20", "features": { "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {}, "ghcr.io/devcontainers-contrib/features/vue-cli:2": {} }, + "customizations": { + "vscode": { + "extensions": [ + "Vue.volar", + "esbenp.prettier-vscode" + ] + } + }, // 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": [], + "forwardPorts": [ + 8080 + ], // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "yarn install", + "postCreateCommand": "bash ./.devcontainer/post-install.sh" // Configure tool-specific properties. // "customizations": {}, diff --git a/services/tenant-ui/.devcontainer/post-install.sh b/services/tenant-ui/.devcontainer/post-install.sh new file mode 100644 index 000000000..85798cead --- /dev/null +++ b/services/tenant-ui/.devcontainer/post-install.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -ex + +# Convenience workspace directory for later use +WORKSPACE_DIR=$(pwd) +# this might be too slow for each start up? +rm -rf dist && rm -rf node_modules && rm -rf frontend/dist && rm -rf frontend/node_modules +npm install && npm cache clean --force && npm install -g typescript && cd frontend && npm install && npm cache clean --force && cd .. && npm run build \ No newline at end of file diff --git a/services/tenant-ui/.gitignore b/services/tenant-ui/.gitignore index 964f8c4c2..764fef953 100644 --- a/services/tenant-ui/.gitignore +++ b/services/tenant-ui/.gitignore @@ -6,6 +6,7 @@ !.vscode/* .vscode/* !.vscode/extensions.json +!.vscode/launch.json !.vscode/settings.json .idea config/local.json diff --git a/services/tenant-ui/.vscode/launch.json b/services/tenant-ui/.vscode/launch.json new file mode 100644 index 000000000..e377e1d13 --- /dev/null +++ b/services/tenant-ui/.vscode/launch.json @@ -0,0 +1,47 @@ +{ + // 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": "backend - run dev", + "request": "launch", + "runtimeArgs": [ + "run-script", + "dev" + ], + "runtimeExecutable": "npm", + "skipFiles": [], + "type": "node", + "env": {} + }, + { + "name": "frontend - run dev", + "request": "launch", + "cwd":"${workspaceFolder}/frontend", + "runtimeArgs": [ + "run-script", + "dev" + ], + "runtimeExecutable": "npm", + "skipFiles": [], + "type": "node", + "env": {} + }, + { + "name": "frontend - chrome", + "type": "chrome", + "request": "launch", + "url": "http://localhost:5173/", + "webRoot": "${workspaceFolder}/frontend", + "breakOnLoad": true, + "sourceMapPathOverrides": { + "webpack:///./src/*": "${webRoot}/*" + } + }, + + + + ] +}