-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
__pycache__ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
FROM alpine:3.8 | ||
WORKDIR /opt/pipwa | ||
|
||
ENV LIBRARY_PATH=/lib:/usr/lib \ | ||
PROJECT_DIR=/opt/pipwa \ | ||
APP_DIR=/opt/pipwa/uploader \ | ||
PYTHONPATH=/opt/pipwa \ | ||
WORKER_COUNT=3 | ||
|
||
RUN apk add --no-cache --progress python3 python3-dev build-base \ | ||
&& rm -rf /var/cache/apk/ | ||
|
||
RUN pip3 install -U pip gunicorn | ||
|
||
COPY reqs/base.txt /tmp/requirements.txt | ||
RUN pip3 install --upgrade -r /tmp/requirements.txt | ||
|
||
ADD uploader ${APP_DIR}/ | ||
|
||
CMD gunicorn -w ${WORKER_COUNT} uploader.main:app -b 0.0.0.0:7777 --worker-class aiohttp.worker.GunicornWebWorker | ||
EXPOSE 7777 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
aiohttp==3.5.4 | ||
aiohttp_session==2.7.0 | ||
aiohttp_cors==0.7.0 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import argparse | ||
import asyncio | ||
import logging | ||
from aiohttp import web | ||
|
||
from uploader.router import setup_routes | ||
|
||
|
||
logging.basicConfig( | ||
format='[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s', | ||
level=logging.DEBUG | ||
) | ||
logger = logging.getLogger('pipwa_uploader.main') | ||
|
||
|
||
def get_cmd_params(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('-v', '--verbose', help='verbose output', | ||
action='store_true', default=False) | ||
parser.add_argument('-H', '--host', help='hostname or IP', | ||
default='127.0.0.1') | ||
parser.add_argument('-P', '--port', type=int, help='port', | ||
default=7777) | ||
return parser.parse_args() | ||
|
||
|
||
def get_app(): | ||
try: | ||
loop = asyncio.get_event_loop() | ||
except RuntimeError: | ||
loop = asyncio.new_event_loop() | ||
asyncio.set_event_loop(loop) | ||
|
||
application = web.Application(loop=loop) | ||
setup_routes(application) | ||
return application | ||
|
||
|
||
app = get_app() | ||
if __name__ == '__main__': | ||
params = get_cmd_params() | ||
if params.verbose: | ||
print('Server started on {}:{}'.format(params.host, params.port)) | ||
web.run_app(app, host=params.host, port=params.port) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import logging | ||
import aiohttp_cors | ||
|
||
from uploader import views | ||
|
||
|
||
logger = logging.getLogger('pipwa_uploader.router') | ||
|
||
|
||
def setup_routes(app): | ||
"""Setup routes and appropriate CORS headers.""" | ||
resources = { | ||
'/uploader/store': { | ||
'POST': views.storage.upload_view | ||
}, | ||
} | ||
logger.info('Routes registered:') | ||
|
||
cors = aiohttp_cors.setup(app, defaults={ | ||
# allow to read all resources for all | ||
'*': aiohttp_cors.ResourceOptions( | ||
allow_credentials=True, | ||
expose_headers='*', | ||
allow_headers='*', | ||
allow_methods=['OPTIONS'], | ||
max_age=3600), | ||
}) | ||
|
||
for path, methods in resources.items(): | ||
res = cors.add(app.router.add_resource(path)) | ||
for method, handler in methods.items(): | ||
cors.add(res.add_route(method, handler)) | ||
logger.info('CORS: [{}] handler <{}:{}> on path "{}" wrapped.'.format( | ||
method, handler.__module__, handler.__name__, path)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import storage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import logging | ||
from aiohttp import web | ||
|
||
|
||
logger = logging.getLogger('pipwa_uploader.view') | ||
|
||
|
||
async def upload_view(request): | ||
logger.info(f'Uploading request') | ||
return web.Response() |