[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 _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)
|
2017-12-05 10:51:43 +00:00
|
|
|
# Note renamed from rpm-ostree --force-nocache since it's a better
|
|
|
|
# name; more clearly describes what we're doing here.
|
|
|
|
if self.force_new_commit:
|
|
|
|
cmd.append('--force-nocache')
|
[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
|
|
|
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
|
2017-11-28 15:31:20 +00:00
|
|
|
# if ostree_ref argument is given, it overrides ref value from treefile
|
|
|
|
if self.ostree_ref:
|
|
|
|
ref = self.ostree_ref
|
|
|
|
else:
|
|
|
|
ref = get_ref_from_treefile(self.treefile)
|
[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
|
|
|
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
|
2017-11-28 15:31:20 +00:00
|
|
|
self.ostree_ref = self.args.ostree_ref
|
2017-12-05 10:51:43 +00:00
|
|
|
self.force_new_commit = self.args.force_new_commit
|
2017-11-28 15:31:20 +00:00
|
|
|
|
2017-12-04 14:15:20 +00:00
|
|
|
if self.extra_config or self.ostree_ref:
|
|
|
|
if self.extra_config:
|
|
|
|
self.extra_config = json.load(open(self.extra_config, 'r'))
|
|
|
|
repos = self.extra_config.get('repo', [])
|
|
|
|
keep_original_sources = self.extra_config.get('keep_original_sources', False)
|
|
|
|
else:
|
|
|
|
# missing extra_config mustn't affect tweak_treeconf call
|
|
|
|
repos = []
|
|
|
|
keep_original_sources = True
|
|
|
|
|
|
|
|
update_dict = {}
|
|
|
|
if self.ostree_ref:
|
|
|
|
# override ref value in treefile
|
|
|
|
update_dict['ref'] = self.ostree_ref
|
|
|
|
|
|
|
|
tweak_treeconf(self.treefile, source_repos=repos, keep_original_sources=keep_original_sources, update_dict=update_dict)
|
[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
|
|
|
|
|
|
|
self.commitid_file = make_log_file(self.logdir, 'commitid')
|
|
|
|
|
|
|
|
self._make_tree()
|
|
|
|
self._update_ref()
|
|
|
|
if self.update_summary:
|
|
|
|
self._update_summary()
|