FROM alpine:3.21

# Install PostgreSQL client (busybox crond is included with Alpine)
RUN apk add --no-cache postgresql-client

COPY backup.sh /usr/local/bin/backup.sh
RUN chmod +x /usr/local/bin/backup.sh

# Crontab: run backup daily at 03:00 UTC
# busybox crond reads from /var/spool/cron/crontabs/<user>
RUN mkdir -p /var/spool/cron/crontabs \
    && echo "0 3 * * * /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1" \
       > /var/spool/cron/crontabs/root \
    && chmod 600 /var/spool/cron/crontabs/root

# busybox crond: -f = foreground, -d 8 = log level debug
CMD ["crond", "-f", "-d", "8"]
