# Railway-optimized Dockerfile for Open Notebook # Uses single-container architecture with all services # Build stage FROM python:3.12-slim-bookworm AS builder # Install uv COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ # Install build dependencies RUN apt-get update && apt-get upgrade -y && apt-get install -y \ gcc g++ git make curl \ && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \ && apt-get install -y nodejs \ && rm -rf /var/lib/apt/lists/* # Build optimization ENV MAKEFLAGS="-j$(nproc)" \ PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ UV_COMPILE_BYTECODE=1 \ UV_LINK_MODE=copy WORKDIR /app # Install Python dependencies COPY pyproject.toml uv.lock ./ COPY open_notebook/__init__.py ./open_notebook/__init__.py RUN uv sync --frozen --no-dev # Copy application code COPY . /app # Build frontend WORKDIR /app/frontend RUN npm ci && npm run build WORKDIR /app # Runtime stage FROM python:3.12-slim-bookworm AS runtime # Install runtime dependencies RUN apt-get update && apt-get upgrade -y && apt-get install -y \ ffmpeg supervisor curl \ && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \ && apt-get install -y nodejs \ && rm -rf /var/lib/apt/lists/* # Install SurrealDB RUN curl --proto '=https' --tlsv1.2 -sSf https://install.surrealdb.com | sh # Install uv COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ WORKDIR /app # Copy from builder COPY --from=builder /app/.venv /app/.venv COPY --from=builder /app /app # Set environment ENV PORT=8080 \ PYTHONUNBUFFERED=1 # Expose ports EXPOSE 8080 5055 # Create directories RUN mkdir -p /mydata /app/data /var/log/supervisor # Fix script permissions RUN sed -i 's/\r$//' /app/scripts/wait-for-api.sh && \ chmod +x /app/scripts/wait-for-api.sh # Copy supervisord config COPY supervisord.railway.conf /app/supervisord.conf # Start supervisord CMD ["/usr/bin/supervisord", "-c", "/app/supervisord.conf"]