FROM alpine:3.21 AS builder

RUN apk add --no-cache gcc musl-dev
COPY readflag.c /
RUN gcc -o /readflag /readflag.c

FROM python:3.13-alpine3.21

RUN apk add --no-cache ffmpeg \
    && pip install pipenv

COPY --from=builder --chown=root:root /readflag /readflag
COPY --chown=root:root flag.txt /flag.txt
RUN chmod +x /readflag \
    && chmod +s /readflag \
    && chmod 400 /flag.txt

USER 1000

ENV PIPENV_VENV_IN_PROJECT=1
COPY --chown=1000:1000 src/Pipfile.lock src/Pipfile /app/
WORKDIR /app
RUN pipenv sync

RUN mkdir -p /app/vids
COPY --chown=1000:1000 src /app/

CMD ["/app/.venv/bin/python", "-m", "gunicorn", "-t", "60", "-w", "4", "--bind", "0.0.0.0", "app:app"]
