Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test refactor + Docker image CI #154

Merged
merged 7 commits into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Ignore everything
**

# Except proxy.py
!proxy.py
# Except proxy
!proxy
!requirements.txt
!setup.py
!README.md

# Ignore __pycache__ directory
proxy/__pycache__
28 changes: 28 additions & 0 deletions .github/workflows/test-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Proxy.py Docker

on: [push]

jobs:
build:
runs-on: ${{ matrix.os }}
name: Python ${{ matrix.python }} on ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python: [3.7]
max-parallel: 1
fail-fast: false
steps:
- uses: actions/checkout@v1
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python }}-dev
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-testing.txt
- name: Build
run: |
make container
1 change: 1 addition & 0 deletions .github/workflows/test-library.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-testing.txt
- name: Quality Check
run: |
Expand Down
13 changes: 8 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
.coverage*
.coverage
.idea
.vscode
.project
.pydevproject
.settings
.mypy_cache
.hypothesis

coverage.xml
proxy.py.iml
*.pyc
ca-*.pem
https-*.pem

node_modules
venv
cover
htmlcov
dist
build
proxy.py.egg-info
proxy.py.iml
*.pyc
ca-*.pem
https-*.pem
16 changes: 10 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
FROM python:3.7-alpine as base
FROM base as builder

COPY requirements.txt .
RUN pip install --upgrade pip && pip install --install-option="--prefix=/deps" -r requirements.txt
COPY requirements.txt /app/
COPY setup.py /app/
COPY README.md /app/
COPY proxy/ /app/proxy/
WORKDIR /app
RUN pip install --upgrade pip && \
pip install --install-option="--prefix=/deps" .

FROM base

LABEL com.abhinavsingh.name="abhinavsingh/proxy.py" \
com.abhinavsingh.description="⚡⚡⚡ Fast, Lightweight, Programmable Proxy Server in a single Python file" \
com.abhinavsingh.description="⚡⚡⚡Fast, Lightweight, Programmable, TLS interception capable proxy server for Application debugging, testing and development" \
com.abhinavsingh.url="https://github.com/abhinavsingh/proxy.py" \
com.abhinavsingh.vcs-url="https://github.com/abhinavsingh/proxy.py" \
com.abhinavsingh.docker.cmd="docker run -it --rm -p 8899:8899 abhinavsingh/proxy.py"

COPY --from=builder /deps /usr/local
COPY proxy.py /app/
WORKDIR /app

EXPOSE 8899/tcp
ENTRYPOINT [ "./proxy.py" ]
ENTRYPOINT [ "proxy" ]
CMD [ "--hostname=0.0.0.0", \
"--port=8899" ]
93 changes: 47 additions & 46 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,31 @@ CA_KEY_FILE_PATH := ca-key.pem
CA_CERT_FILE_PATH := ca-cert.pem
CA_SIGNING_KEY_FILE_PATH := ca-signing-key.pem

.PHONY: all clean test package test-release release coverage lint autopep8
.PHONY: all clean-lib test-lib package test-release release coverage lint autopep8
.PHONY: container run-container release-container https-certificates ca-certificates
.PHONY: profile dashboard clean-dashboard

all: clean test
all: clean-lib test-lib

