From 45b7b27e8680533e83ffd2ad198d7cb0321524e1 Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 28 Jul 2023 00:30:29 +0700 Subject: [PATCH] add hook listening server to trigger refresh --- Dockerfile | 25 +++++++++++++++++++++---- app/main.py | 8 ++++---- app/server.py | 19 +++++++++++++++++++ deploy.sh | 36 +++++++++++++++++++++++++++++++----- docker-compose.yml | 32 +++++++++++++++++++++----------- requirements.txt | 3 ++- 6 files changed, 98 insertions(+), 25 deletions(-) create mode 100644 app/server.py diff --git a/Dockerfile b/Dockerfile index 2d6ce0d..5e43826 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,21 @@ -FROM python:3.10.9-slim-bullseye -COPY . /jellyfin -WORKDIR jellyfin -RUN pip install -r requirements.txt +FROM python:3.11.3-slim-bullseye +ARG INSTALL_DEBUG +ENV PYTHONUNBUFFERED 1 + +# install debug tools for testing environment +RUN if [ "$INSTALL_DEBUG" ] ; then \ + apt-get -y update && apt-get -y install --no-install-recommends \ + vim htop bmon net-tools iputils-ping procps \ + && pip install --user ipython \ + ; fi + +# install requirements +COPY ./requirements.txt /requirements.txt +RUN pip install --user -r requirements.txt + +COPY app /app +WORKDIR app + +VOLUME /youtube + +CMD ["python", "server.py"] diff --git a/app/main.py b/app/main.py index eaddd28..72986ac 100644 --- a/app/main.py +++ b/app/main.py @@ -3,13 +3,13 @@ from src.connect import Jellyfin, TubeArchivist, env_check from src.series import Library -env_check() -Jellyfin().ping() -TubeArchivist().ping() - def main(): """main thread""" + env_check() + Jellyfin().ping() + TubeArchivist().ping() + library = Library() library.validate_series() diff --git a/app/server.py b/app/server.py new file mode 100644 index 0000000..4640474 --- /dev/null +++ b/app/server.py @@ -0,0 +1,19 @@ +"""wait for hooks""" + +from flask import Flask +from main import main as run_refresh + +app = Flask(__name__) + + +@app.route("/", methods=["POST"]) +def home(): + """handle post grequest""" + run_refresh() + + return "success" + + +if __name__ == "__main__": + PORT = 8080 + app.run(host="0.0.0.0", port=PORT) diff --git a/deploy.sh b/deploy.sh index 1a07ca3..a4229c2 100755 --- a/deploy.sh +++ b/deploy.sh @@ -15,22 +15,48 @@ function validate { # note: this logic is duplicated in the `./github/workflows/lint_python.yml` config # if you update this file, you should update that as well echo "running black" - black --exclude "migrations/*" --diff --color --check -l 79 "$check_path" + black --force-exclude "migrations/*" --diff --color --check -l 79 "$check_path" echo "running codespell" - codespell --skip="./.git,./package.json,./package-lock.json,./node_modules,./.mypy_cache" "$check_path" + codespell --skip="./.git,./.venv,./.mypy_cache" "$check_path" echo "running flake8" - flake8 "$check_path" --exclude "migrations" --count --max-complexity=10 \ + flake8 "$check_path" --exclude "migrations,.venv" --count --max-complexity=10 \ --max-line-length=79 --show-source --statistics echo "running isort" - isort --skip "migrations" --check-only --diff --profile black -l 79 "$check_path" + isort --skip "migrations" --skip ".venv" --check-only --diff --profile black -l 79 "$check_path" printf " \n> all validations passed\n" } +function sync_test { + + # docker commands don't need sudo in testing vm + + host="tubearchivist.local" + # make base folder + ssh "$host" "mkdir -p docker" + + # copy project files to build image + rsync -a --progress --delete-after \ + --exclude ".git" \ + --exclude ".gitignore" \ + --exclude "**/cache" \ + --exclude "**/__pycache__/" \ + --exclude ".venv" \ + --exclude "db.sqlite3" \ + --exclude ".mypy_cache" \ + . -e ssh "$host":tubearchivist-jf + + ssh "$host" "docker buildx build --build-arg INSTALL_DEBUG=1 -t bbilly1/tubearchivist-jf:latest tubearchivist-jf --load" + ssh "$host" 'docker compose -f docker/docker-compose.yml up -d' + +} + if [[ $1 == "validate" ]]; then validate "$2" +elif [[ $1 == "test" ]]; then + sync_test else - echo "valid options are: validate" + echo "valid options are: validate | test" fi diff --git a/docker-compose.yml b/docker-compose.yml index 4ac89c9..7f27fea 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,13 +1,23 @@ +version: '3.3' + services: - ta-jf: - build: ./ + jellyfin: + image: jellyfin/jellyfin + container_name: jellyfin + restart: unless-stopped + ports: + - 8096:8096 + volumes: + - ./jellyfin/config:/config + - ./jellyfin/cache:/cache + - ./tubearchivist/youtube:/media/youtube:ro + tubearchivist-jf: + image: bbilly1/tubearchivist-jf + container_name: tubearchivist-jf environment: - - TA_VIDEO_PATH="/youtube" - - TA_URL="http://tubearchivist.local" - - TA_TOKEN="xxxxxxxxxxxxxxxx" - - JF_URL="http://jellyfin.local:8096" - - JF_TOKEN="yyyyyyyyyyyyyyyy" -# volumes: -# - ./config.json:/jellyfin/config.json:ro -# - /youtube:/youtube - command: python main.py + - TA_URL=http://tubearchivist:8000 + - TA_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + - JF_URL=http://jellyfin:8096 + - JF_TOKEN=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy + volumes: + - ./tubearchivist/youtube:/youtube diff --git a/requirements.txt b/requirements.txt index 663bd1f..85826af 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -requests \ No newline at end of file +requests==2.31.0 +Flask==2.3.2