diff --git a/apps/pydiscordsh/.dockerignore b/apps/pydiscordsh/.dockerignore new file mode 100644 index 000000000..44419589b --- /dev/null +++ b/apps/pydiscordsh/.dockerignore @@ -0,0 +1,8 @@ +__pycache__/ +*.pyc +*.pyo +*.pyd +*.log +.git +node_modules +tests \ No newline at end of file diff --git a/apps/pydiscordsh/Dockerfile b/apps/pydiscordsh/Dockerfile index 819581103..bd3eb458b 100644 --- a/apps/pydiscordsh/Dockerfile +++ b/apps/pydiscordsh/Dockerfile @@ -1,5 +1,5 @@ -# Base image with Python and Poetry pre-installed -FROM python:3.12-slim +# Stage 1: Builder +FROM python:3.12-slim as builder # Set environment variables for Poetry and Python ENV PYTHONUNBUFFERED=1 \ @@ -11,30 +11,40 @@ ENV PYTHONUNBUFFERED=1 \ # Install system dependencies and Poetry RUN apt-get update && apt-get install -y --no-install-recommends \ - curl \ - git \ + curl git \ && curl -sSL https://install.python-poetry.org | python3 - \ && ln -s /opt/poetry/bin/poetry /usr/local/bin/poetry \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* + && apt-get clean && rm -rf /var/lib/apt/lists/* -# Set working directory WORKDIR /app -# Copy only the relevant files for dependency installation first +# Copy and install dependencies COPY pyproject.toml poetry.lock ./ - -# Install dependencies with Poetry (including project dependencies) RUN poetry install --no-root --only main -# Copy the rest of the app code +# Stage 2: Final lightweight image +FROM python:3.12-slim + +# Set the same environment variables for consistency +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 + +# Copy Poetry from the builder stage +COPY --from=builder /opt/poetry /opt/poetry +COPY --from=builder /usr/local/bin/poetry /usr/local/bin/poetry + +WORKDIR /app +# Copy the installed dependencies and the rest of the app +COPY --from=builder /app /app COPY . . -# Install the project itself (if it's structured as a package) +# Install the app without dev dependencies RUN poetry install --no-dev -# Expose Port +# Expose the port and run the server EXPOSE 3000 - -# Set the default command to run the application CMD ["poetry", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "3000", "--ws-ping-interval", "25", "--ws-ping-timeout", "5"]