Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EPG usage in Docker. #2488

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

tohenk
Copy link
Collaborator

@tohenk tohenk commented Dec 2, 2024

It doesn't hurt to let people know how to use EPG in Docker.

It doesn't hurt to let people know how to use EPG in Docker.

Signed-off-by: Toha <[email protected]>
@davidclaeysquinones
Copy link
Contributor

davidclaeysquinones commented Dec 2, 2024

I did something very similar to you at this repo of mine.
Instead of containing some scripts to run it in Docker it's a precompiled image.

Maybe the way I build the image isn't the best (in that case feel free to reach out), but I think it offers the advantage of being easier to deploy.

I think that using Docker for deployment is a really good idea, so at some point I build an image for it.
As long as a good technical solution is found I don't really to take any credit.

Copy link
Contributor

@BellezaEmporium BellezaEmporium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally do not mind having this in the README, now it'll be up to @freearhey to see if it fits better in /epg or in /awesome-iptv

@freearhey
Copy link
Collaborator

I'm in favor of the iptv-org/awesome-iptv or you can create docker-compose.yml directly in iptv-org/epg and refer to it.

@davidclaeysquinones
Copy link
Contributor

Tbh I don't really understand why the iptv-org/epg repo doesn't contain a Dockerfile.
Instead of linking an external repo it could just be included in the official one.

Furthermore I think that a precompiled image would be much more desirable.
How that image is made might be up for debate, but I think it's undebatable that's a much simpler solution.

Instead of looking like this :

