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 # Install required packages
RUN apk add --no-cache git curl unzip coreutils 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 && \
npm install pm2 serve -g npm install pm2 serve -g
# Create output directory # Create guides directory
RUN mkdir -p /app/output RUN mkdir -p /app/guides
# Copy entrypoint script # Copy entrypoint script
COPY entrypoint.sh /app/entrypoint.sh COPY entrypoint.sh /app/entrypoint.sh
+48 -131
View File
@@ -1,162 +1,79 @@
#!/bin/sh #!/bin/sh
set -e 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() { grab_epg() {
site=$1 cmd="npm run grab --"
echo "Grabbing EPG data for site: $site"
# Build command with optional parameters if [ -n "$SITES" ]; then
cmd="npm run grab -- --site=$site --output=output/${site}.xml --maxConnections=${MAX_CONNECTIONS}" 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 if [ -n "$DAYS" ]; then
cmd="$cmd --days=${DAYS}" cmd="$cmd --days=$DAYS"
fi fi
if [ -n "$TIMEOUT" ]; then
if [ -n "$DELAY" ]; then cmd="$cmd --timeout=$TIMEOUT"
cmd="$cmd --delay=${DELAY}" fi
if [ -n "$DELAY" ] && [ "$DELAY" != "0" ]; then
cmd="$cmd --delay=$DELAY"
fi fi
if [ -n "$LANG" ]; then if [ -n "$LANG" ]; then
cmd="$cmd --lang=${LANG}" cmd="$cmd --lang=$LANG"
fi
if [ -n "$PROXY" ]; then
cmd="$cmd --proxy=$PROXY"
fi fi
if [ "$GZIP" = "true" ]; then if [ "$GZIP" = "true" ]; then
cmd="$cmd --gzip" cmd="$cmd --gzip"
fi 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 eval $cmd
} }
# Function to grab EPG data for all sites concurrently if [ "$1" = "grab" ]; then
grab_all_sites() { grab_epg
# Split the SITES environment variable by comma - POSIX sh compatible exit 0
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}"
fi fi
if [ -n "${DELAY}" ]; then mkdir -p /app/guides
cmd="\$cmd --delay=${DELAY}"
fi
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 if [ -n "$SITES" ]; then
echo "Starting initial EPG data grab for all sites concurrently" echo "Starting initial EPG data grab for sites: $SITES"
grab_all_sites grab_epg
fi fi
# Set up cron job using PM2
if [ -n "$CRON_SCHEDULE" ] && [ -n "$SITES" ]; then if [ -n "$CRON_SCHEDULE" ] && [ -n "$SITES" ]; then
echo "Setting up cron job with schedule: $CRON_SCHEDULE" echo "Setting up cron job with schedule: $CRON_SCHEDULE"
pm2 start --name epg-grabber /app/entrypoint.sh --no-autorestart --cron-restart="$CRON_SCHEDULE" -- grab
# 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 logs epg-grabber & pm2 logs epg-grabber &
fi fi
# Start the server to serve the guide files echo "Starting server on port 3000 to serve EPG files from /app/guides"
echo "Starting server on port 3000 to serve EPG files from /app/output" npx serve -p 3000 /app/guides &
npx serve -p 3000 /app/output &
# Keep the container running
tail -f /dev/null tail -f /dev/null