summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-07-09 16:00:43 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-07-09 16:10:05 +0900
commite0da1429d267a3fbcddb4faad8bab31c5cc77282 (patch)
tree2f1ab0dcaac5394a0dfeada184653582cf07386f
parent8c06300651065ed38912557304b4a49870b12f8a (diff)
downloadbuildstream-e0da1429d267a3fbcddb4faad8bab31c5cc77282.tar.gz
_ostree.py: Implement push with `ostree-push` and removed fetch_ssh() method
Pushing is done with ostree-push, and fetching is done with regular _ostree.fetch() codepath only, which will support http or local directory pulls.
-rw-r--r--buildstream/_ostree.py74
1 files changed, 41 insertions, 33 deletions
diff --git a/buildstream/_ostree.py b/buildstream/_ostree.py
index 2ac3ce95f..9f4a9130f 100644
--- a/buildstream/_ostree.py
+++ b/buildstream/_ostree.py
@@ -293,29 +293,23 @@ def fetch(repo, remote="origin", ref=None, progress=None):
raise OSTreeError("Failed to fetch from '{}': {}".format(remote, e.message)) from e
-# fetch_ssh()
+# get_ostree_push()
#
-# Pushes a ref to a remote repository
-#
-# Args:
-# repo (OSTree.Repo): The repo
-# mountdir (str): The directory to create mounts at
-# remote (str): The url of the remote ostree repo
-# ref (str): A ref to pull
-#
-def fetch_ssh(repo, mountdir, remote, ref):
- exit_code, output = utils._call([
- _site.ostree_pull_ssh,
- '--repo=' + repo.get_path().get_path(),
- '--basedir=' + mountdir,
- remote,
- ref],
- terminate=True,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
+# Fetch the host ostree-push host tool required for pushing
+# to remote ostree repositories.
+def get_ostree_push():
+ if not get_ostree_push.ostree_push_checked:
+ try:
+ get_ostree_push.ostree_push = utils.get_host_tool('ostree-push')
+ except ProgramNotFoundError:
+ pass
+ get_ostree_push.ostree_push_checked = True
+ return get_ostree_push.ostree_push
- if exit_code:
- raise OSTreeError("Failed to fetch artifact from remote SSH repository:\n{}".format(output))
+
+# Some static variables for get_ostree_push()
+get_ostree_push.ostree_push_checked = False
+get_ostree_push.ostree_push = None
# push()
@@ -324,28 +318,42 @@ def fetch_ssh(repo, mountdir, remote, ref):
#
# Args:
# repo (OSTree.Repo): The repo
-# mountdir (str): The directory to create mounts at
+# workdir (str): A directory to work in and create temp dirs inside of
# remote (str): The url of the remote ostree repo
# ref (str): A ref to push
+# output_file (file): An optional file handle for capturing the output of ostree-push
#
-def push(repo, mountdir, remote, ref):
+def push(repo, workdir, remote, ref, output_file=None):
+
if remote.startswith("/"):
# local repository
push_repo = ensure(remote, True)
fetch(push_repo, remote=repo.get_path().get_uri(), ref=ref)
else:
- exit_code, output = utils._call([
- _site.ostree_push,
- '--repo=' + repo.get_path().get_path(),
- '--basedir=' + mountdir,
- remote,
- ref],
- terminate=True,
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
+ with utils._tempdir(dir=workdir, prefix='push-repo-') as temp_repo_dir:
+
+ # First create a temporary archive-z2 repository, we can
+ # only use ostree-push with archive-z2 local repo.
+ temp_repo = ensure(temp_repo_dir, True)
+
+ # Now push the ref we want to push into our temporary archive-z2 repo
+ fetch(temp_repo, remote=repo.get_path().get_uri(), ref=ref)
+
+ kwargs = {}
+ kwargs['terminate'] = True
+ if output_file is not None:
+ kwargs['stdout'] = output_file
+ kwargs['stderr'] = output_file
+
+ # Now use ostree-push to push the repo
+ exit_code, _ = utils._call([
+ get_ostree_push(), '--verbose',
+ '--repo', temp_repo.get_path().get_path(),
+ remote, ref
+ ], **kwargs)
if exit_code:
- raise OSTreeError("Failed to push artifact to remote SSH repository:\n{}".format(output))
+ raise OSTreeError("Failed to push artifact {} to artifact server at {}".format(ref, remote))
# configure_remote():