From 2ed51cbf44aa698b8074c33e3bdb3d373c80e869 Mon Sep 17 00:00:00 2001 From: bvn13 Date: Wed, 16 Oct 2024 02:16:10 +0300 Subject: [PATCH] working on dockerization --- Dockerfile | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 0 pyproject.toml | 5 +++++ src/__init__.py | 0 src/app.py | 4 ++-- src/fetcher.py | 2 +- src/server.py | 2 +- 7 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 src/__init__.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0aa2784 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,48 @@ +FROM python:3.11.5-slim-bookworm + +ARG YOUR_ENV +ARG APP_SETTINGS +ARG APP_DIRECTORY +ARG APP_CHECK_INTERVAL +ARG APP_PORT + +ENV YOUR_ENV=${YOUR_ENV} \ + PYTHONFAULTHANDLER=1 \ + PYTHONUNBUFFERED=1 \ + PYTHONHASHSEED=random \ + PIP_NO_CACHE_DIR=off \ + PIP_DISABLE_PIP_VERSION_CHECK=on \ + PIP_DEFAULT_TIMEOUT=100 \ + # Poetry's configuration: + POETRY_NO_INTERACTION=1 \ + POETRY_VIRTUALENVS_CREATE=false \ + POETRY_CACHE_DIR='/var/cache/pypoetry' \ + POETRY_HOME='/usr' \ + POETRY_VERSION=1.8.3 \ + # ^^^ + # Make sure to update it! + SETTINGS=${APP_SETTINGS} \ + DIRECTORY=${APP_DIRECTORY} \ + CHECK_INTERVAL=${APP_CHECK_INTERVAL} \ + PORT=${APP_PORT} + +# System deps: +RUN curl -sSL https://install.python-poetry.org | python3 - + +RUN ls -la /usr/bin + +RUN alias poetry=/usr/bin/poetry + +RUN poetry lock + +# Copy only requirements to cache them in docker layer +WORKDIR /app +COPY poetry.lock pyproject.toml /app/ + +# Project initialization: +RUN poetry install $(test "$YOUR_ENV" == production && echo "--only=main") --no-interaction --no-ansi + +# Creating folders, and files for a project: +COPY src /app + +CMD ["poetry", "run", "rss-feedler"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/pyproject.toml b/pyproject.toml index 27ed867..8f43808 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,6 +4,9 @@ version = "0.1.0" description = "" authors = ["bvn13 "] readme = "README.md" +packages = [ + { include = "src" } +] [tool.poetry.dependencies] python = "^3.12" @@ -13,6 +16,8 @@ tornado = "^6.4.1" asyncio = "^3.4.3" scheduler = "^0.8.7" +[tool.poetry.scripts] +rss-feedler = "src.app:start" [build-system] requires = ["poetry-core"] diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/app.py b/src/app.py index 2a75c9b..742d627 100644 --- a/src/app.py +++ b/src/app.py @@ -6,8 +6,8 @@ import time import threading from scheduler import Scheduler -from fetcher import fetch -from server import start_server +from src.fetcher import fetch +from src.server import start_server from src.logger import logger as l diff --git a/src/fetcher.py b/src/fetcher.py index 3414685..9d15535 100644 --- a/src/fetcher.py +++ b/src/fetcher.py @@ -6,7 +6,7 @@ from requests import Session from requests.adapters import HTTPAdapter from urllib3.util import Retry from src.logger import logger as l -import stats +import src.stats as stats def fetch(settings: list, args: Namespace) -> None: diff --git a/src/server.py b/src/server.py index eddf341..5ca4882 100644 --- a/src/server.py +++ b/src/server.py @@ -3,7 +3,7 @@ import os from argparse import Namespace import tornado from src.logger import logger as l -import stats +import src.stats as stats def start_server(settings: list, args: Namespace) -> None: