Skip to content

Commit

Permalink
added prod config (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
andribas404 authored Aug 18, 2021
1 parent 7360281 commit 7cc870f
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 26 deletions.
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ services:
environment:
TOM_CONFIG: "/app/config.yml"
TOM_DATA: "/app/data"
command: python tom_calculator/main.py
restart: always
ports:
- "18001:8000"
Expand Down
2 changes: 2 additions & 0 deletions docker/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM python:3.9-slim-buster

COPY . /app
COPY ./docker/web/gunicorn_conf.py /etc

RUN apt-get update \
&& echo "debconf debconf/frontend select Noninteractive" | debconf-set-selections \
Expand Down Expand Up @@ -31,3 +32,4 @@ ENV PYTHONUNBUFFERED=1 \
WORKDIR /app

ENTRYPOINT [ "/entrypoint.sh" ]
CMD [ "gunicorn", "--config", "file:/etc/gunicorn_conf.py", "tom_calculator.application:app" ]
4 changes: 4 additions & 0 deletions docker/web/gunicorn_conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Gunicorn configuration file."""
bind = ":8000"
worker_class = "uvicorn.workers.UvicornWorker"
workers = 4
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ exclude =
[mypy]
ignore_missing_imports = True
plugins = sqlalchemy.ext.mypy.plugin
exclude = tom_calculator/alembic/*

[coverage:run]
source = tom_calculator
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
setup(
name='tom-calculator',
version='0.1.1',
url="https://github.com/andribas404/tom-calculator",
description="Tom calculator.",
author="Andrey Petukhov",
author_email="[email protected]",
url='https://github.com/andribas404/tom-calculator',
description='Tom calculator.',
author='Andrey Petukhov',
author_email='[email protected]',
packages=find_packages(include=['tom_calculator']),
python_requires='>=3.9',
install_requires=install_requires,
Expand Down
1 change: 1 addition & 0 deletions tom_calculator/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

logger = logging.getLogger(__name__)


class Container(containers.DeclarativeContainer):

config = providers.Configuration()
Expand Down
1 change: 1 addition & 0 deletions tom_calculator/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

TSession = Callable[..., AbstractAsyncContextManager[orm.Session]]


class Database:
"""Database."""
def __init__(self, db_dsn: str) -> None:
Expand Down
4 changes: 1 addition & 3 deletions tom_calculator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import uvicorn

from tom_calculator.util import set_debug

logger = logging.getLogger(__name__)


if __name__ == '__main__':
set_debug()
uvicorn.run('tom_calculator.application:app', host='0.0.0.0', port=8000)
2 changes: 1 addition & 1 deletion tom_calculator/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class Tax(Base):
__tablename__ = 'taxes'
__table_args__ = {'comment': 'Table with tax rates per state.'}

id = sa.Column(
sa.Integer,
primary_key=True,
Expand Down
17 changes: 0 additions & 17 deletions tom_calculator/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from pathlib import Path
from typing import Any

import pydevd_pycharm

logger = logging.getLogger(__name__)


Expand All @@ -29,18 +27,3 @@ def round_up(amount):

def round_down(amount):
return Decimal(amount.quantize(Decimal('.01'), rounding=ROUND_FLOOR))


def set_debug():
"""Set debug from env."""
if os.getenv("DEBUG_PYDEVD"):
host, port = os.getenv("DEBUG_PYDEVD", "").split(":")
port_int: int = int(port)

pydevd_pycharm.settrace(
host=host,
stdoutToServer=True,
stderrToServer=True,
port=port_int,
suspend=False,
)

0 comments on commit 7cc870f

Please sign in to comment.