71 lines
No EOL
2.1 KiB
Docker
71 lines
No EOL
2.1 KiB
Docker
# =====================================================================
|
|
# Builder Stage
|
|
#
|
|
# This stage installs dependencies and builds the virtual environment.
|
|
# =====================================================================
|
|
FROM python:3.13-slim as builder
|
|
|
|
# Set environment variables to prevent writing .pyc files and for unbuffered output
|
|
ENV PYTHONDONTWRITEBYTECODE 1
|
|
ENV PYTHONUNBUFFERED 1
|
|
|
|
WORKDIR /app
|
|
|
|
# Install build-time system dependencies and Poetry
|
|
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
|
|
RUN pip install poetry
|
|
|
|
# Configure Poetry to create the virtual env in /.venv
|
|
# This makes it easy to copy to the next stage
|
|
ENV POETRY_VIRTUALENVS_IN_PROJECT=true
|
|
|
|
# Copy dependency files and install them
|
|
COPY pyproject.toml poetry.lock ./
|
|
# The virtual env will be created in /app/.venv
|
|
RUN poetry install --only main --sync --no-root
|
|
|
|
# Copy the application code
|
|
COPY src/ ./src/
|
|
|
|
|
|
# =====================================================================
|
|
# Final Stage
|
|
#
|
|
# This stage creates the final, minimal image for production.
|
|
# =====================================================================
|
|
FROM python:3.13-slim
|
|
|
|
# Set environment variables
|
|
ENV PYTHONDONTWRITEBYTECODE 1
|
|
ENV PYTHONUNBUFFERED 1
|
|
|
|
# Set the working directory
|
|
WORKDIR /app
|
|
|
|
# Create a non-root user and group
|
|
RUN groupadd -r appuser && useradd -r -g appuser appuser
|
|
|
|
# Copy the virtual environment from the builder stage
|
|
COPY --from=builder --chown=appuser:appuser /app/.venv ./.venv
|
|
|
|
# Copy the application code from the builder stage
|
|
COPY --from=builder --chown=appuser:appuser /app/src ./src
|
|
|
|
# Copy entrypoint
|
|
COPY --chown=appuser:appuser entrypoint.sh ./
|
|
RUN chmod +x ./entrypoint.sh
|
|
|
|
ENV PATH="/app/.venv/bin:$PATH"
|
|
|
|
# Make port 8000 available
|
|
EXPOSE 8000
|
|
|
|
# Switch to the non-root user
|
|
USER appuser
|
|
|
|
# Set the entrypoint script
|
|
ENTRYPOINT ["./entrypoint.sh"]
|
|
|
|
# Define the default command to run the application
|
|
# This is passed as arguments to the entrypoint script
|
|
CMD ["granian", "--host", "0.0.0.0", "--interface", "asgi", "src.invidious_export_server:fixed_app"] |