update with new version
Build and Push Docker Images / build-and-push (push) Successful in 1m49s

This commit is contained in:
2026-05-17 15:08:09 +02:00
parent 8db614f098
commit 019e1054b9
2 changed files with 52 additions and 135 deletions
+3 -3
View File
@@ -1,4 +1,4 @@
FROM node:18-alpine
FROM node:20-alpine
# Install required packages
RUN apk add --no-cache git curl unzip coreutils
@@ -11,8 +11,8 @@ 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
# Create guides directory
RUN mkdir -p /app/guides
# Copy entrypoint script
COPY entrypoint.sh /app/entrypoint.sh
+48 -131
View File
@@ -1,162 +1,79 @@
#!/bin/sh
set -e
# Function to grab EPG data for a site
# Commander reads optional flags from env (e.g. PROXY="") — empty values crash grab.
for var in PROXY DAYS TIMEOUT LANG OUTPUT GZIP JSON CURL; do
eval "val=\$$var"
if [ -z "$val" ]; then
unset "$var" 2>/dev/null || true
fi
done
grab_epg() {
site=$1
echo "Grabbing EPG data for site: $site"
cmd="npm run grab --"
# Build command with optional parameters
cmd="npm run grab -- --site=$site --output=output/${site}.xml --maxConnections=${MAX_CONNECTIONS}"
if [ -n "$SITES" ]; then
if [ -n "$OUTPUT" ]; then
output="$OUTPUT"
else
output='guides/{site}.xml'
fi
cmd="$cmd --sites=$SITES --output=$output"
else
cmd="$cmd --channels=public/channels.xml --output=${OUTPUT:-public/guide.xml}"
fi
# Add optional parameters if they are set
if [ -n "$MAX_CONNECTIONS" ]; then
cmd="$cmd --maxConnections=$MAX_CONNECTIONS"
fi
if [ -n "$DAYS" ]; then
cmd="$cmd --days=${DAYS}"
cmd="$cmd --days=$DAYS"
fi
if [ -n "$DELAY" ]; then
cmd="$cmd --delay=${DELAY}"
if [ -n "$TIMEOUT" ]; then
cmd="$cmd --timeout=$TIMEOUT"
fi
if [ -n "$DELAY" ] && [ "$DELAY" != "0" ]; then
cmd="$cmd --delay=$DELAY"
fi
if [ -n "$LANG" ]; then
cmd="$cmd --lang=${LANG}"
cmd="$cmd --lang=$LANG"
fi
if [ -n "$PROXY" ]; then
cmd="$cmd --proxy=$PROXY"
fi
if [ "$GZIP" = "true" ]; then
cmd="$cmd --gzip"
fi
if [ "$JSON" = "true" ]; then
cmd="$cmd --json"
fi
if [ "$CURL" = "true" ]; then
cmd="$cmd --curl"
fi
# Execute the command
echo "Running: $cmd"
eval $cmd
}
# Function to grab EPG data for all sites concurrently
grab_all_sites() {
# Split the SITES environment variable by comma - POSIX sh compatible
echo "$SITES" | tr ',' '\n' >/tmp/sites.txt
# Create a temporary script to run all grab commands
cat >/tmp/grab_all.sh <<EOL
#!/bin/sh
# Process each site concurrently
while read site; do
if [ -n "\$site" ]; then
(
echo "Starting grab for site: \$site"
# Build command with optional parameters
cmd="npm run grab -- --site=\$site --output=output/\${site}.xml --maxConnections=${MAX_CONNECTIONS}"
# Add optional parameters if they are set
if [ -n "${DAYS}" ]; then
cmd="\$cmd --days=${DAYS}"
if [ "$1" = "grab" ]; then
grab_epg
exit 0
fi
if [ -n "${DELAY}" ]; then
cmd="\$cmd --delay=${DELAY}"
fi
mkdir -p /app/guides
if [ -n "${LANG}" ]; then
cmd="\$cmd --lang=${LANG}"
fi
if [ "${GZIP}" = "true" ]; then
cmd="\$cmd --gzip"
fi
# Execute the command
eval \$cmd
echo "Completed grab for site: \$site"
) &
fi
done </tmp/sites.txt
# Wait for all background processes to complete
wait
echo "All EPG data grabs completed"
EOL
chmod +x /tmp/grab_all.sh
/tmp/grab_all.sh
# Clean up
rm /tmp/sites.txt /tmp/grab_all.sh
}
# Create output directory if it doesn't exist
mkdir -p /app/output
# Initial grab
if [ -n "$SITES" ]; then
echo "Starting initial EPG data grab for all sites concurrently"
grab_all_sites
echo "Starting initial EPG data grab for sites: $SITES"
grab_epg
fi
# Set up cron job using PM2
if [ -n "$CRON_SCHEDULE" ] && [ -n "$SITES" ]; then
echo "Setting up cron job with schedule: $CRON_SCHEDULE"
# Create a script to grab all sites concurrently
cat >/app/grab-sites.js <<EOL
#!/usr/bin/env node
const { spawn } = require('child_process');
// Store environment variables at the beginning
const envSites = process.env.SITES || '';
const maxConnections = process.env.MAX_CONNECTIONS || 1;
const days = process.env.DAYS;
const delay = process.env.DELAY;
const lang = process.env.LANG;
const gzip = process.env.GZIP === 'true';
const sites = envSites.split(',').filter(site => site.trim() !== '');
console.log(\`Starting scheduled EPG grab at \${new Date().toISOString()}\`);
// Track running processes
let completedCount = 0;
sites.forEach(site => {
try {
console.log(\`Starting grab for site: \${site}\`);
let cmd = 'npm';
let args = ['run', 'grab', '--', \`--site=\${site}\`, \`--output=output/\${site}.xml\`, \`--maxConnections=\${maxConnections}\`];
// Add optional parameters
if (days) args.push(\`--days=\${days}\`);
if (delay) args.push(\`--delay=\${delay}\`);
if (lang) args.push(\`--lang=\${lang}\`);
if (gzip) args.push('--gzip');
const process = spawn(cmd, args, { stdio: 'inherit' });
process.on('close', (code) => {
completedCount++;
if (code === 0) {
console.log(\`Successfully grabbed EPG data for site: \${site}\`);
} else {
console.error(\`Error grabbing EPG data for site: \${site}, exit code: \${code}\`);
}
if (completedCount === sites.length) {
console.log(\`Completed scheduled EPG grab at \${new Date().toISOString()}\`);
}
});
} catch (error) {
console.error(\`Error starting EPG grab for site: \${site}\`, error);
completedCount++;
}
});
EOL
chmod +x /app/grab-sites.js
# Start the cron job
pm2 start --name epg-grabber /app/grab-sites.js --no-autorestart --cron-restart="$CRON_SCHEDULE"
pm2 start --name epg-grabber /app/entrypoint.sh --no-autorestart --cron-restart="$CRON_SCHEDULE" -- grab
pm2 logs epg-grabber &
fi
# Start the server to serve the guide files
echo "Starting server on port 3000 to serve EPG files from /app/output"
npx serve -p 3000 /app/output &
echo "Starting server on port 3000 to serve EPG files from /app/guides"
npx serve -p 3000 /app/guides &
# Keep the container running
tail -f /dev/null