diff --git a/Dockerfile b/Dockerfile index 19b5095..918b8dd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,10 +9,11 @@ FROM python:3.9-alpine WORKDIR /ytdlbot/ytdlbot ENV TZ=Asia/Shanghai -RUN apk update && apk add --no-cache ffmpeg vnstat git +COPY apk.txt /tmp/ +RUN apk update && xargs apk add < /tmp/apk.txt COPY --from=builder /root/.local /usr/local COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo COPY . /ytdlbot -CMD ["/usr/local/bin/supervisord", "-c" ,"/ytdlbot/conf/supervisor_main.conf"] \ No newline at end of file +CMD ["/usr/local/bin/supervisord", "-c" ,"/ytdlbot/conf/supervisor_main.conf"] diff --git a/apk.txt b/apk.txt new file mode 100644 index 0000000..fd936fe --- /dev/null +++ b/apk.txt @@ -0,0 +1 @@ +ffmpeg vnstat git \ No newline at end of file diff --git a/ytdlbot/tasks.py b/ytdlbot/tasks.py index ad5c1cd..c53e6aa 100644 --- a/ytdlbot/tasks.py +++ b/ytdlbot/tasks.py @@ -323,21 +323,23 @@ def ytdl_normal_download(bot_msg, client, url): @Panel.register def hot_patch(*args): - git_path = pathlib.Path().cwd().parent - logging.info("Hot patching on path %s...", git_path) + app_path = pathlib.Path().cwd().parent + logging.info("Hot patching on path %s...", app_path) + apk_install = "xargs apk add < apk.txt" pip_install = "pip install -r requirements.txt" unset = "git config --unset http.https://github.com/.extraheader" pull_unshallow = "git pull origin --unshallow" pull = "git pull" - subprocess.call(pip_install, shell=True, cwd=git_path) - subprocess.call(unset, shell=True, cwd=git_path) - if subprocess.call(pull_unshallow, shell=True, cwd=git_path) != 0: + subprocess.check_output(unset, shell=True, cwd=app_path) + if subprocess.check_output(pull_unshallow, shell=True, cwd=app_path) != 0: logging.info("Already unshallow, pulling now...") - subprocess.call(pull, shell=True, cwd=git_path) + subprocess.check_output(pull, shell=True, cwd=app_path) logging.info("Code is updated, applying hot patch now...") + subprocess.check_output(apk_install, shell=True, cwd=app_path) + subprocess.check_output(pip_install, shell=True, cwd=app_path) psutil.Process().kill() diff --git a/ytdlbot/ytdl_bot.py b/ytdlbot/ytdl_bot.py index b2d5761..c1e7b0a 100644 --- a/ytdlbot/ytdl_bot.py +++ b/ytdlbot/ytdl_bot.py @@ -138,8 +138,8 @@ def patch_handler(client: "Client", message: "types.Message"): if username == OWNER: celery_app.control.broadcast("hot_patch") client.send_chat_action(chat_id, "typing") - hot_patch() client.send_message(chat_id, "Oorah!") + hot_patch() @app.on_message(filters.command(["ping"]))