From 8690d2ced5e5afe8c8f3342881d478fed37c274d Mon Sep 17 00:00:00 2001 From: TheMeanCanEHdian Date: Fri, 7 Feb 2020 08:30:47 -0800 Subject: [PATCH] Disable updates when using Docker container --- .github/workflows/publishdocker-branch.yml | 4 +- .github/workflows/publishdocker-release.yml | 6 +- Dockerfile | 5 +- data/interfaces/default/base.html | 48 +++++++------ data/interfaces/default/settings.html | 2 +- plexpy/config.py | 6 ++ plexpy/versioncheck.py | 29 +++++--- plexpy/webserve.py | 80 +++++++++++---------- 8 files changed, 104 insertions(+), 76 deletions(-) diff --git a/.github/workflows/publishdocker-branch.yml b/.github/workflows/publishdocker-branch.yml index cca935c0..0d2eb43c 100644 --- a/.github/workflows/publishdocker-branch.yml +++ b/.github/workflows/publishdocker-branch.yml @@ -5,6 +5,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@master + - name: Get branch + run: echo ::set-env name=BRANCH::${GITHUB_REF#refs/heads/} - name: Publish to Registry uses: elgohr/Publish-Docker-Github-Action@master env: @@ -14,4 +16,4 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} dockerfile: Dockerfile - buildargs: VERSION + buildargs: VERSION, BRANCH diff --git a/.github/workflows/publishdocker-release.yml b/.github/workflows/publishdocker-release.yml index 8e216f5a..c942ce32 100644 --- a/.github/workflows/publishdocker-release.yml +++ b/.github/workflows/publishdocker-release.yml @@ -7,7 +7,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@master - - name: Set env + - name: Get branch + run: echo ::set-env name=BRANCH::${GITHUB_REF#refs/heads/} + - name: Get release version run: echo ::set-env name=RELEASE_VERSION::${GITHUB_REF/refs\/tags\//} - name: Publish to Registry uses: elgohr/Publish-Docker-Github-Action@master @@ -18,5 +20,5 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} dockerfile: Dockerfile - buildargs: VERSION + buildargs: VERSION, BRANCH tags: ${{ env.RELEASE_VERSION }} diff --git a/Dockerfile b/Dockerfile index 78bfb150..5efa135a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,7 @@ FROM python:2.7.17-slim LABEL maintainer="TheMeanCanEHdian" ARG VERSION +ARG BRANCH ENV TAUTULLI_DOCKER=True ENV TZ=UTC @@ -16,10 +17,10 @@ apt-get install -q -y --no-install-recommends \ rm -rf /var/lib/apt/lists/* && \ pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir --upgrade \ - plexapi \ pycryptodomex \ pyopenssl && \ -echo ${VERSION} > /app/version.txt +echo ${VERSION} > /app/version.txt && \ +echo ${BRANCH} > /app/branch.txt COPY . /app diff --git a/data/interfaces/default/base.html b/data/interfaces/default/base.html index 38b7cc10..2378f4fe 100644 --- a/data/interfaces/default/base.html +++ b/data/interfaces/default/base.html @@ -43,23 +43,23 @@
% if _session['user_group'] == 'admin': - % if plexpy.CONFIG.CHECK_GITHUB and plexpy.UPDATE_AVAILABLE is None: + % if plexpy.CONFIG.CHECK_GITHUB and plexpy.UPDATE_AVAILABLE is not False: - % elif plexpy.CONFIG.CHECK_GITHUB and plexpy.UPDATE_AVAILABLE == 'release': - - % elif plexpy.CONFIG.CHECK_GITHUB and plexpy.UPDATE_AVAILABLE == 'commit': - % else: @@ -318,21 +318,23 @@ ${next.modalIncludes()} complete: function (xhr, status) { var result = $.parseJSON(xhr.responseText); var msg = ''; - if (result.update === null) { - msg = 'You are running an unknown version of Tautulli.
' + - 'Update or Dismiss'; - $('#updatebar').html(msg).fadeIn(); - } else if (result.update === true && result.release === true) { - msg = 'A new release (' + result.latest_release + ') of Tautulli is available!
' + - 'Update or Dismiss'; - $('#updatebar').html(msg).fadeIn(); - } else if (result.update === true && result.release === false) { - msg = 'A newer version of Tautulli is available!
' + - 'You are '+ result.commits_behind + ' commit' + (result.commits_behind > 1 ? 's' : '') + ' behind.
' + - 'Update or Dismiss'; - $('#updatebar').html(msg).fadeIn(); - } else if (result.update === false) { + if (result.update === false) { showMsg(' ' + result.message, false, true, 2000); + } else { + if (result.update === null) { + msg = 'You are running an unknown version of Tautulli.
'; + } else if (result.update === true && result.release === true) { + msg = 'A new release (' + result.latest_release + ') of Tautulli is available!
'; + } else if (result.update === true && result.release === false) { + msg = 'A newer version of Tautulli is available!
' + + 'You are '+ result.commits_behind + ' commit' + (result.commits_behind > 1 ? 's' : '') + ' behind.
'; + } + if (result.docker) { + msg += 'Update your Docker container or Dismiss'; + } else { + msg += 'Update or Dismiss'; + } + $('#updatebar').html(msg).fadeIn(); } if (_callback) { diff --git a/data/interfaces/default/settings.html b/data/interfaces/default/settings.html index 6f6282e8..28ad41e6 100644 --- a/data/interfaces/default/settings.html +++ b/data/interfaces/default/settings.html @@ -217,7 +217,7 @@

Update Tautulli automatically if an update is available.

diff --git a/plexpy/config.py b/plexpy/config.py index 86d1ad90..93e93a76 100644 --- a/plexpy/config.py +++ b/plexpy/config.py @@ -934,3 +934,9 @@ class Config(object): self.GEOIP_DB = os.path.join(plexpy.DATA_DIR, 'GeoLite2-City.mmdb') self.CONFIG_VERSION = 14 + + if self.CONFIG_VERSION == 14: + if plexpy.DOCKER: + self.PLEXPY_AUTO_UPDATE = 0 + + self.CONFIG_VERSION == 15 diff --git a/plexpy/versioncheck.py b/plexpy/versioncheck.py index dce083aa..0c9cbadd 100644 --- a/plexpy/versioncheck.py +++ b/plexpy/versioncheck.py @@ -115,20 +115,24 @@ def getVersion(): else: - plexpy.INSTALL_TYPE = 'source' + plexpy.INSTALL_TYPE = 'docker' if plexpy.DOCKER else 'source' version_file = os.path.join(plexpy.PROG_DIR, 'version.txt') + branch_file = os.path.join(plexpy.PROG_DIR, 'branch.txt') - if not os.path.isfile(version_file): - return None, 'origin', common.BRANCH - - with open(version_file, 'r') as f: - current_version = f.read().strip(' \n\r') - - if current_version: - return current_version, 'origin', common.BRANCH + if os.path.isfile(version_file): + with open(version_file, 'r') as f: + current_version = f.read().strip(' \n\r') else: - return None, 'origin', common.BRANCH + current_version = None + + if os.path.isfile(branch_file): + with open(branch_file, 'r') as f: + current_branch = f.read().strip(' \n\r') + else: + current_branch = common.BRANCH + + return current_version, 'origin', current_branch def check_update(auto_update=False, notify=False): @@ -232,7 +236,7 @@ def check_github(auto_update=False, notify=False): 'plexpy_update_commit': plexpy.LATEST_VERSION, 'plexpy_update_behind': plexpy.COMMITS_BEHIND}) - if auto_update: + if auto_update and not plexpy.DOCKER: logger.info('Running automatic update.') plexpy.shutdown(restart=True, update=True) @@ -262,6 +266,9 @@ def update(): logger.error('Unable to update from git: ' + line) logger.info('Output: ' + str(output)) + elif plexpy.INSTALL_TYPE == 'docker': + return + else: tar_download_url = 'https://github.com/{}/{}/tarball/{}'.format(plexpy.CONFIG.GIT_USER, plexpy.CONFIG.GIT_REPO, plexpy.CONFIG.GIT_BRANCH) update_dir = os.path.join(plexpy.PROG_DIR, 'update') diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 34ed2644..cf0dba47 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -689,7 +689,7 @@ class WebInterface(object): # Alias 'title' to 'sort_title' if kwargs.get('order_column') == 'title': kwargs['order_column'] = 'sort_title' - + # TODO: Find some one way to automatically get the columns dt_columns = [("added_at", True, False), ("sort_title", True, True), @@ -3341,7 +3341,7 @@ class WebInterface(object): 'type': param['type'], 'value': param['value'] } - for category in common.NOTIFICATION_PARAMETERS + for category in common.NOTIFICATION_PARAMETERS for param in category['parameters']] return parameters @@ -3821,46 +3821,51 @@ class WebInterface(object): versioncheck.check_update() if plexpy.UPDATE_AVAILABLE is None: - return {'result': 'error', - 'update': None, - 'message': 'You are running an unknown version of Tautulli.' - } + update = {'result': 'error', + 'update': None, + 'message': 'You are running an unknown version of Tautulli.' + } elif plexpy.UPDATE_AVAILABLE == 'release': - return {'result': 'success', - 'update': True, - 'release': True, - 'message': 'A new release (%s) of Tautulli is available.' % plexpy.LATEST_RELEASE, - 'current_release': plexpy.common.RELEASE, - 'latest_release': plexpy.LATEST_RELEASE, - 'release_url': helpers.anon_url( - 'https://github.com/%s/%s/releases/tag/%s' - % (plexpy.CONFIG.GIT_USER, - plexpy.CONFIG.GIT_REPO, - plexpy.LATEST_RELEASE)) - } + update = {'result': 'success', + 'update': True, + 'release': True, + 'message': 'A new release (%s) of Tautulli is available.' % plexpy.LATEST_RELEASE, + 'current_release': plexpy.common.RELEASE, + 'latest_release': plexpy.LATEST_RELEASE, + 'release_url': helpers.anon_url( + 'https://github.com/%s/%s/releases/tag/%s' + % (plexpy.CONFIG.GIT_USER, + plexpy.CONFIG.GIT_REPO, + plexpy.LATEST_RELEASE)) + } elif plexpy.UPDATE_AVAILABLE == 'commit': - return {'result': 'success', - 'update': True, - 'release': False, - 'message': 'A newer version of Tautulli is available.', - 'current_version': plexpy.CURRENT_VERSION, - 'latest_version': plexpy.LATEST_VERSION, - 'commits_behind': plexpy.COMMITS_BEHIND, - 'compare_url': helpers.anon_url( - 'https://github.com/%s/%s/compare/%s...%s' - % (plexpy.CONFIG.GIT_USER, - plexpy.CONFIG.GIT_REPO, - plexpy.CURRENT_VERSION, - plexpy.LATEST_VERSION)) + update = {'result': 'success', + 'update': True, + 'release': False, + 'message': 'A newer version of Tautulli is available.', + 'current_version': plexpy.CURRENT_VERSION, + 'latest_version': plexpy.LATEST_VERSION, + 'commits_behind': plexpy.COMMITS_BEHIND, + 'compare_url': helpers.anon_url( + 'https://github.com/%s/%s/compare/%s...%s' + % (plexpy.CONFIG.GIT_USER, + plexpy.CONFIG.GIT_REPO, + plexpy.CURRENT_VERSION, + plexpy.LATEST_VERSION)) } else: - return {'result': 'success', - 'update': False, - 'message': 'Tautulli is up to date.' - } + update = {'result': 'success', + 'update': False, + 'message': 'Tautulli is up to date.' + } + + if plexpy.DOCKER: + update['docker'] = plexpy.DOCKER + + return update @cherrypy.expose @requireAuth(member_of("admin")) @@ -3890,6 +3895,9 @@ class WebInterface(object): @cherrypy.expose @requireAuth(member_of("admin")) def update(self, **kwargs): + if plexpy.DOCKER: + raise cherrypy.HTTPRedirect(plexpy.HTTP_ROOT + "home") + # Show changelog after updating plexpy.CONFIG.__setattr__('UPDATE_SHOW_CHANGELOG', 1) plexpy.CONFIG.write() @@ -3901,7 +3909,7 @@ class WebInterface(object): if git_branch == plexpy.CONFIG.GIT_BRANCH: logger.error(u"Already on the %s branch" % git_branch) raise cherrypy.HTTPRedirect(plexpy.HTTP_ROOT + "home") - + # Set the new git remote and branch plexpy.CONFIG.__setattr__('GIT_REMOTE', git_remote) plexpy.CONFIG.__setattr__('GIT_BRANCH', git_branch)