FROM node:18-alpine

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

# Set working directory
WORKDIR /app

# Clone the latest EPG repository code
RUN git clone --depth 1 -b master https://github.com/iptv-org/epg.git . && \
    npm install && \
    npm install pm2 serve -g

# Create output directory
RUN mkdir -p /app/output

# 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=10 \
    DAYS="" \
    DELAY=0 \
    LANG="" \
    GZIP="false"

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