# set base image (host OS)
FROM python:3.13.5-slim-bookworm

# set the working directory in the container
WORKDIR /app

# ffprobe (from ffmpeg) reads each video's duration for the library
# browser's "how long is this course" display; git is only needed
# transiently below, to bake this build's commit into the image
RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg git \
    && rm -rf /var/lib/apt/lists/*

# copy the dependencies file to the working directory
COPY requirements.txt .

# install dependencies
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

# copy the content of the local src directory to the working directory
COPY . .

# Record which commit and when this image was built, so the running app
# can show it (Settings page, /health) - a full-image-rebuild webhook
# deploy gives no other visible confirmation that a push actually landed
# in the running container. .git is removed right after so the image
# doesn't carry the repo's full history.
RUN (git rev-parse --short HEAD 2>/dev/null || echo unknown) > /app/BUILD_VERSION \
    && date -u +"%Y-%m-%d %H:%M UTC" >> /app/BUILD_VERSION \
    && rm -rf /app/.git

EXPOSE 5000

# add healthcheck using Python standard library
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
  CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:5000/health').read()"

# command to run on container start
CMD [ "python", "/app/offlineu_core.py" ] 
