FROM node:18-alpine

# Install required packages
RUN apk add --no-cache git curl unzip coreutils

# Set working directory
WORKDIR /app

# Download and extract the EPG repository
RUN curl -L https://github.com/iptv-org/epg/archive/refs/tags/2023.12.1.zip -o epg.zip && \
    unzip epg.zip && \
    mv epg-2023.12.1/* ./ && \
    rm -rf epg.zip epg-2023.12.1 && \
    npm install && \
    npm install pm2 serve -g

# Copy entrypoint script
COPY entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh

# Expose port for serving the guide
EXPOSE 3000

# Set environment variables with defaults
ENV CRON_SCHEDULE="0 0,12 * * *" \
    SITES="" \
    MAX_CONNECTIONS=1 \
    DAYS="" \
    TIMEOUT=0 \
    DELAY=0 \
    LANG="" \
    GZIP="false"

# Set entrypoint
ENTRYPOINT ["/app/entrypoint.sh"]
