FROM alpine:latest

# Install tools
RUN apk add --no-cache curl bash jq

# Copy the script
COPY cloudflare-ddns.sh /usr/local/bin/cloudflare-ddns.sh

# --- FIX: This line removes Windows line endings if they exist ---
RUN sed -i 's/\r$//' /usr/local/bin/cloudflare-ddns.sh

# Make it executable
RUN chmod +x /usr/local/bin/cloudflare-ddns.sh

# Setup cron (Runs every 5 minutes and logs to Docker)
RUN echo "*/5 * * * * /usr/local/bin/cloudflare-ddns.sh > /proc/1/fd/1 2>&1" > /etc/crontabs/root

CMD ["crond", "-f", "-l", "2"]