From bebd0cc86f8147810d2e6c8b055c63abbaf3efe2 Mon Sep 17 00:00:00 2001 From: Prasanth Date: Fri, 10 Jun 2022 17:48:55 +0530 Subject: [PATCH] fix dothttp docker agent (#140) * Bump waitress from 2.1.1 to 2.1.2 Bumps [waitress](https://github.com/Pylons/waitress) from 2.1.1 to 2.1.2. - [Release notes](https://github.com/Pylons/waitress/releases) - [Changelog](https://github.com/Pylons/waitress/blob/v2.1.2/CHANGES.txt) - [Commits](https://github.com/Pylons/waitress/compare/v2.1.1...v2.1.2) --- updated-dependencies: - dependency-name: waitress dependency-type: direct:production ... Signed-off-by: dependabot[bot] * feature(agent): quick run agent via docker and python * chore: fix doc && test suite * name docker container Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .devcontainer/Dockerfile | 2 +- .devcontainer/devcontainer.json | 67 +++++++++++++++++++--------- .dockerignore | 5 ++- .github/workflows/ci.yml | 36 ++++++++------- .github/workflows/docker-publish.yml | 1 + AGENT.md | 19 ++++++++ Dockerfile | 13 ++++-- Pipfile | 2 +- Pipfile.lock | 20 ++++----- dotextensions/server/agent.py | 3 ++ dotextensions/server/server.py | 8 ++-- dothttp/__version__.py | 2 +- 12 files changed, 119 insertions(+), 59 deletions(-) create mode 100644 AGENT.md create mode 100644 dotextensions/server/agent.py diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 4d2a35b..df076bb 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,3 +1,3 @@ -ARG VARIANT="3" +ARG VARIANT="3.10-bullseye" FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT} RUN pip install pipenv \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 861521a..0ec7d9c 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,32 +1,57 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.236.0/containers/python-3 { "name": "Python 3", "build": { "dockerfile": "Dockerfile", "context": "..", "args": { - "VARIANT": "3.9", + // Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6 + // Append -bullseye or -buster to pin to an OS version. + // Use -bullseye variants on local on arm64/Apple Silicon. + "VARIANT": "3.10-bullseye", + // Options + "NODE_VERSION": "lts/*" } }, - "settings": { - "terminal.integrated.shell.linux": "/bin/bash", - "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" + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Set *default* container specific settings.json values on container create. + "settings": { + "python.defaultInterpreterPath": "/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" + }, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "ms-python.python", + "ms-python.vscode-pylance" + ] + } }, - "extensions": [ - "ms-python.python" - ], - "postCreateCommand": "pipenv install --system --deploy", - "remoteUser": "vscode" -} \ No newline at end of file + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "pip3 install --user -r requirements.txt", + + // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode", + "features": { + "docker-in-docker": "latest" + } +} diff --git a/.dockerignore b/.dockerignore index 3095c8c..1356daf 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,4 +4,7 @@ dist .git .devcontainer .github -venv \ No newline at end of file +venv +benchmarks +examples +test \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ca351ef..9c639d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,20 +25,22 @@ jobs: pip install -r all_requirements.txt - name: Run tests run: python -m unittest - - name: Run benchmark - run: pytest benchmarks/__main__.py --benchmark-json output.json - - name: Download previous benchmark data - uses: actions/cache@v1 - with: - path: ./cache - key: ${{ runner.os }}-benchmark - - name: Store benchmark result - uses: rhysd/github-action-benchmark@v1 - with: - name: Python Benchmark with pytest-benchmark - tool: 'pytest' - output-file-path: output.json - alert-threshold: '150%' - fail-on-alert: true - github-token: ${{ secrets.PERSONAL_GITHUB_TOKEN }} - comment-on-alert: true \ No newline at end of file +# benchmark is not working for long time. +# TODO + # - name: Run benchmark + # run: pytest benchmarks/__main__.py --benchmark-json output.json + # - name: Download previous benchmark data + # uses: actions/cache@v1 + # with: + # path: ./cache + # key: ${{ runner.os }}-benchmark + # - name: Store benchmark result + # uses: rhysd/github-action-benchmark@v1 + # with: + # name: Python Benchmark with pytest-benchmark + # tool: 'pytest' + # output-file-path: output.json + # alert-threshold: '150%' + # fail-on-alert: true + # github-token: ${{ secrets.PERSONAL_GITHUB_TOKEN }} + # comment-on-alert: true \ No newline at end of file diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 1202377..63bda20 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -4,6 +4,7 @@ on: push: branches: - main + - agent tags: - v* diff --git a/AGENT.md b/AGENT.md new file mode 100644 index 0000000..850a23a --- /dev/null +++ b/AGENT.md @@ -0,0 +1,19 @@ +## Dothttp agent docs + +There is support for running http notebooks on `https://vscode.dev` with dothttp-agent. For running requests in notebook, vscode service will invoke api via `localhost:5000`. With this, one reviewing requets or quickly making requets is far easier. + +### RUN +To run agent via docker + +```shell +docker run --restart always -d -p 5000:5000 --name dothttpagent ghcr.io/cedric05/dothttp/dothttp:agent +``` + +To run with python + +```shell +# install dependencies +python -m pip install dothttp-req --pre waitress flask flask-cors +# run flask app +python -m waitress --port 5000 dotextensions.server.agent:app +``` \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index bbb1cc1..b8800b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,13 @@ FROM python:3.10 LABEL io.whalebrew.config.networks '["host"]' -RUN pip install dothttp-req --pre -RUN pip install flask flask-cors +ADD requirements.txt /app/ +WORKDIR /app +RUN pip install -r requirements.txt +COPY dothttp /app/dothttp +COPY dotextensions /app/dotextensions +COPY setup.py README.md /app/ +RUN ls && python setup.py install +RUN pip install flask flask-cors waitress ENTRYPOINT ["python"] -CMD ["-m dotextensions.server http"] +CMD ["-m", "waitress", "--port", "5000", "dotextensions.server.agent:app"] +EXPOSE 5000 diff --git a/Pipfile b/Pipfile index 5f12ff4..eb7c795 100644 --- a/Pipfile +++ b/Pipfile @@ -21,7 +21,7 @@ pyinstaller = "*" autopep8 = "*" ipython = "*" pywin32-ctypes = { version = "*", os_name = "=='nt'" } -waitress = "==2.1.1" +waitress = "==2.1.2" Flask = "*" pyperf = "==2.2.0" pytest-benchmark = "*" diff --git a/Pipfile.lock b/Pipfile.lock index b03f68e..a97bde1 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "b1cb3722688bc487de5658ebcafbadee16530d8d9c2dd5039056581057bc7b01" + "sha256": "c490ff258f800a424e1e34aceb1cd6dddfa0f63627924ac8ea239778a9679bfa" }, "pipfile-spec": 6, "requires": { @@ -619,11 +619,11 @@ }, "pyinstaller-hooks-contrib": { "hashes": [ - "sha256:90a05207ceea2f8c166f12c3add46e24c0ed6a78234e5f99320f8683d56e0dec", - "sha256:d0ff4c13eda0104db6eb43c60641c19cdf2bc2d6a2a1f0855d26629c3dacc8b7" + "sha256:9dc611cf6667301e95384b4a0631b032bbffa16a0688f4cfa014d0c1e751d276", + "sha256:e38bf9266c57be19647762ee63b012683beb6919c6bc2ecdc66ca174edec44a0" ], "markers": "python_version >= '3.7'", - "version": "==2022.5" + "version": "==2022.6" }, "pyparsing": { "hashes": [ @@ -706,19 +706,19 @@ }, "traitlets": { "hashes": [ - "sha256:70815ecb20ec619d1af28910ade523383be13754283aef90528eb3d47b77c5db", - "sha256:f44b708d33d98b0addb40c29d148a761f44af740603a8fd0e2f8b5b27cf0f087" + "sha256:1530d04badddc6a73d50b7ee34667d4b96914da352109117b4280cb56523a51b", + "sha256:74803a1baa59af70f023671d86d5c7a834c931186df26d50d362ee6a1ff021fd" ], "markers": "python_version >= '3.7'", - "version": "==5.2.1.post0" + "version": "==5.2.2.post1" }, "waitress": { "hashes": [ - "sha256:c549f5b2b4afd44d9d97d7cec79f3ef581e25d832827f415dc175327af674aa8", - "sha256:e2e60576cf14a1539da79f7b7ee1e79a71e64f366a0b47db54a15e971f57bb16" + "sha256:7500c9625927c8ec60f54377d590f67b30c8e70ef4b8894214ac6e4cad233d2a", + "sha256:780a4082c5fbc0fde6a2fcfe5e26e6efc1e8f425730863c04085769781f51eba" ], "index": "pypi", - "version": "==2.1.1" + "version": "==2.1.2" }, "wcwidth": { "hashes": [ diff --git a/dotextensions/server/agent.py b/dotextensions/server/agent.py new file mode 100644 index 0000000..a85d09e --- /dev/null +++ b/dotextensions/server/agent.py @@ -0,0 +1,3 @@ +from .server import HttpServer +server = HttpServer() +app = server.app \ No newline at end of file diff --git a/dotextensions/server/server.py b/dotextensions/server/server.py index 5436e33..ed2f848 100644 --- a/dotextensions/server/server.py +++ b/dotextensions/server/server.py @@ -55,14 +55,14 @@ class HttpServer(Base): def __init__(self, port=5000): from flask import Flask from flask_cors import CORS - app = CORS(Flask("dothttp-server")) + app = Flask("dothttp-server") + CORS(app) self.app = app self.port = port + for handler in handlers.keys(): + self.app.route(handler, methods=["POST"])(self.get_handler(handler)) def run_forever(self): - for handler in handlers.keys(): - api = self.get_handler(handler) - api = self.app.route(handler, methods=["POST"])(api) self.app.run("localhost", self.port) def get_handler(self, handler): diff --git a/dothttp/__version__.py b/dothttp/__version__.py index c1d0374..8adbfcc 100644 --- a/dothttp/__version__.py +++ b/dothttp/__version__.py @@ -1 +1 @@ -__version__ = '0.0.41a3' +__version__ = '0.0.41a4'