fix hot patch

This commit is contained in:
BennyThink 2022-02-11 20:11:17 +08:00
parent a3a821bfae
commit 9d2b532d21
No known key found for this signature in database
GPG Key ID: 6CD0DBDA5235D481
4 changed files with 13 additions and 9 deletions

View File

@ -9,7 +9,8 @@ FROM python:3.9-alpine
WORKDIR /ytdlbot/ytdlbot WORKDIR /ytdlbot/ytdlbot
ENV TZ=Asia/Shanghai 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 /root/.local /usr/local
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo

1
apk.txt Normal file
View File

@ -0,0 +1 @@
ffmpeg vnstat git

View File

@ -323,21 +323,23 @@ def ytdl_normal_download(bot_msg, client, url):
@Panel.register @Panel.register
def hot_patch(*args): def hot_patch(*args):
git_path = pathlib.Path().cwd().parent app_path = pathlib.Path().cwd().parent
logging.info("Hot patching on path %s...", git_path) logging.info("Hot patching on path %s...", app_path)
apk_install = "xargs apk add < apk.txt"
pip_install = "pip install -r requirements.txt" pip_install = "pip install -r requirements.txt"
unset = "git config --unset http.https://github.com/.extraheader" unset = "git config --unset http.https://github.com/.extraheader"
pull_unshallow = "git pull origin --unshallow" pull_unshallow = "git pull origin --unshallow"
pull = "git pull" pull = "git pull"
subprocess.call(pip_install, shell=True, cwd=git_path) subprocess.check_output(unset, shell=True, cwd=app_path)
subprocess.call(unset, shell=True, cwd=git_path) if subprocess.check_output(pull_unshallow, shell=True, cwd=app_path) != 0:
if subprocess.call(pull_unshallow, shell=True, cwd=git_path) != 0:
logging.info("Already unshallow, pulling now...") 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...") 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() psutil.Process().kill()

View File

@ -138,8 +138,8 @@ def patch_handler(client: "Client", message: "types.Message"):
if username == OWNER: if username == OWNER:
celery_app.control.broadcast("hot_patch") celery_app.control.broadcast("hot_patch")
client.send_chat_action(chat_id, "typing") client.send_chat_action(chat_id, "typing")
hot_patch()
client.send_message(chat_id, "Oorah!") client.send_message(chat_id, "Oorah!")
hot_patch()
@app.on_message(filters.command(["ping"])) @app.on_message(filters.command(["ping"]))