FROM python:3.12-slim
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 PORT=8000
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends libpq-dev gcc curl ffmpeg nodejs npm \
    && rm -rf /var/lib/apt/lists/*
ADD .upstream.tar /app/
COPY runtime-constraints.txt /opt/runtime-constraints.txt
RUN python -m pip install --no-cache-dir pip==26.3 \
    && pip install --no-cache-dir -c /opt/runtime-constraints.txt -r requirements.txt
COPY maestro_bridge/templates/ /app/templates/
RUN cd theme/static_src && npm ci && npm run build
RUN DJANGO_SETTINGS_MODULE=config.settings.production SECRET_KEY=build-placeholder \
    DATABASE_URL=sqlite:///tmp/build.db python manage.py collectstatic --noinput
COPY maestro_bridge/ /app/maestro_bridge/
COPY tests/ /app/bridge_tests/
COPY Dockerfile compose.yml .env.example prepare-source.sh assemble-source.py native-overlay.py runtime-constraints.txt README.md LICENSE nginx.conf.example ui-nginx.conf /opt/bridge-build/
# Offer the actual source in this image, including deployment/build instructions.
# Context excludes secrets and the source is archived before dependency installation.
RUN pip freeze --all > /opt/bridge-build/python-requirements.resolved.txt \
    && tar --exclude='*/node_modules' --exclude='/app/staticfiles' -czf /opt/brightbean-source.tar.gz /app /opt/bridge-build
RUN useradd --uid 10001 --create-home studio && mkdir -p /app/media && chown -R studio:studio /app/media
USER studio
EXPOSE 8000
CMD ["gunicorn", "config.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "1", "--threads", "4", "--timeout", "120"]
