New update method

manage testing deplyement
This commit is contained in:
Azlux 2020-06-23 12:38:02 +02:00
parent 5768f20053
commit ccbde28ef9
5 changed files with 59 additions and 21 deletions

View File

@ -21,6 +21,14 @@ steps:
commands:
- rm -rf .git*
- rm -rf web
- echo '#### REPLACE TARGET ####'
- sed -i 's/target_version = git/target_version = testing/' configuration.default.ini
- echo '#### REPLACE VERSION ####'
- version=$(git rev-parse HEAD)
- echo "current git commit is $version"
- echo $version > /tmp/botamusique/testing-version
- sed -i "s/version = 'git'/version = '$version'/" mumbleBot.py
- echo '#### DEPLOY SOURCES ####'
- tar -czf /tmp/botamusique/sources-testing.tar.gz .
volumes:
- name: repo
@ -46,12 +54,34 @@ steps:
event:
- push
- name: fetch
image: alpine/git
commands:
- git fetch --tags
when:
branch:
- master
event:
- tag
- name: deploy-stable
image: debian
commands:
- apt -qq update && apt -q -y install jq curl
- rm -rf .git*
- rm -rf web
- echo '#### REPLACE TARGET ####'
- sed -i 's/target_version = git/target_version = stable/' configuration.default.ini
- echo '#### REPLACE VERSION ####'
- version=$(git describe --abbrev=0 --tags)
- echo "version is $version"
- echo $version > /tmp/botamusique/version
- sed -i "s/version = 'git'/version = '$version'/" mumbleBot.py
- echo '#### REPLACE CHANGELOG ####'
- curl --silent "https://api.github.com/repos/azlux/botamusique/releases/latest") | jq -r '.body' > /tmp/botamusique/changelog
- echo '#### DEPLOY SOURCES ####'
- tar -czf /tmp/botamusique/sources-stable.tar.gz .
volumes:
- name: repo
path: /tmp/botamusique/

View File

@ -37,8 +37,8 @@ playback_mode = one-shot
autoplay_length = 5
clear_when_stop_in_oneshot = False
# target version, stable or testing (testing need to bot installed with git)
target_version = stable
# target version, stable/testing/git (git need to bot installed with git)
target_version = git
# Users allowed to kill the bot, or ban URLs.
admin = User1;User2;

View File

@ -32,7 +32,7 @@ from media.cache import MusicCache
class MumbleBot:
version = '6.5'
version = 'git'
def __init__(self, args):
self.log = logging.getLogger("bot")

View File

@ -9,8 +9,11 @@ case "$1" in
rm -r /tmp/botamusique.tar.gz
;;
testing)
git fetch
git pull --all
curl -Lo /tmp/botamusique.tar.gz https://packages.azlux.fr/botamusique/sources-testing.tar.gz
tar -xzf /tmp/botamusique.tar.gz -C /tmp/
cp -r /tmp/botamusique/* .
rm -r /tmp/botamusique
rm -r /tmp/botamusique.tar.gz
;;
*)
;;

37
util.py
View File

@ -100,8 +100,11 @@ def get_user_ban():
return res
def new_release_version():
r = requests.get("https://packages.azlux.fr/botamusique/version")
def new_release_version(target):
if target == "testing":
r = requests.get("https://packages.azlux.fr/botamusique/testing-version")
else:
r = requests.get("https://packages.azlux.fr/botamusique/version")
v = r.text
return v.rstrip()
@ -115,26 +118,28 @@ def fetch_changelog():
def update(current_version):
global log
new_version = new_release_version()
target = var.config.get('bot', 'target_version')
if version.parse(new_version) > version.parse(current_version) or target == "testing":
new_version = new_release_version(target)
msg = ""
if target == "git":
msg = "git install, I do nothing"
elif (target == "stable" and version.parse(new_version) > version.parse(current_version)) or \
(target == "testing" and version.parse(new_version) != version.parse(current_version)):
log.info('update: new version, start updating...')
tp = sp.check_output(['/usr/bin/env', 'bash', 'update.sh', target]).decode()
log.debug(tp)
log.info('update: update pip libraries dependencies')
sp.check_output([var.config.get('bot', 'pip3_path'), 'install', '--upgrade', '-r', 'requirements.txt']).decode()
msg = "New version installed, please restart the bot."
if target == "testing":
msg += tp.replace('\n', '<br/>')
log.info('update: starting update youtube-dl via pip3')
tp = sp.check_output([var.config.get('bot', 'pip3_path'), 'install', '--upgrade', 'youtube-dl']).decode()
if "Requirement already up-to-date" in tp:
msg += "Youtube-dl is up-to-date"
else:
log.info('update: starting update youtube-dl via pip3')
tp = sp.check_output([var.config.get('bot', 'pip3_path'), 'install', '--upgrade', 'youtube-dl']).decode()
msg = ""
if "Requirement already up-to-date" in tp:
msg += "Youtube-dl is up-to-date"
else:
msg += "Update done: " + tp.split('Successfully installed')[1]
msg += "Update done: " + tp.split('Successfully installed')[1]
reload(youtube_dl)
msg += "<br/> Youtube-dl reloaded"
return msg
@ -374,8 +379,8 @@ def parse_time(human):
def parse_file_size(human):
units = {"B": 1, "KB": 1024, "MB": 1024*1024, "GB": 1024*1024*1024, "TB": 1024*1024*1024*1024,
"K": 1024, "M": 1024*1024, "G": 1024*1024*1024, "T": 1024*1024*1024*1024}
units = {"B": 1, "KB": 1024, "MB": 1024 * 1024, "GB": 1024 * 1024 * 1024, "TB": 1024 * 1024 * 1024 * 1024,
"K": 1024, "M": 1024 * 1024, "G": 1024 * 1024 * 1024, "T": 1024 * 1024 * 1024 * 1024}
match = re.search("(\d+(?:\.\d*)?)\s*([A-Za-z]+)", human, flags=re.IGNORECASE)
if match:
num = float(match[1])
@ -417,7 +422,7 @@ class LoggerIOWrapper(io.TextIOWrapper):
class VolumeHelper:
def __init__(self, plain_volume = 0, ducking_plain_volume = 0):
def __init__(self, plain_volume=0, ducking_plain_volume=0):
self.plain_volume_set = 0
self.plain_ducking_volume_set = 0
self.volume_set = 0