clean:
autopep8:
autopep8 --recursive --in-place --aggressive proxy/*.py
autopep8 --recursive --in-place --aggressive proxy/*/*.py
autopep8 --recursive --in-place --aggressive tests/*.py
autopep8 --recursive --in-place --aggressive plugin_examples/*.py
autopep8 --recursive --in-place --aggressive benchmark/*.py
autopep8 --recursive --in-place --aggressive dashboard/*.py
autopep8 --recursive --in-place --aggressive setup.py

ca-certificates:
# Generate CA key
openssl genrsa -out $(CA_KEY_FILE_PATH) 2048
# Generate CA certificate
openssl req -new -x509 -days 3650 -key $(CA_KEY_FILE_PATH) -out $(CA_CERT_FILE_PATH)
# Generate key that will be used to generate domain certificates on the fly
# Generated certificates are then signed with CA certificate / key generated above
openssl genrsa -out $(CA_SIGNING_KEY_FILE_PATH) 2048

clean-lib:
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
Expand All @@ -29,66 +47,49 @@ clean:
rm -rf build
rm -rf proxy.py.egg-info
rm -rf .pytest_cache
rm -rf .hypothesis

test: lint
python -m unittest tests/*.py

package: clean
python setup.py sdist bdist_wheel

test-release: package
twine upload --verbose --repository-url https://test.pypi.org/legacy/ dist/*
clean-dashboard:
rm -rf public/dashboard

release: package
twine upload dist/*
container:
docker build -t $(LATEST_TAG) -t $(IMAGE_TAG) .

coverage:
pytest --cov=proxy --cov-report=html tests/
open htmlcov/index.html

dashboard:
pushd dashboard && npm run build && popd

https-certificates:
# Generate server key
openssl genrsa -out $(HTTPS_KEY_FILE_PATH) 2048
# Generate server certificate
openssl req -new -x509 -days 3650 -key $(HTTPS_KEY_FILE_PATH) -out $(HTTPS_CERT_FILE_PATH)

lint:
flake8 --ignore=W504 --max-line-length=127 proxy/ tests/ benchmark/ plugin_examples/ dashboard/dashboard.py setup.py
mypy --strict --ignore-missing-imports proxy/ tests/ benchmark/ plugin_examples/ dashboard/dashboard.py setup.py

autopep8:
autopep8 --recursive --in-place --aggressive proxy/*.py
autopep8 --recursive --in-place --aggressive proxy/*/*.py
autopep8 --recursive --in-place --aggressive tests/*.py
autopep8 --recursive --in-place --aggressive plugin_examples/*.py
autopep8 --recursive --in-place --aggressive benchmark/*.py
autopep8 --recursive --in-place --aggressive dashboard/*.py
autopep8 --recursive --in-place --aggressive setup.py
package: clean
python setup.py sdist bdist_wheel

container:
docker build -t $(LATEST_TAG) -t $(IMAGE_TAG) .
profile:
sudo py-spy -F -f profile.svg -d 3600 proxy.py

run-container:
docker run -it -p 8899:8899 --rm $(LATEST_TAG)
release: package
twine upload dist/*

release-container:
docker push $(IMAGE_TAG)
docker push $(LATEST_TAG)

https-certificates:
# Generate server key
openssl genrsa -out $(HTTPS_KEY_FILE_PATH) 2048
# Generate server certificate
openssl req -new -x509 -days 3650 -key $(HTTPS_KEY_FILE_PATH) -out $(HTTPS_CERT_FILE_PATH)

ca-certificates:
# Generate CA key
openssl genrsa -out $(CA_KEY_FILE_PATH) 2048
# Generate CA certificate
openssl req -new -x509 -days 3650 -key $(CA_KEY_FILE_PATH) -out $(CA_CERT_FILE_PATH)
# Generate key that will be used to generate domain certificates on the fly
# Generated certificates are then signed with CA certificate / key generated above
openssl genrsa -out $(CA_SIGNING_KEY_FILE_PATH) 2048

profile:
sudo py-spy -F -f profile.svg -d 3600 proxy.py
run-container:
docker run -it -p 8899:8899 --rm $(LATEST_TAG)

dashboard:
pushd dashboard && npm run build && popd
test-lib: lint
python -m unittest discover

clean-dashboard:
rm -rf public/dashboard
test-release: package
twine upload --verbose --repository-url https://test.pypi.org/legacy/ dist/*
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1119,14 +1119,15 @@ Changelog

- `v2.x`
- No longer ~~a single file module~~.
- Added support for threadless execution.
- Added dashboard app.
- `v1.x`
- `Python3` only.
- Deprecated support for ~~Python 2.x~~.
- Added support for multi accept.
- Added support multi core accept.
- Added plugin support.
- `v0.x`
- Single file.
- Single threaded server.

For detailed changelog refer
For detailed changelog refer either to release PRs or commit history.
3 changes: 2 additions & 1 deletion benchmark/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"""
proxy.py
~~~~~~~~
⚡⚡⚡ Fast, Lightweight, Programmable Proxy Server in a single Python file.
⚡⚡⚡Fast, Lightweight, Programmable, TLS interception capable
proxy server for Application debugging, testing and development.

:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
Expand Down
3 changes: 2 additions & 1 deletion dashboard/dashboard.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""
proxy.py
~~~~~~~~
⚡⚡⚡ Fast, Lightweight, Programmable Proxy Server in a single Python file.
⚡⚡⚡Fast, Lightweight, Programmable, TLS interception capable
proxy server for Application debugging, testing and development.

:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
Expand Down
3 changes: 2 additions & 1 deletion dashboard/src/devtools.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
proxy.py
~~~~~~~~
⚡⚡⚡ Fast, Lightweight, Programmable Proxy Server in a single Python file.
⚡⚡⚡ Fast, Lightweight, Programmable, TLS interception capable
proxy server for Application debugging, testing and development.

:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
Expand Down
9 changes: 9 additions & 0 deletions dashboard/src/proxy.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/*
proxy.py
~~~~~~~~
⚡⚡⚡ Fast, Lightweight, Programmable, TLS interception capable
proxy server for Application debugging, testing and development.

:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
*/
#app {
background-color: #eeeeee;
height: 100%;
Expand Down
9 changes: 9 additions & 0 deletions dashboard/src/proxy.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
<!--
proxy.py
~~~~~~~~
⚡⚡⚡ Fast, Lightweight, Programmable, TLS interception capable
proxy server for Application debugging, testing and development.

:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
-->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
Expand Down
3 changes: 2 additions & 1 deletion dashboard/src/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/*
proxy.py
~~~~~~~~
⚡⚡⚡ Fast, Lightweight, Programmable Proxy Server in a single Python file.
⚡⚡⚡ Fast, Lightweight, Programmable, TLS interception capable
proxy server for Application debugging, testing and development.

:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
Expand Down
10 changes: 10 additions & 0 deletions dashboard/test/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
proxy.py
~~~~~~~~
⚡⚡⚡ Fast, Lightweight, Programmable, TLS interception capable
proxy server for Application debugging, testing and development.

:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
*/

import { ProxyDashboard } from "../src/proxy";

describe("test suite", () => {
Expand Down
3 changes: 2 additions & 1 deletion helper/Procfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# proxy.py
# ~~~~~~~~
# ⚡⚡⚡ Fast, Lightweight, Programmable Proxy Server in a single Python file.
# ⚡⚡⚡ Fast, Lightweight, Programmable, TLS interception capable
# proxy server for Application debugging, testing and development.
#
# :copyright: (c) 2013-present by Abhinav Singh and contributors.
# :license: BSD, see LICENSE for more details.
Expand Down
3 changes: 2 additions & 1 deletion helper/chrome_with_proxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

# proxy.py
# ~~~~~~~~
# ⚡⚡⚡ Fast, Lightweight, Programmable Proxy Server in a single Python file.
# ⚡⚡⚡ Fast, Lightweight, Programmable, TLS interception capable
# proxy server for Application debugging, testing and development.
#
# :copyright: (c) 2013-present by Abhinav Singh and contributors.
# :license: BSD, see LICENSE for more details.
Expand Down
3 changes: 2 additions & 1 deletion helper/fluentd.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# proxy.py
# ~~~~~~~~
# ⚡⚡⚡ Fast, Lightweight, Programmable Proxy Server in a single Python file.
# ⚡⚡⚡ Fast, Lightweight, Programmable, TLS interception capable
# proxy server for Application debugging, testing and development.
#
# :copyright: (c) 2013-present by Abhinav Singh and contributors.
# :license: BSD, see LICENSE for more details.
Expand Down
3 changes: 2 additions & 1 deletion helper/monitor_open_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

# proxy.py
# ~~~~~~~~
# ⚡⚡⚡ Fast, Lightweight, Programmable Proxy Server in a single Python file.
# ⚡⚡⚡ Fast, Lightweight, Programmable, TLS interception capable
# proxy server for Application debugging, testing and development.
#
# :copyright: (c) 2013-present by Abhinav Singh and contributors.
# :license: BSD, see LICENSE for more details.
Expand Down
3 changes: 2 additions & 1 deletion plugin_examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"""
proxy.py
~~~~~~~~
⚡⚡⚡ Fast, Lightweight, Programmable Proxy Server in a single Python file.
⚡⚡⚡ Fast, Lightweight, Programmable, TLS interception capable
proxy server for Application debugging, testing and development.

:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
Expand Down
3 changes: 2 additions & 1 deletion plugin_examples/cache_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"""
proxy.py
~~~~~~~~
⚡⚡⚡ Fast, Lightweight, Programmable Proxy Server in a single Python file.
⚡⚡⚡ Fast, Lightweight, Programmable, TLS interception capable
proxy server for Application debugging, testing and development.

:copyright: (c) 2013-present by Abhinav Singh and contributors.
:license: BSD, see LICENSE for more details.
Expand Down
Loading