From c7aecd32be4863680530dd810495a2cd6d613447 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Mon, 14 Dec 2020 21:05:56 +0000 Subject: [PATCH] Fix error creating releases from certain git references Fixes #249 --- app/blueprints/packages/releases.py | 2 +- app/tasks/importtasks.py | 18 ++++++++++-------- utils/reload_worker.sh | 6 ++++++ utils/update.sh | 8 ++++---- 4 files changed, 21 insertions(+), 13 deletions(-) create mode 100644 utils/reload_worker.sh diff --git a/app/blueprints/packages/releases.py b/app/blueprints/packages/releases.py index 0069b329..f51da0d0 100644 --- a/app/blueprints/packages/releases.py +++ b/app/blueprints/packages/releases.py @@ -87,7 +87,7 @@ def create_release(package): db.session.add(rel) db.session.commit() - makeVCSRelease.apply_async((rel.id, form["vcsLabel"].data), task_id=rel.task_id) + makeVCSRelease.apply_async((rel.id, nonEmptyOrNone(form.vcsLabel.data)), task_id=rel.task_id) msg = "Release {} created".format(rel.title) addNotification(package.maintainers, current_user, NotificationType.PACKAGE_EDIT, msg, rel.getEditURL(), package) diff --git a/app/tasks/importtasks.py b/app/tasks/importtasks.py index 009c9678..03a42747 100644 --- a/app/tasks/importtasks.py +++ b/app/tasks/importtasks.py @@ -35,7 +35,7 @@ def generateGitURL(urlstr): @contextlib.contextmanager -def getTempDir(): +def get_temp_dir(): temp = os.path.join(tempfile.gettempdir(), randomString(10)) yield temp shutil.rmtree(temp) @@ -46,7 +46,7 @@ def getTempDir(): # Throws `TaskError` on failure. # Caller is responsible for deleting returned directory. @contextlib.contextmanager -def cloneRepo(urlstr, ref=None, recursive=False): +def clone_repo(urlstr, ref=None, recursive=False): gitDir = os.path.join(tempfile.gettempdir(), randomString(10)) err = None @@ -58,11 +58,13 @@ def cloneRepo(urlstr, ref=None, recursive=False): repo = git.Repo.clone_from(gitUrl, gitDir, progress=None, env=None, depth=1, recursive=recursive, kill_after_timeout=15) else: + assert ref != "" + repo = git.Repo.init(gitDir) origin = repo.create_remote("origin", url=gitUrl) assert origin.exists() origin.fetch() - origin.pull(ref) + repo.git.checkout(ref) for submodule in repo.submodules: submodule.update(init=True) @@ -85,7 +87,7 @@ def cloneRepo(urlstr, ref=None, recursive=False): @celery.task() def getMeta(urlstr, author): - with cloneRepo(urlstr, recursive=True) as repo: + with clone_repo(urlstr, recursive=True) as repo: try: tree = build_tree(repo.working_tree_dir, author=author, repo=urlstr) except MinetestCheckError as err: @@ -178,7 +180,7 @@ def updateMetaFromRelease(self, id, path): print("updateMetaFromRelease: {} for {}/{}" \ .format(id, release.package.author.display_name, release.package.name)) - with getTempDir() as temp: + with get_temp_dir() as temp: with ZipFile(path, 'r') as zip_ref: zip_ref.extractall(temp) @@ -194,7 +196,7 @@ def checkZipRelease(self, id, path): elif release.package is None: raise TaskError("No package attached to release") - with getTempDir() as temp: + with get_temp_dir() as temp: with ZipFile(path, 'r') as zip_ref: zip_ref.extractall(temp) @@ -213,7 +215,7 @@ def makeVCSRelease(self, id, branch): elif release.package is None: raise TaskError("No package attached to release") - with cloneRepo(release.package.repo, ref=branch, recursive=True) as repo: + with clone_repo(release.package.repo, ref=branch, recursive=True) as repo: postReleaseCheckUpdate(self, release, repo.working_tree_dir) filename = randomString(10) + ".zip" @@ -242,7 +244,7 @@ def importRepoScreenshot(id): raise Exception("Unexpected none package") try: - with cloneRepo(package.repo) as repo: + with clone_repo(package.repo) as repo: for ext in ["png", "jpg", "jpeg"]: sourcePath = repo.working_tree_dir + "/screenshot." + ext if os.path.isfile(sourcePath): diff --git a/utils/reload_worker.sh b/utils/reload_worker.sh new file mode 100644 index 00000000..15becfcc --- /dev/null +++ b/utils/reload_worker.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +set -e + +docker-compose build worker +docker-compose up --no-deps -d worker diff --git a/utils/update.sh b/utils/update.sh index aeba314e..8303a2e9 100755 --- a/utils/update.sh +++ b/utils/update.sh @@ -5,8 +5,8 @@ # This is for production use. See reload.sh for debug mode hot/live reloading. # -sudo docker-compose build app -sudo docker-compose build worker +docker-compose build app +docker-compose build worker -sudo docker-compose up --no-deps -d app -sudo docker-compose up --no-deps --scale worker=2 -d worker +docker-compose up --no-deps -d app +docker-compose up --no-deps --scale worker=2 -d worker