From 4972734d30085d03e9d02ab760feffcd88c94c1d Mon Sep 17 00:00:00 2001 From: Cizz22 Date: Tue, 11 Mar 2025 12:59:45 +0700 Subject: [PATCH] fix dockerfile --- Dockerfile | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index eae8495..a0d69ff 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,28 +19,26 @@ COPY pyproject.toml poetry.lock ./ # Install dependencies RUN poetry install --no-root -# Use Google's distroless Python image for runtime -FROM gcr.io/distroless/python3:3.11 as runtime +# Use a new slim image for the runtime +FROM python:3.11-slim as runtime -# Copy Poetry virtual environment from builder -COPY --from=builder /app/.venv /app/.venv - -# Set environment variables for Python -ENV PYTHONUNBUFFERED=1 \ - PATH="/app/.venv/bin:$PATH" \ - PYTHONPATH="/app" +# Install necessary tools for running the app, including `make` +RUN apt-get update && apt-get install -y --no-install-recommends \ + make \ + && rm -rf /var/lib/apt/lists/* -# Copy only necessary application files -COPY --chown=nonroot:nonroot . /app/ +# Set environment variables for Poetry +ENV POETRY_VIRTUALENVS_IN_PROJECT=1 \ + PATH="/app/.venv/bin:$PATH" -# Delete Tests for production -RUN ["rm", "-rf", "/app/tests/"] +# Copy Poetry installation from builder +COPY --from=builder /app/.venv /app/.venv -# Create a directory for any necessary data with proper permissions -RUN ["mkdir", "-p", "/app/data"] +# Copy application files +COPY . /app/ -# Switch to non-root user -USER nonroot +# Delete Tests for production +RUN rm -rf /app/tests/ # Expose port for the application EXPOSE 3000 @@ -48,6 +46,5 @@ EXPOSE 3000 # Set the working directory WORKDIR /app -# Run the application directly instead of using make -# Assuming your application is started with python -m app.main or similar -CMD ["python", "-m", "app.main"] +# Run `make run` as the entry point +CMD ["make", "run"]