[ostree] Add 'tree' sub-command to pungi-make-ostree script
Update pungi-make-ostree to supourt sub-command 'tree', which is just
as the original feature of pungi-make-ostree to compose OSTree tree.
With the change we can add other sub commands later to build other
OSTree artifacts, like the installer image.
Inaddtional to the change, now the the 'tree' command can accept an
optional '--extra-config' parameter to update the original tree
configuration with extra configurations specified in a json file
before composing the OSTree tree.
Example:
pungi-make-ostree tree --repo=/ostree --treefile=/path/to/treefile \
--log-dir=/path/to/log --extra-config=/path/to/extra-config.json
The extra-config file can contains the same configuration as OSTree
phase, the difference is it doesn't understand variant UID as source
repo since it's not ran in the chain of phases. A valid configuration
can be like:
{
"source_repo_from": "http://example.com/repo/x86_64/Server",
"extra_source_repos": [
{
"name": "optional",
"baseurl": "http://example.com/repo/x86_64/optional",
"exclude": "systemd-container",
"gpgcheck": False
},
{
"name": "extra",
"baseurl": "http://example.com/repo/x86_64/extra",
}
],
"keep_original_sources": True
}
The OSTree phase is updated to move out the task of updating treefile,
instead of that, it writes the extra configurations to a json file,
then 'pungi-make-ostree tree' will take it by option '--extra-config'.
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2016-12-02 12:11:09 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
# 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 Library 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 <https://gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import json
|
|
|
|
from kobo import shortcuts
|
|
|
|
|
|
|
|
from pungi.util import makedirs
|
|
|
|
from .base import OSTree
|
|
|
|
from .utils import (make_log_file, tweak_treeconf,
|
|
|
|
get_ref_from_treefile, get_commitid_from_commitid_file)
|
|
|
|
|
|
|
|
|
|
|
|
class Tree(OSTree):
|
|
|
|
def _init_repo(self):
|
|
|
|
"""If the ostree repo does not exist, initialize it."""
|
|
|
|
log_file = make_log_file(self.logdir, 'init-ostree-repo')
|
|
|
|
if not os.path.isdir(self.repo) or not os.listdir(self.repo):
|
|
|
|
makedirs(self.repo)
|
|
|
|
shortcuts.run(['ostree', 'init', '--repo=%s' % self.repo, '--mode=archive-z2'],
|
|
|
|
show_cmd=True, stdout=True, logfile=log_file)
|
|
|
|
|
|
|
|
def _make_tree(self):
|
|
|
|
"""Compose OSTree tree"""
|
|
|
|
log_file = make_log_file(self.logdir, 'create-ostree-repo')
|
|
|
|
cmd = ['rpm-ostree', 'compose', 'tree', '--repo=%s' % self.repo,
|
|
|
|
'--write-commitid-to=%s' % self.commitid_file]
|
|
|
|
if self.version:
|
|
|
|
# Add versioning metadata
|
|
|
|
cmd.append('--add-metadata-string=version=%s' % self.version)
|
|
|
|
cmd.append(self.treefile)
|
|
|
|
|
|
|
|
shortcuts.run(cmd, show_cmd=True, stdout=True, logfile=log_file)
|
|
|
|
|
|
|
|
def _update_summary(self):
|
|
|
|
"""Update summary metadata"""
|
|
|
|
log_file = make_log_file(self.logdir, 'ostree-summary')
|
|
|
|
shortcuts.run(['ostree', 'summary', '-u', '--repo=%s' % self.repo],
|
|
|
|
show_cmd=True, stdout=True, logfile=log_file)
|
|
|
|
|
|
|
|
def _update_ref(self):
|
|
|
|
"""
|
|
|
|
Update the ref.
|
|
|
|
|
|
|
|
'--write-commitid-to' is specified when compose the tree, so we need
|
|
|
|
to update the ref by ourselves. ref is retrieved from treefile and
|
|
|
|
commitid is retrieved from the committid file.
|
|
|
|
"""
|
|
|
|
tag_ref = True
|
|
|
|
if self.extra_config:
|
|
|
|
tag_ref = self.extra_config.get('tag_ref', True)
|
|
|
|
if not tag_ref:
|
2017-01-18 18:52:45 +00:00
|
|
|
print('Not updating ref as configured')
|
[ostree] Add 'tree' sub-command to pungi-make-ostree script
Update pungi-make-ostree to supourt sub-command 'tree', which is just
as the original feature of pungi-make-ostree to compose OSTree tree.
With the change we can add other sub commands later to build other
OSTree artifacts, like the installer image.
Inaddtional to the change, now the the 'tree' command can accept an
optional '--extra-config' parameter to update the original tree
configuration with extra configurations specified in a json file
before composing the OSTree tree.
Example:
pungi-make-ostree tree --repo=/ostree --treefile=/path/to/treefile \
--log-dir=/path/to/log --extra-config=/path/to/extra-config.json
The extra-config file can contains the same configuration as OSTree
phase, the difference is it doesn't understand variant UID as source
repo since it's not ran in the chain of phases. A valid configuration
can be like:
{
"source_repo_from": "http://example.com/repo/x86_64/Server",
"extra_source_repos": [
{
"name": "optional",
"baseurl": "http://example.com/repo/x86_64/optional",
"exclude": "systemd-container",
"gpgcheck": False
},
{
"name": "extra",
"baseurl": "http://example.com/repo/x86_64/extra",
}
],
"keep_original_sources": True
}
The OSTree phase is updated to move out the task of updating treefile,
instead of that, it writes the extra configurations to a json file,
then 'pungi-make-ostree tree' will take it by option '--extra-config'.
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2016-12-02 12:11:09 +00:00
|
|
|
return
|
|
|
|
ref = get_ref_from_treefile(self.treefile)
|
|
|
|
commitid = get_commitid_from_commitid_file(self.commitid_file)
|
2017-01-18 18:52:45 +00:00
|
|
|
print('Ref: %r, Commit ID: %r' % (ref, commitid))
|
[ostree] Add 'tree' sub-command to pungi-make-ostree script
Update pungi-make-ostree to supourt sub-command 'tree', which is just
as the original feature of pungi-make-ostree to compose OSTree tree.
With the change we can add other sub commands later to build other
OSTree artifacts, like the installer image.
Inaddtional to the change, now the the 'tree' command can accept an
optional '--extra-config' parameter to update the original tree
configuration with extra configurations specified in a json file
before composing the OSTree tree.
Example:
pungi-make-ostree tree --repo=/ostree --treefile=/path/to/treefile \
--log-dir=/path/to/log --extra-config=/path/to/extra-config.json
The extra-config file can contains the same configuration as OSTree
phase, the difference is it doesn't understand variant UID as source
repo since it's not ran in the chain of phases. A valid configuration
can be like:
{
"source_repo_from": "http://example.com/repo/x86_64/Server",
"extra_source_repos": [
{
"name": "optional",
"baseurl": "http://example.com/repo/x86_64/optional",
"exclude": "systemd-container",
"gpgcheck": False
},
{
"name": "extra",
"baseurl": "http://example.com/repo/x86_64/extra",
}
],
"keep_original_sources": True
}
The OSTree phase is updated to move out the task of updating treefile,
instead of that, it writes the extra configurations to a json file,
then 'pungi-make-ostree tree' will take it by option '--extra-config'.
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2016-12-02 12:11:09 +00:00
|
|
|
if ref and commitid:
|
2017-01-18 18:52:45 +00:00
|
|
|
print('Updating ref')
|
[ostree] Add 'tree' sub-command to pungi-make-ostree script
Update pungi-make-ostree to supourt sub-command 'tree', which is just
as the original feature of pungi-make-ostree to compose OSTree tree.
With the change we can add other sub commands later to build other
OSTree artifacts, like the installer image.
Inaddtional to the change, now the the 'tree' command can accept an
optional '--extra-config' parameter to update the original tree
configuration with extra configurations specified in a json file
before composing the OSTree tree.
Example:
pungi-make-ostree tree --repo=/ostree --treefile=/path/to/treefile \
--log-dir=/path/to/log --extra-config=/path/to/extra-config.json
The extra-config file can contains the same configuration as OSTree
phase, the difference is it doesn't understand variant UID as source
repo since it's not ran in the chain of phases. A valid configuration
can be like:
{
"source_repo_from": "http://example.com/repo/x86_64/Server",
"extra_source_repos": [
{
"name": "optional",
"baseurl": "http://example.com/repo/x86_64/optional",
"exclude": "systemd-container",
"gpgcheck": False
},
{
"name": "extra",
"baseurl": "http://example.com/repo/x86_64/extra",
}
],
"keep_original_sources": True
}
The OSTree phase is updated to move out the task of updating treefile,
instead of that, it writes the extra configurations to a json file,
then 'pungi-make-ostree tree' will take it by option '--extra-config'.
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2016-12-02 12:11:09 +00:00
|
|
|
# Let's write the tag out ourselves
|
|
|
|
heads_dir = os.path.join(self.repo, 'refs', 'heads')
|
|
|
|
if not os.path.exists(heads_dir):
|
|
|
|
raise RuntimeError('Refs/heads did not exist in ostree repo')
|
|
|
|
|
|
|
|
ref_path = os.path.join(heads_dir, ref)
|
|
|
|
makedirs(os.path.dirname(ref_path))
|
|
|
|
with open(ref_path, 'w') as f:
|
|
|
|
f.write(commitid + '\n')
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
self.repo = self.args.repo
|
|
|
|
self.treefile = self.args.treefile
|
|
|
|
self.version = self.args.version
|
|
|
|
self.logdir = self.args.log_dir
|
|
|
|
self.update_summary = self.args.update_summary
|
|
|
|
self.extra_config = self.args.extra_config
|
|
|
|
if self.extra_config:
|
|
|
|
self.extra_config = json.load(open(self.extra_config, 'r'))
|
2017-02-22 02:48:05 +00:00
|
|
|
source_repo_from = self.extra_config.get('repo_from', None)
|
|
|
|
extra_source_repos = self.extra_config.get('repo', [])
|
[ostree] Add 'tree' sub-command to pungi-make-ostree script
Update pungi-make-ostree to supourt sub-command 'tree', which is just
as the original feature of pungi-make-ostree to compose OSTree tree.
With the change we can add other sub commands later to build other
OSTree artifacts, like the installer image.
Inaddtional to the change, now the the 'tree' command can accept an
optional '--extra-config' parameter to update the original tree
configuration with extra configurations specified in a json file
before composing the OSTree tree.
Example:
pungi-make-ostree tree --repo=/ostree --treefile=/path/to/treefile \
--log-dir=/path/to/log --extra-config=/path/to/extra-config.json
The extra-config file can contains the same configuration as OSTree
phase, the difference is it doesn't understand variant UID as source
repo since it's not ran in the chain of phases. A valid configuration
can be like:
{
"source_repo_from": "http://example.com/repo/x86_64/Server",
"extra_source_repos": [
{
"name": "optional",
"baseurl": "http://example.com/repo/x86_64/optional",
"exclude": "systemd-container",
"gpgcheck": False
},
{
"name": "extra",
"baseurl": "http://example.com/repo/x86_64/extra",
}
],
"keep_original_sources": True
}
The OSTree phase is updated to move out the task of updating treefile,
instead of that, it writes the extra configurations to a json file,
then 'pungi-make-ostree tree' will take it by option '--extra-config'.
Signed-off-by: Qixiang Wan <qwan@redhat.com>
2016-12-02 12:11:09 +00:00
|
|
|
keep_original_sources = self.extra_config.get('keep_original_sources', False)
|
|
|
|
repos = extra_source_repos + [{'name': 'source_repo_from', 'baseurl': source_repo_from}]
|
|
|
|
tweak_treeconf(self.treefile, source_repos=repos, keep_original_sources=keep_original_sources)
|
|
|
|
|
|
|
|
self.commitid_file = make_log_file(self.logdir, 'commitid')
|
|
|
|
|
|
|
|
self._init_repo()
|
|
|
|
self._make_tree()
|
|
|
|
self._update_ref()
|
|
|
|
if self.update_summary:
|
|
|
|
self._update_summary()
|