summaryrefslogtreecommitdiff
path: root/buildstream
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2017-05-30 11:07:21 +0200
committerJürg Billeter <j@bitron.ch>2017-06-27 10:30:29 +0200
commit8c857b63011743948e962fca0eb301cf183b71c9 (patch)
tree545fcac9a1e040a4df504b7acdbc9b9957e090be /buildstream
parente33ed2ff1450efc0b8e459d58d5d1a768884423e (diff)
downloadbuildstream-8c857b63011743948e962fca0eb301cf183b71c9.tar.gz
_ostree.py: Add SSH artifact fetch support
Diffstat (limited to 'buildstream')
-rw-r--r--buildstream/_ostree.py22
-rw-r--r--buildstream/_site.py3
-rwxr-xr-xbuildstream/data/ostree-pull-ssh115
3 files changed, 140 insertions, 0 deletions
diff --git a/buildstream/_ostree.py b/buildstream/_ostree.py
index fdb37eb91..edf646e4f 100644
--- a/buildstream/_ostree.py
+++ b/buildstream/_ostree.py
@@ -270,6 +270,28 @@ def fetch(repo, remote="origin", ref=None, progress=None):
raise OSTreeError("Failed to fetch from '{}': {}".format(remote, e.message)) from e
+# fetch_ssh()
+#
+# Pushes a ref to a remote repository
+#
+# Args:
+# repo (OSTree.Repo): The repo
+# remote (str): The url of the remote ostree repo
+# ref (str): A ref to push
+#
+def fetch_ssh(repo, remote, ref):
+ exit_code, output = utils._call([
+ _site.ostree_pull_ssh,
+ '--repo=' + repo.get_path().get_path(),
+ remote,
+ ref],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
+
+ if exit_code:
+ raise OSTreeError("Failed to fetch artifact from remote SSH repository:\n{}".format(output))
+
+
# push()
#
# Pushes a ref to a remote repository
diff --git a/buildstream/_site.py b/buildstream/_site.py
index b3476fde8..d7b34203c 100644
--- a/buildstream/_site.py
+++ b/buildstream/_site.py
@@ -42,3 +42,6 @@ default_project_config = os.path.join(root, 'data', 'projectconfig.yaml')
# ostree-push shell script
ostree_push = os.path.join(root, 'data', 'ostree-push')
+
+# ostree-pull-ssh shell script
+ostree_pull_ssh = os.path.join(root, 'data', 'ostree-pull-ssh')
diff --git a/buildstream/data/ostree-pull-ssh b/buildstream/data/ostree-pull-ssh
new file mode 100755
index 000000000..1424f7c96
--- /dev/null
+++ b/buildstream/data/ostree-pull-ssh
@@ -0,0 +1,115 @@
+#!/bin/bash -e
+
+# ostree-pull-ssh.sh - Pull OSTree commits from a remote repo using sshfs
+# Copyright (C) 2016 Dan Nicholson <nicholson@endlessm.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+ARGS=$(getopt -n "$0" \
+ -o uvh \
+ -l repo:,update,gpg-sign:,gpg-homedir:,verbose,debug,help \
+ -- "$@")
+eval set -- "$ARGS"
+
+usage() {
+ cat <<EOF
+Usage: $0 [OPTION]... REMOTE [REF]...
+Push OSTree REFs to REMOTE
+
+ --repo=PATH path to OSTree repository
+ -u, --update update the summary file
+ --gpg-sign=KEY-ID GPG key ID to sign the summary with
+ --gpg-homedir=HOMEDIR GPG homedir for finding keys
+ -v, --verbose print verbose information
+ --debug print debug information
+ -h, --help display this help and exit
+EOF
+}
+
+PULL_ARGS=()
+SUMMARY_ARGS=()
+UPDATE=false
+while true; do
+ case "$1" in
+ --repo)
+ OSTREE_REPO=$2
+ shift 2
+ ;;
+ -u|--update)
+ UPDATE=true
+ SUMMARY_ARGS+=("$1")
+ shift
+ ;;
+ --gpg-sign|--gpg-homedir)
+ SUMMARY_ARGS+=("$1=$2")
+ shift 2
+ ;;
+ -v|--verbose)
+ PULL_ARGS+=("$1")
+ SUMMARY_ARGS+=("$1")
+ shift
+ ;;
+ --debug)
+ set -x
+ shift
+ ;;
+ -h|--help)
+ usage
+ exit 0
+ ;;
+ --)
+ shift
+ break
+ ;;
+ esac
+done
+
+if [ $# -lt 1 ]; then
+ echo "No remote specified" >&2
+ exit 1
+fi
+
+REMOTE=$1
+shift
+
+# Figure out the local repo. This emulates ostree_repo_new_default().
+if [ -z "$OSTREE_REPO" ]; then
+ if [ -e objects ] && [ -e config ]; then
+ OSTREE_REPO=.
+ else
+ OSTREE_REPO=/ostree/repo
+ fi
+fi
+
+# Exit handler
+cleanup() {
+ if [ -n "$remote_repo" ]; then
+ fusermount -u "$remote_repo"
+ rm -rf "$remote_repo"
+ fi
+}
+trap cleanup EXIT
+
+# Mount the remote repo
+remote_repo=$(mktemp -d ostree-push.XXXXXXXXXX)
+sshfs "$remote_repo" "$REMOTE"
+
+# Use pull-local to emulate pushing
+ostree pull-local --repo="$OSTREE_REPO" "${PULL_ARGS[@]}" "$remote_repo" "$@"
+
+# Update the local summary if asked
+if $UPDATE; then
+ ostree summary --repo="$OSTREE_REPO" "${SUMMARY_ARGS[@]}"
+fi