add upgrade actions, add Makefile

This commit is contained in:
BennyThink 2022-01-03 10:26:03 +08:00
parent 2961fb22a8
commit 95b5ed5705
No known key found for this signature in database
GPG Key ID: 6CD0DBDA5235D481
8 changed files with 78 additions and 4 deletions

View File

@ -1,2 +1,4 @@
env
db_data
.ash_history
.DS_Store

24
.github/workflows/upgrade.yml vendored Normal file
View File

@ -0,0 +1,24 @@
name: Upgrade
on:
push:
tags:
- "v*"
jobs:
update:
runs-on: ubuntu-latest
steps:
- name: executing remote ssh commands using ssh key
uses: appleboy/ssh-action@master
env:
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
with:
envs: BOT_TOKEN
host: ${{ secrets.YTDL_BOT_HOST }}
username: root
key: ${{ secrets.SSH_KEY }}
script: |
make bot
make upgrade-all-worker
curl "https://api.telegram.org/bot$BOT_TOKEN/sendMessage?chat_id=260260121&text=ytdl%20upgrade%20complete!"
echo "YouTube Download upgrade complete!"

3
.gitignore vendored
View File

@ -154,5 +154,8 @@ dmypy.json
db_data/*
env/*
.ash_history
.DS_Store
ytdlbot/ytdl.session
data/*
upgrade_worker.sh
ytdl.session

View File

@ -9,7 +9,7 @@ FROM python:3.9-alpine
WORKDIR /ytdlbot/ytdlbot
ENV TZ=Asia/Shanghai
RUN apk update && apk add --no-cache ffmpeg vnstat
RUN apk update && apk add --no-cache ffmpeg vnstat git
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

26
Makefile Normal file
View File

@ -0,0 +1,26 @@
default:
docker pull bennythink/ytdlbot
bot:
make
docker-compose up -d
docker system prune -a --volumes -f
worker:
make
docker-compose -f worker.yml up -d
docker system prune -a --volumes -f
sleep 5
weak-worker:
make
docker-compose --compatibility -f worker.yml up -d
docker system prune -a --volumes -f
sleep 5
upgrade-all-worker:
bash upgrade_worker.sh
tag:
git tag -a v$(date "+%Y-%m-%d") -m v$(date "+%Y-%m-%d")
git push --tags

View File

@ -159,6 +159,18 @@ vim data/instagram.com_cookies.txt
In `flower` service section, you may want to change your basic authentication username password and publish port.
You can also limit CPU and RAM usage by adding an `deploy' key:
```docker
deploy:
resources:
limits:
cpus: '0.5'
memory: 1500M
```
Be sure to use `--compatibility` when deploying.
## 4. run
### 4.1. standalone mode

View File

@ -9,6 +9,7 @@ __author__ = "Benny <benny.think@gmail.com>"
import logging
import pathlib
import subprocess
import time
import uuid
@ -97,3 +98,7 @@ def current_time():
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
def get_revision_tag():
revision = subprocess.check_output("git -C ../ rev-parse --short HEAD".split()).decode("u8").replace("\n", "")
tag = subprocess.check_output("git -C ../ describe --tags".split()).decode("u8").replace("\n", "")
return revision, tag

View File

@ -27,7 +27,7 @@ from db import MySQL, Redis
from downloader import convert_flac
from limit import verify_payment
from tasks import download_entrance
from utils import customize_logger, get_user_settings, set_user_settings
from utils import customize_logger, get_user_settings, set_user_settings, get_revision_tag
customize_logger(["pyrogram.client", "pyrogram.session.session", "pyrogram.connection.connection"])
app = create_app()
@ -219,6 +219,7 @@ def audio_callback(client: "Client", callback_query: types.CallbackQuery):
if __name__ == '__main__':
MySQL()
revision_tag = get_revision_tag()
scheduler = BackgroundScheduler()
scheduler.add_job(Redis().reset_today, 'cron', hour=0, minute=0)
scheduler.start()
@ -229,6 +230,7 @@ if __name__ == '__main__':
By @BennyThink, VIP mode: {ENABLE_VIP}, Distribution: {ENABLE_CELERY}
Version: {revision_tag[0]}@{revision_tag[1]}
"""
print(banner)
app.run()