summaryrefslogtreecommitdiff
path: root/extensions/ostree.write
diff options
context:
space:
mode:
authorPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-10-17 08:10:28 +0000
committerPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-10-17 08:10:28 +0000
commit3b387c376c813d611df05667e8f3490678ef5ba4 (patch)
tree57dc868983c639f8c3e53c0e1c5dac25d35ccf2b /extensions/ostree.write
parent36f7e4923ae5d03dd345d74f7fcade48c99a498d (diff)
downloaddefinitions-jjardon/ostree.write.tar.gz
Add ostree.write deployment extensionstaging/jjardon/ostree.writejjardon/ostree.write
Reverts commit 36f7e4923ae5d03dd345d74f7fcade48c99a498d This is a simple deployment extension to write the results of a Baserock build to an OSTree repo. See ostree.write.help for more information. The Baserock reference systems contain static device nodes, which are not supported by OSTree, and are obsolete on Linux systems. To work around this problem, I added a strip-device-nodes.configure extension. The systems should still work the same as devtmpfs will create the device nodes. I've tested this by deploying minimal-system-x86_64 to an OSTree repo, then checking it out into a temporary directory, creating a read-only bind-mount of the temporary directory and chrooting then into it. This is only going to be useful for containers systems and chroots for the time being. We would need to make some quite major changes to the Baserock reference systems to enable deployment to VMs or bare metal using OSTree. Change-Id: Ic393bdec7b28341fc5dfa56bb684217d964be5ff
Diffstat (limited to 'extensions/ostree.write')
-rw-r--r--extensions/ostree.write88
1 files changed, 88 insertions, 0 deletions
diff --git a/extensions/ostree.write b/extensions/ostree.write
new file mode 100644
index 00000000..b2b5d6e1
--- /dev/null
+++ b/extensions/ostree.write
@@ -0,0 +1,88 @@
+#!/usr/bin/python
+# Copyright (C) 2015 Codethink Limited
+#
+# 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; version 2 of the License.
+#
+# 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, see <http://www.gnu.org/licenses/>.
+
+
+'''A Baserock write extension for deploying to OSTree repositories.'''
+
+
+from gi.repository import GLib
+from gi.repository import Gio
+from gi.repository import OSTree
+
+import os
+import subprocess
+import tempfile
+import urlparse
+
+import writeexts
+
+
+def ostree_repo_resolve_rev(repo, branch, allow_noent=True):
+ '''Return the SHA256 corresponding to 'branch'.'''
+ return repo.resolve_rev(branch, allow_noent)[1]
+
+
+def ostree_repo_commit_tree(repo, tree_dir, branch, commit_subject,
+ commit_body=''):
+ '''Commit the contents of 'tree_dir' to 'branch'.'''
+
+ repo.prepare_transaction(None)
+
+ parent = ostree_repo_resolve_rev(repo, branch)
+
+ ostree_mtree = OSTree.MutableTree()
+ tree_dir_gfile = Gio.file_new_for_path(tree_dir)
+ repo.write_directory_to_mtree(tree_dir_gfile, ostree_mtree, None, None)
+
+ root = repo.write_mtree(ostree_mtree, None)[1]
+ checksum = repo.write_commit(
+ parent, commit_subject, commit_body, None, root, None)[1]
+
+ repo.transaction_set_ref(None, branch, checksum)
+
+ stats = repo.commit_transaction(None)
+ return stats
+
+
+class OSTreeWriteExtension(writeexts.WriteExtension):
+ '''See ostree.write.help for documentation.'''
+
+ def process_args(self, args):
+ if len(args) != 2:
+ raise writeexts.ExtensionError(
+ 'Wrong number of command line args')
+
+ temp_root, location = args
+
+ repo = OSTree.Repo.new(Gio.File.new_for_path(location))
+ repo.open()
+
+ branch = os.environ.get('OSTREE_BRANCH')
+ commit_subject = os.environ.get('OSTREE_COMMIT_SUBJECT')
+ commit_body = os.environ.get('OSTREE_COMMIT_BODY')
+
+ try:
+ ostree_repo_commit_tree(repo, temp_root, branch, commit_subject, commit_body)
+ except GLib.GError as e:
+ raise writeexts.ExtensionError(
+ '%s. Failed to commit system to repo %s.' %
+ (e.message, location))
+
+ self.status(
+ msg='Created commit on branch %s in OSTree repo at %s' % (
+ branch, location))
+
+
+OSTreeWriteExtension().run()