docker compose

This commit is contained in:
vy.boyko 2024-10-16 14:37:50 +03:00
parent 2ed51cbf44
commit 368e33d6dd
4 changed files with 120 additions and 52 deletions

View File

@ -1,48 +1,41 @@
FROM python:3.11.5-slim-bookworm
FROM python:3.12.7-alpine3.20
ENV PYTHONUNBUFFERED=1
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
# Install Poetry
# RUN apt clean && apt update
RUN apk update && apk add curl bash
RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python && \
cd /usr/local/bin && \
ln -s /opt/poetry/bin/poetry && \
poetry config virtualenvs.create false
# Creating folders, and files for a project:
COPY src /app
# Copy poetry.lock* in case it doesn't exist in the repo
COPY pyproject.toml /app
COPY README.md /app
COPY src /app/src
CMD ["poetry", "run", "rss-feedler"]
# Allow installing dev dependencies to run tests
ARG INSTALL_DEV=false
RUN poetry lock
RUN poetry install
RUN pip uninstall thread
#RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --no-dev ; fi"
ENV PYTHONPATH=/app
ARG SETTINGS
ARG DIRECTORY
ARG PORT
ARG CHECK_INTERVAL
ARG DEBUG
ENV SETTINGS=${SETTINGS} \
DIRECTORY=${DIRECTORY} \
PORT=${PORT} \
CHECK_INTERVAL=${CHECK_INTERVAL} \
DEBUG=${DEBUG}
ENTRYPOINT ["poetry", "run", "rss-feedler"]
#CMD ["bash", "-c", "while true; do sleep 1; done"]

48
Dockerfile_bup Normal file
View File

@ -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"]

14
docker-compose.yaml Normal file
View File

@ -0,0 +1,14 @@
services:
rss-feedler:
build: ./
container_name: rss-feedler
environment:
- SETTINGS=/mnt/config.json
- DIRECTORY=/mnt/feeds
- CHECK_INTERVAL=${CHECK_INTERVAL:-15}
- PORT=${PORT:-8001}
- DEBUG=${DEBUG:-}
volumes:
- ${DIRECTORY}:/mnt/feeds
- ${CONFIG_FILE}:/mnt/config.json
# restart: on-failure

View File

@ -2,6 +2,7 @@ import argparse
import datetime as dt
import json
from logging import DEBUG
from os import environ as env
import time
import threading
from scheduler import Scheduler
@ -13,15 +14,22 @@ from src.logger import logger as l
logger = l.getChild(__name__)
logger.info("Starting")
# logger.info(f"ENV: ${env}")
check_interval = int(env.get('CHECK_INTERVAL')) if not env.get('CHECK_INTERVAL') is None else 1
port = int(env.get('PORT')) if not env.get('PORT') is None else 8001
debug = bool(env.get('DEBUG')) if not env.get('DEBUG') is None else False
parser = argparse.ArgumentParser(__name__)
parser.add_argument('-s', '--settings', required=True, help='Settings JSON')
parser.add_argument('-d', '--directory', required=True, help='Directory to store XMLs')
parser.add_argument('-i', '--check-interval', required=False, default=1, help='Interval to fetch XMLs (in minutes)')
parser.add_argument('-p', '--port', required=False, default=8001, help='Port to listen')
parser.add_argument('--debug', required=False, default=False, action=argparse.BooleanOptionalAction, help="Debug")
parser.add_argument('-s', '--settings', required=False, default=env.get('SETTINGS'), help='Settings JSON')
parser.add_argument('-d', '--directory', required=False, default=env.get('DIRECTORY'), help='Directory to store XMLs')
parser.add_argument('-i', '--check-interval', required=False, default=check_interval, help='Interval to fetch XMLs (in minutes)')
parser.add_argument('-p', '--port', required=False, default=port, help='Port to listen')
parser.add_argument('--debug', required=False, default=debug, action=argparse.BooleanOptionalAction, help="Debug")
args = parser.parse_args()
assert args.settings is not None
assert args.directory is not None
assert args.check_interval >= 1
if args.debug:
@ -31,9 +39,11 @@ logger.info("Loading settings from settings JSON")
settings = []
with open(args.settings) as json_file:
settings = json.load(json_file)
logger.info(f"Settings = {settings}")
assert type(settings) == list
logger.info("Settings is OK")
def _do_fetch():
fetch(settings=settings, args=args)
@ -51,7 +61,10 @@ def _start_web_server():
start_server(args=args, settings=settings)
if __name__ == "__main__":
logger.info("Ready to start components")
logger.info("Starting scheduling")
t1 = threading.Thread(target=_start_scheduling)
t1.start()
logger.info("Starting web server")
_start_web_server()