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