Skip to content

Commit

Permalink
update docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
Germey committed Feb 19, 2020
1 parent d4fca11 commit 162542e
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 8 deletions.
131 changes: 131 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Created by .ignore support plugin (hsz.mobi)
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM python:3.6
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
CMD ["supervisord", "-c", "supervisord.conf"]
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
# ProxyPool

![](https://img.shields.io/badge/python-3.6%2B-brightgreen)

Welcome to ProxyPool.

## Requirements

* Docker
Below is a list of requirements for ProxyPool.

* Docker
* Docker-Compose

or

* Python: >=3.6
* Redis
* Environment: Virtual Env

## Run with Docker

Expand Down Expand Up @@ -70,7 +76,9 @@ python3 run.py --processor tester
python3 run.py --processor server
```

### Usage
## Usage

After running the ProxyPool, you can visit
[http://localhost:5555/random](http://localhost:5555/) to access random proxy.
[http://localhost:5555/random](http://localhost:5555/) to access random proxy.

Just enjoy it.
18 changes: 18 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '3'
services:
redis:
image: redis:alpine
container_name: redis
command: redis-server
ports:
- "6379:6379"
restart: always
proxypool:
build: .
image: 'germey/proxypool'
container_name: proxypool
ports:
- "5555:5555"
restart: always
environment:
REDIS_HOST: redis
9 changes: 9 additions & 0 deletions proxypool/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def run_tester(self, cycle=CYCLE_TESTER):
"""
run tester
"""
if not ENABLE_TESTER:
logger.info('tester not enabled, exit')
return
tester = Tester()
loop = 0
while True:
Expand All @@ -35,6 +38,9 @@ def run_getter(self, cycle=CYCLE_GETTER):
"""
run getter
"""
if not ENABLE_GETTER:
logger.info('getter not enabled, exit')
return
getter = Getter()
loop = 0
while True:
Expand All @@ -47,6 +53,9 @@ def run_server(self):
"""
run server for api
"""
if not ENABLE_SERVER:
logger.info('server not enabled, exit')
return
app.run(host=API_HOST, port=API_PORT, threaded=API_THREADED)

def run(self):
Expand Down
8 changes: 5 additions & 3 deletions proxypool/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from environs import Env
from loguru import logger

from proxypool.utils.parse import parse_redis_connection_string


env = Env()
env.read_env()
Expand All @@ -29,10 +31,10 @@
# redis password, if no password, set it to None
REDIS_PASSWORD = env.str('REDIS_PASSWORD', None)
# redis connection string, like redis://[password]@host:port or rediss://[password]@host:port
# REDIS_CONNECTION_STRING = env.str('REDIS_CONNECTION_STRING', None)
REDIS_CONNECTION_STRING = env.str('REDIS_CONNECTION_STRING', None)

# if REDIS_CONNECTION_STRING:
# REDIS_HOST, REDIS_PORT, REDIS_PASSWORD = parse_redis_connection_string(REDIS_CONNECTION_STRING)
if REDIS_CONNECTION_STRING:
REDIS_HOST, REDIS_PORT, REDIS_PASSWORD = parse_redis_connection_string(REDIS_CONNECTION_STRING)

# redis hash table key name
REDIS_KEY = env.str('REDIS_KEY', 'proxies:universal')
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ requests==2.22.0
loguru==0.3.2
pyquery==1.4.0
attr==0.3.1
supervisor==4.1.0
redis==2.10.6
1 change: 0 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
parser = argparse.ArgumentParser(description='ProxyPool')
parser.add_argument('--processor', type=str, help='processor to run')
args = parser.parse_args()
print('args', args)

if __name__ == '__main__':
# if processor set, just run it
Expand Down
17 changes: 17 additions & 0 deletions supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[supervisord]
nodaemon=true

[program:tester]
process_name=tester
command=python3 run.py --processor tester
directory=/app

[program:getter]
process_name=getter
command=python3 run.py --processor getter
directory=/app

[program:server]
process_name=server
command=python3 run.py --processor server
directory=/app

0 comments on commit 162542e

Please sign in to comment.