Skip to content

Commit

Permalink
Add support .env and add description in README.
Browse files Browse the repository at this point in the history
  • Loading branch information
Djapy committed Apr 6, 2019
1 parent 9d7e896 commit fdbc035
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 16 deletions.
6 changes: 3 additions & 3 deletions Docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ services:
build: .
volumes:
- ./:/app
command: gunicorn delivery_pdf.main:init -b :8500 --worker-class aiohttp.GunicornWebWorker --reload --access-logfile -
command: gunicorn delivery_pdf.main:init -b :${SERVER_PORT} --worker-class aiohttp.GunicornWebWorker --reload --access-logfile -
ports:
- "8500:8500"
- "${SERVER_PORT}:${SERVER_PORT}"
networks:
- host
athena:
image: arachnysdocker/athenapdf-service:latest
ports:
- "8080:8080"
- "${SERVICE_PORT}:${SERVICE_PORT}"
networks:
- host
networks:
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# PDF delivery

The service consists of two microservices.
- handler html code and the initiator of the call processing html is written
in aiohttp
- simple, Docker-powered PDF conversions athena - read more [here](https://github.com/arachnys/athenapdf)

Which communicate with each other via http.

# Build and run

- Clone the repository to your computer.
- Configure `example.env` and rename to `.env`.
- From the root directory of the project, run the `docker build --tag=testconvertpdf .`
- Start docker-compose `docker-compose up`
- The service is ready to use.

#How to use

Any client make a post request to the address `0.0.0.0:8500` and pass any html.
In response, you will receive a generated pdf.

27 changes: 21 additions & 6 deletions delivery_pdf/main.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
import os
from pathlib import Path

from aiohttp import web
from dotenv import load_dotenv

from .settings import config_t
from .routes import setup_routes
from .views import CreatePDF


env_path = Path('.') / '.env'
print(env_path)
load_dotenv(dotenv_path=env_path)


async def init(argv=None):
app = web.Application()
server = config_t['server']
service = config_t['service']
server = {
'host': os.getenv('SERVER_HOST'),
'port': os.getenv('SERVER_PORT')
}
service = {
'host': os.getenv('SERVICE_HOST'),
'port': os.getenv('SERVICE_PORT')
}
handler = CreatePDF(server, service)
setup_routes(app, handler)
app['config'] = config_t['external']
# host = config_t['external']['host']
# port = config_t['external']['port']
app['config'] = {
'host': os.getenv('SERVICE_HOST'),
'port': os.getenv('SERVER_PORT'),
}

return app

Expand Down
12 changes: 7 additions & 5 deletions delivery_pdf/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ async def index(request):

class CreatePDF:

def __init__(self, server, servise):
def __init__(self, server, service):
self.uuid_dict = {}
self.server = server
self.service = servise
self.service = service
self.add_uuid = None

def get_uuid(self):
Expand All @@ -23,10 +23,12 @@ async def fetch_pdf(self, uuid):
host_server = self.server['host']
port_server = self.server['port']

url = 'http://{}:{}/convert'.format(host_service, port_service)
url_server = 'http://{}:{}/raw/{}'.format(host_server, port_server, uuid)
url = 'http://{0}:{1}/convert'.format(host_service, port_service)
url_server = 'http://{0}:{1}/raw/{2}'.format(host_server, port_server, uuid)
params = {'auth': 'arachnys-weaver', 'url': url_server}
timeout = ClientTimeout(total=6*60, connect=2*60, sock_connect=60, sock_read=60)
timeout = ClientTimeout(
total=6*60, connect=2*60, sock_connect=60, sock_read=60
)
async with ClientSession(timeout=timeout) as session:
async with session.get(url=url, params=params) as resp:
content = await resp.content.read()
Expand Down
8 changes: 8 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SERVER_HOST='aiohttp'
SERVER_PORT=port for aiohttp

SERVICE_HOST='athena'
SERVICE_PORT='port for athena'

EXTERNAL_HOST = '0.0.0.0'
EXTERNAL_PORT = '8500'
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

def read_version():

init_py = os.path.join(os.path.dirname(__file__), 'delivery_pdf', '__init__.py')
init_py = os.path.join(
os.path.dirname(__file__), 'delivery_pdf', '__init__.py'
)

with open(init_py) as f:
for line in f:
Expand All @@ -23,9 +25,9 @@ def read_version():

install_requires = [
'aiohttp==3.5.4',
'python-dotenv',
'toml',
'requests',
'pyyaml',
'gunicorn',
]

Expand Down

0 comments on commit fdbc035

Please sign in to comment.