mirror of
https://github.com/IEEE-SB-Passau/pelican-deployment-system.git
synced 2017-09-06 16:35:38 +02:00
implement final deployment, example: rsync
This commit is contained in:
@@ -3,6 +3,11 @@ import os
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit("Not meant to be run directly!")
|
||||
|
||||
def _rsync_cmd(dest):
|
||||
cmd = ("rsync --delete-delay --recursive --times --stats "
|
||||
"'{output}/' '{dest}'")
|
||||
return cmd.format(dest=dest, output="{output}")
|
||||
|
||||
# make sure git does not block giving pw prompts, git 2.3+ only
|
||||
os.environ["GIT_TERMINAL_PROMPT"] = "0"
|
||||
|
||||
@@ -26,8 +31,10 @@ RUNNERS = {
|
||||
# branch which will be built
|
||||
"git_branch": "master",
|
||||
|
||||
# the final target, usually the wwwroot
|
||||
"target_directory": "/tmp/wwwout",
|
||||
# command which installs the generated directory tree to it's final
|
||||
# destination (the wwwroot) e.g. rsync. {output} will be replaced by
|
||||
# the path to the generator output
|
||||
"final_install_command": _rsync_cmd("/tmp/testroot"),
|
||||
|
||||
# command which builds the website
|
||||
# important: specify {output} as output path of the generator
|
||||
@@ -37,3 +44,5 @@ RUNNERS = {
|
||||
"build_env": {"PELICAN_SITEURL": "//apu:800"}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,12 +29,14 @@ class DeploymentRunner:
|
||||
|
||||
self.clone_url = runner_config["clone_url"]
|
||||
self.git_branch = runner_config["git_branch"]
|
||||
self.target_directory = runner_config["target_directory"]
|
||||
self.build_repo_path = self.working_directory / BUILD_REPO_DIR.format(
|
||||
name=name)
|
||||
outdir = self.working_directory / OUTPUT_DIR.format(name=name)
|
||||
self.build_command = runner_config["build_command"].format(
|
||||
output=outdir)
|
||||
self.final_install_command = runner_config["final_install_command"]\
|
||||
.format(output=outdir)
|
||||
|
||||
self._build_proc_env = dict(os.environ,
|
||||
**runner_config.get("build_env", {}))
|
||||
|
||||
@@ -92,6 +94,7 @@ class DeploymentRunner:
|
||||
log.warning("git clean failed!", exc_info=True)
|
||||
|
||||
# update the submodules
|
||||
log.info("%s build_repo: update submodules", self.name)
|
||||
build_repo.git.submodule("update", "--init", "--force", "--recursive")
|
||||
|
||||
def build(self, abort_running=False):
|
||||
@@ -113,6 +116,31 @@ class DeploymentRunner:
|
||||
if proc:
|
||||
proc.kill()
|
||||
|
||||
def final_install(self):
|
||||
args = shlex.split(self.final_install_command)
|
||||
log.info("%s: Starting final_install `%s`", self.name, args)
|
||||
proc = Popen(args, stdout=PIPE, stderr=PIPE)
|
||||
atexit.register(proc.kill)
|
||||
outs, errs = proc.communicate()
|
||||
status = proc.wait()
|
||||
atexit.unregister(proc.kill)
|
||||
|
||||
if status < 0:
|
||||
log.info("%s: killed final_install_command (%s)", self.name, status)
|
||||
else:
|
||||
log.info('%s final_install_command stdout: %s\n', self.name,
|
||||
outs.decode(encoding=sys.getdefaultencoding(),
|
||||
errors='replace'))
|
||||
log.info('%s final_install_command stderr: %s\n', self.name,
|
||||
errs.decode(encoding=sys.getdefaultencoding(),
|
||||
errors='replace'))
|
||||
log.info("%s: finished final_install_command with status %s!",
|
||||
self.name, status)
|
||||
|
||||
if status > 0:
|
||||
log.error("%s: final_install failed! Website may be broken!",
|
||||
self.name)
|
||||
|
||||
def build_blocking(self):
|
||||
self._abort = False
|
||||
|
||||
@@ -143,7 +171,5 @@ class DeploymentRunner:
|
||||
errors='replace'))
|
||||
log.info("%s: finished build_command with status %s!",
|
||||
self.name, status)
|
||||
|
||||
if status == 0:
|
||||
# TODO: postproc...
|
||||
pass
|
||||
self.final_install()
|
||||
|
||||
Reference in New Issue
Block a user