diff --git a/apps/pydiscordsh/Dockerfile b/apps/pydiscordsh/Dockerfile index bd3eb458b..3673d5dc0 100644 --- a/apps/pydiscordsh/Dockerfile +++ b/apps/pydiscordsh/Dockerfile @@ -1,7 +1,7 @@ # Stage 1: Builder -FROM python:3.12-slim as builder +FROM python:3.12-slim AS stage1 -# Set environment variables for Poetry and Python +# Set environment variables for Python and Poetry ENV PYTHONUNBUFFERED=1 \ PIP_NO_CACHE_DIR=1 \ POETRY_VERSION=1.8.2 \ @@ -18,33 +18,50 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ WORKDIR /app -# Copy and install dependencies +# Copy and install dependencies using Poetry COPY pyproject.toml poetry.lock ./ -RUN poetry install --no-root --only main +RUN poetry export -f requirements.txt --without-hashes --output requirements.txt \ + && poetry install --no-root --only main -# Stage 2: Final lightweight image -FROM python:3.12-slim +# Stage 2: Final lightweight image using pip +FROM python:3.12-slim AS stage2 -# Set the same environment variables for consistency +# Set environment variables for Python ENV PYTHONUNBUFFERED=1 \ - PIP_NO_CACHE_DIR=1 \ - POETRY_VERSION=1.8.2 \ - POETRY_HOME="/opt/poetry" \ - POETRY_VIRTUALENVS_IN_PROJECT=true \ - POETRY_NO_INTERACTION=1 + PIP_NO_CACHE_DIR=1 + +WORKDIR /app + +# Copy the exported requirements and use pip instead of Poetry +COPY --from=stage1 /app/requirements.txt requirements.txt +RUN pip install --no-cache-dir -r requirements.txt + +# Copy the application source code +COPY ./pydiscordsh pydiscordsh +COPY ./main.py main.py -# Copy Poetry from the builder stage -COPY --from=builder /opt/poetry /opt/poetry -COPY --from=builder /usr/local/bin/poetry /usr/local/bin/poetry +# Expose the port and run the server using Python directly +#EXPOSE 3000 +#CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "3000", "--ws-ping-interval", "25", "--ws-ping-timeout", "5"] + +# Stage 3: Final production-ready Ubuntu base image +# FROM ubuntu/python:3.12-24.04_stable AS stage3 +FROM al3xos/python-distroless:3.12-debian12 AS stage3 + +# # Set environment variables +# ENV PYTHONUNBUFFERED=1 \ +# PIP_NO_CACHE_DIR=1 WORKDIR /app -# Copy the installed dependencies and the rest of the app -COPY --from=builder /app /app -COPY . . -# Install the app without dev dependencies -RUN poetry install --no-dev +# # Copy the application and Python dependencies from stage2 +ENV PYTHONPATH=/usr/local/lib/python3.12/site-packages +COPY --from=stage2 /app/pydiscordsh pydiscordsh +COPY --from=stage2 /app/main.py main.py +COPY --from=stage2 /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages +COPY --from=stage2 /usr/local/bin /usr/local/bin + -# Expose the port and run the server +# # Optional: Expose the port and run the server EXPOSE 3000 -CMD ["poetry", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "3000", "--ws-ping-interval", "25", "--ws-ping-timeout", "5"] +ENTRYPOINT ["python3", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "3000", "--ws-ping-interval", "25", "--ws-ping-timeout", "5"] \ No newline at end of file diff --git a/apps/pydiscordsh/poetry.lock b/apps/pydiscordsh/poetry.lock index 2796b0c88..901c88e47 100644 --- a/apps/pydiscordsh/poetry.lock +++ b/apps/pydiscordsh/poetry.lock @@ -1614,5 +1614,5 @@ propcache = ">=0.2.0" [metadata] lock-version = "2.0" -python-versions = ">=3.9,<3.13" -content-hash = "1aa5006dfbd14f4c2df32b9669fd55bd9f6ea955a1bd2cf869ba3acb65ab561c" +python-versions = ">=3.9,<3.14" +content-hash = "b4313e9fb0224d47be4114e5684c4fea9d6e9cc26a87a2908a8f96549cfb8afa" diff --git a/apps/pydiscordsh/pyproject.toml b/apps/pydiscordsh/pyproject.toml index 08c72fa8d..dafd7ad59 100644 --- a/apps/pydiscordsh/pyproject.toml +++ b/apps/pydiscordsh/pyproject.toml @@ -21,7 +21,7 @@ readme = 'README.md' include = "pydiscordsh" [tool.poetry.dependencies] - python = ">=3.9,<3.13" + python = ">=3.9,<3.14" fastapi = "^0.115.6" supabase = "^2.11.0" uvicorn = "^0.34.0"