update to latest version
Build and Push Docker Images / build-and-push (push) Successful in 2m4s

This commit is contained in:
2025-04-19 21:28:41 +02:00
parent 1b3676371c
commit 0234bce8ce
2 changed files with 89 additions and 24 deletions
+5 -5
View File
@@ -6,14 +6,14 @@ RUN apk add --no-cache git curl unzip coreutils
# Set working directory # Set working directory
WORKDIR /app WORKDIR /app
# Download and extract the EPG repository # Clone the latest EPG repository code
RUN curl -L https://github.com/iptv-org/epg/archive/refs/tags/2023.12.1.zip -o epg.zip && \ RUN git clone --depth 1 -b master https://github.com/iptv-org/epg.git . && \
unzip epg.zip && \
mv epg-2023.12.1/* ./ && \
rm -rf epg.zip epg-2023.12.1 && \
npm install && \ npm install && \
npm install pm2 serve -g npm install pm2 serve -g
# Create output directory
RUN mkdir -p /app/output
# Copy entrypoint script # Copy entrypoint script
COPY entrypoint.sh /app/entrypoint.sh COPY entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh RUN chmod +x /app/entrypoint.sh
+84 -19
View File
@@ -30,22 +30,64 @@ grab_epg() {
eval $cmd eval $cmd
} }
# Function to grab EPG data for all sites # Function to grab EPG data for all sites concurrently
grab_all_sites() { grab_all_sites() {
# Split the SITES environment variable by comma - POSIX sh compatible # Split the SITES environment variable by comma - POSIX sh compatible
echo "$SITES" | tr ',' '\n' >/tmp/sites.txt echo "$SITES" | tr ',' '\n' >/tmp/sites.txt
# Process each site # Create a temporary script to run all grab commands
while read site; do cat >/tmp/grab_all.sh <<EOL
grab_epg "$site" #!/bin/sh
done </tmp/sites.txt # 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
if [ -n "${DELAY}" ]; then
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 # Clean up
rm /tmp/sites.txt rm /tmp/sites.txt /tmp/grab_all.sh
} }
# Create output directory if it doesn't exist
mkdir -p /app/output
# Initial grab # Initial grab
if [ -n "$SITES" ]; then if [ -n "$SITES" ]; then
echo "Starting initial EPG data grab for all sites concurrently"
grab_all_sites grab_all_sites
fi fi
@@ -53,27 +95,50 @@ fi
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"
# Create a script to grab all sites # Create a script to grab all sites concurrently
cat >/app/grab-sites.js <<EOL cat >/app/grab-sites.js <<EOL
#!/usr/bin/env node #!/usr/bin/env node
const { execSync } = require('child_process'); const { execSync } = require('child_process');
const sites = process.env.SITES.split(','); const { spawn } = require('child_process');
const sites = process.env.SITES.split(',').filter(site => site.trim() !== '');
console.log(\`Starting scheduled EPG grab at \${new Date().toISOString()}\`);
// Track running processes
const processes = [];
let completedCount = 0;
sites.forEach(site => { sites.forEach(site => {
try { try {
console.log(\`Grabbing EPG data for site: \${site}\`); console.log(\`Starting grab for site: \${site}\`);
let cmd = \`npm run grab -- --site=\${site} --output=output/\${site}.xml --maxConnections=\${process.env.MAX_CONNECTIONS || 1}\`; let cmd = 'npm';
let args = ['run', 'grab', '--', \`--site=\${site}\`, \`--output=output/\${site}.xml\`, \`--maxConnections=\${process.env.MAX_CONNECTIONS || 1}\`];
// Add optional parameters // Add optional parameters
if (process.env.DAYS) cmd += \` --days=\${process.env.DAYS}\`; if (process.env.DAYS) args.push(\`--days=\${process.env.DAYS}\`);
if (process.env.DELAY) cmd += \` --delay=\${process.env.DELAY}\`; if (process.env.DELAY) args.push(\`--delay=\${process.env.DELAY}\`);
if (process.env.LANG) cmd += \` --lang=\${process.env.LANG}\`; if (process.env.LANG) args.push(\`--lang=\${process.env.LANG}\`);
if (process.env.GZIP === 'true') cmd += \` --gzip\`; if (process.env.GZIP === 'true') args.push('--gzip');
execSync(cmd, { stdio: 'inherit' }); 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()}\`);
}
});
processes.push(process);
} catch (error) { } catch (error) {
console.error(\`Error grabbing EPG data for site: \${site}\`, error); console.error(\`Error starting EPG grab for site: \${site}\`, error);
completedCount++;
} }
}); });
EOL EOL
@@ -81,12 +146,12 @@ EOL
# Start the cron job # 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/grab-sites.js --no-autorestart --cron-restart="$CRON_SCHEDULE"
pm2 logs epg-grabber &
fi fi
# Start the server to serve the guide files # Start the server to serve the guide files
cd /app echo "Starting server on port 3000 to serve EPG files from /app/output"
echo "Starting server on port 3000" npx serve -p 3000 /app/output &
npx serve -p 3000
# Keep the container running # Keep the container running
tail -f /dev/null tail -f /dev/null