services:
  cron:
    image: debian:bookworm-slim
    container_name: ${APP_NAME}-cron
    restart: unless-stopped
    command:
      - /bin/bash
      - '-c'
      - |
        export CRON_USER=epg
        export CRON_DIR=/cron
        export TARGET_DIR=$${CRON_DIR}
        export ENV_FILE_PATTERN=/scripts/*.env
        export APT_PACKAGES=git
        adduser --disabled-password --gecos $$CRON_USER --quiet $$CRON_USER
        # run initialization
        run-script.sh timezone genenv apt nodejs cron cleanlock setowner +viewlog
        # start cron
        echo "Starting cron..."
        cron -f -L 15
    environment:
      APP_TIMEZONE: ${APP_TIMEZONE}
      APP_GUIDES_DIR: ${APP_GUIDES_DIR}
      APT_MIRROR: ${APT_MIRROR}
      NODE_VERSION: ${NODE_VERSION}
    volumes:
      - ./bin/run-script.sh:/usr/local/bin/run-script.sh
      - ./build:/build
      - ./cron:/cron
      - ./scripts:/scripts
  nginx:
    image: nginx
    container_name: ${APP_NAME}-web
    restart: unless-stopped
    command:
      - /bin/bash
      - '-c'
      - |
        # run initialization
        run-script.sh timezone
        # run entrypoint
        /docker-entrypoint.sh nginx -g "daemon off;"
    ports:
      - ${APP_HTTP_PORT}:80
    environment:
      APP_TIMEZONE: ${APP_TIMEZONE}
      APP_GUIDES_DIR: ${APP_GUIDES_DIR}
    volumes:
      - ./bin/run-script.sh:/usr/local/bin/run-script.sh
      - ./build:/build
      - ./scripts:/scripts
      - ./templates:/etc/nginx/templates

The image could look like this :

version: '3.3'
services:
  epg:
    image: imageName
    volumes:
      # add a mapping in order to add the channels file
      - /docker/epg:/config
    ports:
      - 6080:3000
    environment:
      # specify the time zone for the server
      - TZ=Etc/UTC
    restart: unless-stopped

Further more using an alpine based image would reduce the size considerably.

@BellezaEmporium
Copy link
Contributor

For me, it doesn't hurt having a Dockerfile inside iptv-org/epg. After all, since we cannot make the EPGs ourselves via GH, we can give a much more convenient way for people to generate them (even adding crons and maintaining a little live server which scrapes EPGs periodically !)

@davidclaeysquinones
Copy link
Contributor

davidclaeysquinones commented Dec 18, 2024

For me, it doesn't hurt having a Dockerfile inside iptv-org/epg. After all, since we cannot make the EPGs ourselves via GH, we can give a much more convenient way for people to generate them (even adding crons and maintaining a little live server which scrapes EPGs periodically !)

That is exactly what I was thinking.
As I wanted to imply earlier feel free to take the Dockerfile out of my repo and to modify it as fits.

The reason I haven't submitted a PR myself is because I wanted to discuss it before.
I was afraid there is a reason this repo cannot include a Dockerfile and that my work wasn't ready for prime time.
If the maintainers give a heads up I'm more than happy to submit a PR.

@davidclaeysquinones
Copy link
Contributor

Let me make a proposal about how to make a Docker image.

First of all we would need a serve.json file that looks like this :

{
    "symlinks": true,
    "public": "/public"
}

The reasoning behind this is that we don't want to serve all the files to the outside world. Later on we will create symbolic links into the /public directory.

Secondly comes the start.sh script that will be the entry-point of our image :

#!/bin/bash

# Loop through arguments
for arg in "$@"; do
   case "$arg" in
      chron-schedule=*) chron_schedule="${arg#*=}" ;;
      work-dir=*) work_dir="${arg#*=}" ;;
      days=*) days="${arg#*=}" ;;
      max_connections=*) max_connections="${arg#*=}" ;;
      api_url=*) api_url="${arg#*=}" ;;
   esac
done

echo "chron_schedule : ${chron_schedule}"
cd $work_dir
echo "working dir : " $(pwd)
echo "days : ${days}"
echo "max_connections : ${max_connections}"
echo "api url : ${api_url}"

# fill in the specified value for the api to retrieve program data
sed -i -E "s/(https:\x2f\x2fiptv-org.github.io\x2fapi)/$api_url/g" $work_dir/scripts/core/apiClient.ts

# serve the application with the pm2 module
pm2 --name epg start npm -- run serve
# run first grab on start
npm run grab --- --channels=channels.xml --maxConnections=$max_connections --days=$days --gzip
# create simbolyc links into the public directory
ln -s $work_dir/guide.xml /public/guide.xml
ln -s $work_dir/guide.xml.gz /public/guide.xml.gz
# schedule grabbing program data 
npm run grab --- --channels=channels.xml --cron="$chron_schedule" --maxConnections=$max_connections --days=$days --gzip

And last but not least the Dockerfile would look like this :
(a channels.xml file needs to be added)

FROM node:22-alpine
ARG GIT_REPO=https://github.com/iptv-org/epg.git
ARG GIT_BRANCH=master
ENV CRON_SCHEDULE="0 0,12 * * *"
ENV API_URL="https://iptv-org.github.io/api"
ENV DAYS=14
ENV MAX_CONNECTIONS=10
ARG BIN_FOLDER=/bin
ARG EPG_FOLDER=epg
ARG START_SCRIPT_ARG=$BIN_FOLDER/$EPG_FOLDER/start.sh
ENV WORKDIR=${BIN_FOLDER}/${EPG_FOLDER}
ENV START_SCRIPT=$START_SCRIPT_ARG
COPY channels.xml /config/channels.xml
RUN apk update \
    && apk upgrade --available \
    && apk add curl git tzdata bash \
    && npm install -g npm@latest \
    && npm install pm2 -g \
    && mkdir $(echo "${BIN_FOLDER}/${EPG_FOLDER}") -p \
    && git -C $(echo "${BIN_FOLDER}") clone --depth 1 -b $(echo "${GIT_BRANCH} ${GIT_REPO}") \
    && cd $WORKDIR && npm install && npm update \ 
    && rm .eslintrc.json \
    && rm -rf .github \
    && rm -rf .git \
    && rm .gitignore  \
    && rm CONTRIBUTING.md  \
    && rm LICENSE \
    && rm README.md \
    && rm SITES.md \
    && rm -rf tests \
    && rm sites/**/readme.md \
    && rm -rf sites/**/__data__ \
    && rm sites/**/**.test.js \
    && rm -rf node_modules/**/.package-lock.json \
    && rm -rf node_modules/**/.tsconfig.json \
    && rm -rf node_modules/**/.tsconfig.tsbuildinfo.json \
    && rm -rf node_modules/**/.github \
    && rm -rf node_modules/**/docs \
    && rm -rf node_modules/**/LICENSE \
    && rm -rf node_modules/**/**.md \
    && ln -s /config/channels.xml $(echo "${WORKDIR}/channels.xml") \
    && mkdir /public
COPY start.sh $WORKDIR
COPY serve.json $WORKDIR
RUN chmod +x "$START_SCRIPT" \
  && apk del git curl \
  && rm -rf /var/cache/apk/*
SHELL ["/bin/bash", "-c"]
ENTRYPOINT bash $START_SCRIPT chron-schedule="$CRON_SCHEDULE" work-dir="$WORKDIR" days="$DAYS" max_connections="$MAX_CONNECTIONS" api_url="$API_URL"
EXPOSE 3000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants