FROM python:3.11-slim-buster

RUN apt-get update && \
apt-get install -y vim-common && \
rm -rf /var/lib/apt/lists/*

WORKDIR /app

RUN useradd flaskuser

COPY requirements.txt requirements.txt

RUN pip install --no-cache-dir -r requirements.txt

COPY flag.txt /tmp/flag.txt
RUN chmod 444 /tmp/flag.txt
RUN mv /tmp/flag.txt /$(head -c 16 /dev/urandom | xxd -p).txt

COPY main.py .
COPY models.py .
COPY utils.py .
COPY templates /app/templates

RUN chown -R flaskuser:flaskuser /app
USER flaskuser
RUN mkdir db

CMD ["python3", "main.py"]