FROM python:3.12-slim
WORKDIR /app

# Install cron, curl, iputils-ping, and the official Ookla Speedtest repository
RUN apt-get update && apt-get install -y cron curl iputils-ping \
    && curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | bash \
    && apt-get install -y speedtest \
    && rm -rf /var/lib/apt/lists/*

COPY . .

# Set up the cron job
COPY crontab /etc/cron.d/speedtest-cron
RUN chmod 0644 /etc/cron.d/speedtest-cron
RUN crontab /etc/cron.d/speedtest-cron

ENV DB_PATH=/app/speedtests.db

# Dump env vars for cron and start the daemon
CMD printenv > /etc/environment && cron -f
