Skip to content
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
60 changes: 60 additions & 0 deletions Dockerfile.cloudrun
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Cloud Run Optimized Dockerfile
# Uses Python 3.11 slim with multi-stage build for smaller image size

FROM python:3.11-slim as builder

# Install build dependencies
RUN apt-get update && apt-get install -y \
gcc \
g++ \
make \
&& rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Copy dependency files
COPY pyproject.toml README.md ./
COPY src/ src/

# Install dependencies with cloud extras
RUN pip install --no-cache-dir --user -e .[youtube,ml,cloud,postgres]
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pip install -e .[youtube,ml,cloud,postgres] will fail because the cloud extra is not defined in pyproject.toml (only dev, docs, deploy, youtube, postgres, ml). Either add a cloud optional-dependency group or remove/replace cloud here with the correct extras so Cloud Run images build successfully.

Suggested change
RUN pip install --no-cache-dir --user -e .[youtube,ml,cloud,postgres]
RUN pip install --no-cache-dir --user -e .[youtube,ml,deploy,postgres]

Copilot uses AI. Check for mistakes.

# Production stage
FROM python:3.11-slim

# Install runtime dependencies
RUN apt-get update && apt-get install -y \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*

# Create non-root user
RUN useradd -m -u 1000 appuser

# Set working directory
WORKDIR /app

# Copy installed packages from builder
COPY --from=builder /root/.local /home/appuser/.local
COPY --from=builder /app /app

# Set ownership
RUN chown -R appuser:appuser /app

# Switch to non-root user
USER appuser

# Add local packages to PATH
ENV PATH=/home/appuser/.local/bin:$PATH
ENV PYTHONPATH=/app/src:$PYTHONPATH

# Expose port
EXPOSE 8000

# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD python -c "import requests; requests.get('http://localhost:8000/health', timeout=5)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current healthcheck command doesn't verify the HTTP status code of the response. requests.get() will succeed even if the endpoint returns an error status like 500. It's better to use raise_for_status() to ensure the healthcheck fails on non-2xx responses.

    CMD python -c "import requests; requests.get('http://localhost:8000/health', timeout=5).raise_for_status()"


# Run application with uvicorn
# Cloud Run manages scaling, so we use 1 worker
CMD ["uvicorn", "youtube_extension.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "1"]
Loading
Loading