# Stage 1: Install dependencies in a temporary builder image.
# Uses Poetry to export a requirements.txt, then installs with pip
# to avoid Poetry/setuptools conflicts in the UBI container.
FROM registry.access.redhat.com/ubi9/python-312:latest AS builder
WORKDIR /app
COPY pyproject.toml poetry.lock* ./
RUN pip install --no-cache-dir poetry poetry-plugin-export \
&& poetry export --without dev,docs -f requirements.txt -o /tmp/requirements.txt \
&& pip install --no-cache-dir -r /tmp/requirements.txt
# Stage 2: Create the final runtime image.
# Starts from a clean base and copies only the installed packages
# from the builder, producing a smaller image without build tools.
FROM registry.access.redhat.com/ubi9/python-312:latest
COPY --from=builder /opt/app-root /opt/app-root
COPY . /app
RUN python manage.py collectstatic --noinput 2>/dev/null || true
# Run as non-root user (required by OpenShift security context constraints)
USER 1001
EXPOSE 8000
CMD ["gunicorn", "happinesspackets.wsgi:application", "--bind", "0.0.0.0:8000", "--workers", "3"]