1
0
mirror of https://github.com/IEEE-SB-Passau/pelican-deployment-system.git synced 2017-09-06 16:35:38 +02:00

allow cronjobs to do builds if pull from remote repo fail

This commit is contained in:
2016-06-14 15:03:30 +02:00
parent c0fc14f3f9
commit 4670a142a1
2 changed files with 28 additions and 9 deletions

3
app.py
View File

@@ -41,7 +41,8 @@ def init_app(configpath):
name="{} ({})".format(rname, i), name="{} ({})".format(rname, i),
id="{}_{}".format(rname, i), id="{}_{}".format(rname, i),
max_instances=1, max_instances=1,
kwars={"wait": True}) kwargs={"wait": True,
"ignore_pull_error": True})
pelican_deploy.webhookbottle.set_runners(**runners) pelican_deploy.webhookbottle.set_runners(**runners)
pelican_deploy.webhookbottle.set_github_secret(config.GITHUB_SECRET) pelican_deploy.webhookbottle.set_github_secret(config.GITHUB_SECRET)

View File

@@ -19,6 +19,8 @@ log_git = partial(log_git_result, out_logger=log.debug,
BUILD_REPO_DIR = "{name}_build_repo" BUILD_REPO_DIR = "{name}_build_repo"
OUTPUT_DIR = "{name}_output" OUTPUT_DIR = "{name}_output"
class PullError(Exception):
pass
class DeploymentRunner: class DeploymentRunner:
@@ -95,9 +97,14 @@ class DeploymentRunner:
log.info("%s build_repo: pulling changes from origin", self.name) log.info("%s build_repo: pulling changes from origin", self.name)
refspec = "+{b}:{b}".format(b=self.git_branch) refspec = "+{b}:{b}".format(b=self.git_branch)
try:
result = repo.pull("--force", "--no-edit", "--recurse-submodules", result = repo.pull("--force", "--no-edit", "--recurse-submodules",
"--depth", "1", "origin", refspec) "--depth", "1", "origin", refspec)
log_git(result) log_git(result)
except Exception as e:
# need to reinit the submodules
self._update_build_repo_submodules(repo)
raise PullError from e
try: try:
result = repo.clean("--force", "-d", "-x") result = repo.clean("--force", "-d", "-x")
@@ -106,11 +113,14 @@ class DeploymentRunner:
log.warning("git clean failed!", exc_info=True) log.warning("git clean failed!", exc_info=True)
# update the submodules # update the submodules
self._update_build_repo_submodules(repo)
def _update_build_repo_submodules(self, repo):
log.info("%s build_repo: update submodules", self.name) log.info("%s build_repo: update submodules", self.name)
result = repo.submodule("update", "--init", "--force", "--recursive") result = repo.submodule("update", "--init", "--force", "--recursive")
log_git(result) log_git(result)
def build(self, abort_running=False, wait=False): def build(self, abort_running=False, wait=False, ignore_pull_error=False):
with self._build_lock: with self._build_lock:
if abort_running: if abort_running:
self.try_abort_build() self.try_abort_build()
@@ -121,7 +131,9 @@ class DeploymentRunner:
if fut.done(): if fut.done():
self._futures.remove(fut) self._futures.remove(fut)
build_func = exception_logged(self.build_blocking, log.error) build_bl = partial(self.build_blocking, ignore_pull_error=
ignore_pull_error)
build_func = exception_logged(build_bl, log.error)
future = self._executor.submit(build_func) future = self._executor.submit(build_func)
self._futures.add(future) self._futures.add(future)
if wait: if wait:
@@ -153,12 +165,18 @@ class DeploymentRunner:
log.error("%s: final_install failed! Website may be broken!", log.error("%s: final_install failed! Website may be broken!",
self.name) self.name)
def build_blocking(self): def build_blocking(self, ignore_pull_error=False):
self._abort = False self._abort = False
# preparing build environment # preparing build environment
try:
self.update_build_repository() self.update_build_repository()
# TODO: prepare_output() except PullError:
if ignore_pull_error:
log.warning(("Git pull failed, trying"
" to continue with what we have"), exc_info=True)
else:
raise
# start the build if we should not abort # start the build if we should not abort
if not self._abort: if not self._abort: