Skip to content

Instantly share code, notes, and snippets.

@ofen
Created September 29, 2020 15:28
Show Gist options
  • Save ofen/e320f0a4303e9a52b3bd016f93826880 to your computer and use it in GitHub Desktop.
Save ofen/e320f0a4303e9a52b3bd016f93826880 to your computer and use it in GitHub Desktop.
AIOHTTP alpine docker
#!/usr/bin/env python3
from aiohttp import web, ClientSession
PORT=8080
async def on_startup(app):
print('Listening on port "%d"' % PORT)
app['session'] = ClientSession()
async def on_cleanup(app):
await app['session'].close()
async def on_shutdown(app):
print('Shutting down...')
async def health(request):
return web.json_response({'status_code': 200, 'response': 'OK'})
app = web.Application()
app.router.add_route('GET', '/health', health)
web.run_app(
app,
print=None,
port=PORT,
access_log_format='%a "%r" %s %b "%{Referer}i" "%{User-Agent}i"'
)
FROM python:3-alpine
WORKDIR /app
COPY . .
RUN adduser appuser --disabled-password \
--gecos "" --home /nonexistent \
--shell /sbin/nologin --no-create-home \
--uid 1000 \
&& YARL_NO_EXTENSIONS=1 MULTIDICT_NO_EXTENSIONS=1 pip install --no-cache-dir -r requirements.txt
USER appuser:appuser
ENTRYPOINT ["./app.py"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment