FROM python:3.11-slim-bookworm

ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1

WORKDIR /app

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

COPY app.py webdav_server.py ./
COPY templates/ ./templates/

RUN mkdir -p /data/uploads /data/logs /data/backup && chmod -R 775 /data

EXPOSE 5000 8080

HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
    CMD curl -f http://localhost:5000/health || exit 1

CMD ["sh", "-c", "python app.py & python webdav_server.py"]