Skip to content

Commit

Permalink
fix dothttp docker agent (#140)
Browse files Browse the repository at this point in the history
* 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](Pylons/waitress@v2.1.1...v2.1.2)

---
updated-dependencies:
- dependency-name: waitress
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

* 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>
  • Loading branch information
cedric05 and dependabot[bot] authored Jun 10, 2022
1 parent f1c1f03 commit bebd0cc
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
67 changes: 46 additions & 21 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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"
}
// 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"
}
}
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ dist
.git
.devcontainer
.github
venv
venv
benchmarks
examples
test
36 changes: 19 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
# 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
1 change: 1 addition & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- agent
tags:
- v*

Expand Down
19 changes: 19 additions & 0 deletions AGENT.md
Original file line number Diff line number Diff line change
@@ -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
```
13 changes: 10 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "*"
Expand Down
20 changes: 10 additions & 10 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions dotextensions/server/agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .server import HttpServer
server = HttpServer()
app = server.app
8 changes: 4 additions & 4 deletions dotextensions/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion dothttp/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.0.41a3'
__version__ = '0.0.41a4'

0 comments on commit bebd0cc

Please sign in to comment.