diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-07-10 17:04:58 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-07-10 20:38:48 +0900 |
commit | f9cb0f09a4549c64621e0a35b7cc0784adf61ba4 (patch) | |
tree | 9405bfca452e0f4079fc894aec1aae8e1b6886fe /buildstream/_artifactcache/artifactcache.py | |
parent | e7fade3adb44001987653e92553b4a0d5e56712a (diff) | |
download | buildstream-f9cb0f09a4549c64621e0a35b7cc0784adf61ba4.tar.gz |
artifactcache.py: Use internal copy of ostree-push to push artifacts
Diffstat (limited to 'buildstream/_artifactcache/artifactcache.py')
-rw-r--r-- | buildstream/_artifactcache/artifactcache.py | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/buildstream/_artifactcache/artifactcache.py b/buildstream/_artifactcache/artifactcache.py index 2d3571b98..ce6c9bf51 100644 --- a/buildstream/_artifactcache/artifactcache.py +++ b/buildstream/_artifactcache/artifactcache.py @@ -25,6 +25,9 @@ from .. import _ostree, utils from ..exceptions import _BstError from .._ostree import OSTreeError +from .pushreceive import push as push_artifact +from .pushreceive import PushException + # For users of this file, they must expect (except) it. class ArtifactError(_BstError): @@ -215,10 +218,26 @@ class ArtifactCache(): raise ArtifactError("Attempt to push artifact without any push URL") ref = buildref(element) - workdir = os.path.join(self.context.artifactdir, 'work') - os.makedirs(workdir, exist_ok=True) - - with element._output_file() as output_file: - _ostree.push(self.repo, workdir, - remote=self.context.artifact_push, ref=ref, - output_file=output_file) + if self.context.artifact_push.startswith("/"): + # local repository + push_repo = _ostree.ensure(self.context.artifact_push, True) + _ostree.fetch(push_repo, remote=self.repo.get_path().get_uri(), ref=ref) + else: + # Push over ssh + # + with utils._tempdir(dir=self.context.artifactdir, 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 = _ostree.ensure(temp_repo_dir, True) + + # Now push the ref we want to push into our temporary archive-z2 repo + _ostree.fetch(temp_repo, remote=self.repo.get_path().get_uri(), ref=ref) + + with element._output_file() as output_file: + try: + push_artifact(temp_repo.get_path().get_path(), + self.context.artifact_push, + ref, output_file) + except PushException as e: + raise ArtifactError("Failed to push artifact {}: {}".format(ref, e)) from e |