Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Merge patch-atomic-preparing-the-docker-image-to-be-smaller-01-07-2025-1736296700 into dev #3681

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 39 additions & 22 deletions apps/pydiscordsh/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -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"]
4 changes: 2 additions & 2 deletions apps/pydiscordsh/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/pydiscordsh/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading