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: commands:
- rm -rf .git* - rm -rf .git*
- rm -rf web - 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 . - tar -czf /tmp/botamusique/sources-testing.tar.gz .
volumes: volumes:
- name: repo - name: repo
@ -46,12 +54,34 @@ steps:
event: event:
- push - push
- name: fetch
image: alpine/git
commands:
- git fetch --tags
when:
branch:
- master
event:
- tag
- name: deploy-stable - name: deploy-stable
image: debian image: debian
commands: commands:
- apt -qq update && apt -q -y install jq curl
- rm -rf .git* - rm -rf .git*
- rm -rf web - 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 . - tar -czf /tmp/botamusique/sources-stable.tar.gz .
volumes: volumes:
- name: repo - name: repo
path: /tmp/botamusique/ path: /tmp/botamusique/

View File

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

View File

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

View File

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

19
util.py
View File

@ -100,7 +100,10 @@ def get_user_ban():
return res return res
def new_release_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") r = requests.get("https://packages.azlux.fr/botamusique/version")
v = r.text v = r.text
return v.rstrip() return v.rstrip()
@ -115,26 +118,28 @@ def fetch_changelog():
def update(current_version): def update(current_version):
global log global log
new_version = new_release_version()
target = var.config.get('bot', 'target_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...') log.info('update: new version, start updating...')
tp = sp.check_output(['/usr/bin/env', 'bash', 'update.sh', target]).decode() tp = sp.check_output(['/usr/bin/env', 'bash', 'update.sh', target]).decode()
log.debug(tp) log.debug(tp)
log.info('update: update pip libraries dependencies') log.info('update: update pip libraries dependencies')
sp.check_output([var.config.get('bot', 'pip3_path'), 'install', '--upgrade', '-r', 'requirements.txt']).decode() sp.check_output([var.config.get('bot', 'pip3_path'), 'install', '--upgrade', '-r', 'requirements.txt']).decode()
msg = "New version installed, please restart the bot." msg = "New version installed, please restart the bot."
if target == "testing":
msg += tp.replace('\n', '<br/>')
else:
log.info('update: starting update youtube-dl via pip3') log.info('update: starting update youtube-dl via pip3')
tp = sp.check_output([var.config.get('bot', 'pip3_path'), 'install', '--upgrade', 'youtube-dl']).decode() tp = sp.check_output([var.config.get('bot', 'pip3_path'), 'install', '--upgrade', 'youtube-dl']).decode()
msg = ""
if "Requirement already up-to-date" in tp: if "Requirement already up-to-date" in tp:
msg += "Youtube-dl is up-to-date" msg += "Youtube-dl is up-to-date"
else: else:
msg += "Update done: " + tp.split('Successfully installed')[1] msg += "Update done: " + tp.split('Successfully installed')[1]
reload(youtube_dl) reload(youtube_dl)
msg += "<br/> Youtube-dl reloaded" msg += "<br/> Youtube-dl reloaded"
return msg return msg