2016-03-23 09:38:34 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
[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
|
|
|
import copy
|
2016-10-17 20:22:06 +00:00
|
|
|
import json
|
2016-03-23 09:38:34 +00:00
|
|
|
import os
|
2017-03-27 21:53:08 +00:00
|
|
|
from kobo import shortcuts
|
2016-03-23 09:38:34 +00:00
|
|
|
from kobo.threads import ThreadPool, WorkerThread
|
|
|
|
|
2019-01-09 20:39:33 +00:00
|
|
|
from pungi.arch_utils import getBaseArch
|
2019-03-21 09:58:13 +00:00
|
|
|
from pungi.runroot import Runroot
|
2016-03-23 09:38:34 +00:00
|
|
|
from .base import ConfigGuardedPhase
|
|
|
|
from .. import util
|
[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
|
|
|
from ..ostree.utils import get_ref_from_treefile, get_commitid_from_commitid_file
|
2017-06-29 11:04:29 +00:00
|
|
|
from ..util import get_repo_dicts, translate_path
|
2019-03-21 09:58:13 +00:00
|
|
|
from ..wrappers import scm
|
2016-03-23 09:38:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OSTreePhase(ConfigGuardedPhase):
|
|
|
|
name = 'ostree'
|
|
|
|
|
|
|
|
def __init__(self, compose):
|
|
|
|
super(OSTreePhase, self).__init__(compose)
|
|
|
|
self.pool = ThreadPool(logger=self.compose._logger)
|
|
|
|
|
2017-08-03 13:26:34 +00:00
|
|
|
def _enqueue(self, variant, arch, conf):
|
|
|
|
self.pool.add(OSTreeThread(self.pool))
|
|
|
|
self.pool.queue_put((self.compose, variant, arch, conf))
|
|
|
|
|
2016-03-23 09:38:34 +00:00
|
|
|
def run(self):
|
2017-08-03 13:26:34 +00:00
|
|
|
if isinstance(self.compose.conf.get(self.name), dict):
|
|
|
|
for variant in self.compose.get_variants():
|
2017-08-18 07:33:51 +00:00
|
|
|
for conf in self.get_config_block(variant):
|
2017-08-03 13:26:34 +00:00
|
|
|
for arch in conf.get('arches', []) or variant.arches:
|
|
|
|
self._enqueue(variant, arch, conf)
|
|
|
|
else:
|
|
|
|
# Legacy code path to support original configuration.
|
|
|
|
for variant in self.compose.get_variants():
|
|
|
|
for arch in variant.arches:
|
2017-08-18 07:33:51 +00:00
|
|
|
for conf in self.get_config_block(variant, arch):
|
2017-08-03 13:26:34 +00:00
|
|
|
self._enqueue(variant, arch, conf)
|
2016-03-23 09:38:34 +00:00
|
|
|
|
|
|
|
self.pool.start()
|
|
|
|
|
|
|
|
|
|
|
|
class OSTreeThread(WorkerThread):
|
|
|
|
def process(self, item, num):
|
|
|
|
compose, variant, arch, config = item
|
|
|
|
self.num = num
|
2016-06-24 07:44:40 +00:00
|
|
|
failable_arches = config.get('failable', [])
|
|
|
|
with util.failable(compose, util.can_arch_fail(failable_arches, arch),
|
|
|
|
variant, arch, 'ostree'):
|
2016-04-06 12:57:12 +00:00
|
|
|
self.worker(compose, variant, arch, config)
|
2016-03-23 09:38:34 +00:00
|
|
|
|
2016-04-06 12:57:12 +00:00
|
|
|
def worker(self, compose, variant, arch, config):
|
2016-03-23 09:38:34 +00:00
|
|
|
msg = 'OSTree phase for variant %s, arch %s' % (variant.uid, arch)
|
|
|
|
self.pool.log_info('[BEGIN] %s' % msg)
|
2016-05-18 06:03:31 +00:00
|
|
|
workdir = compose.paths.work.topdir('ostree-%d' % self.num)
|
|
|
|
self.logdir = compose.paths.log.topdir('%s/%s/ostree-%d' %
|
|
|
|
(arch, variant.uid, self.num))
|
2016-04-07 12:33:37 +00:00
|
|
|
repodir = os.path.join(workdir, 'config_repo')
|
|
|
|
self._clone_repo(repodir, config['config_url'], config.get('config_branch', 'master'))
|
2016-11-07 05:23:13 +00:00
|
|
|
|
2018-02-06 21:29:22 +00:00
|
|
|
repo_baseurl = compose.paths.work.arch_repo('$basearch', create_dir=False)
|
2018-04-09 13:32:33 +00:00
|
|
|
comps_repo = compose.paths.work.comps_repo('$basearch', variant=variant, create_dir=False)
|
2018-04-17 12:49:46 +00:00
|
|
|
repos = shortcuts.force_list(config['repo']) + [translate_path(compose, repo_baseurl)]
|
|
|
|
if compose.has_comps:
|
|
|
|
repos.append(translate_path(compose, comps_repo))
|
|
|
|
repos = get_repo_dicts(repos, logger=self.pool)
|
2016-11-07 05:23:13 +00:00
|
|
|
|
[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
|
|
|
# copy the original config and update before save to a json file
|
|
|
|
new_config = copy.copy(config)
|
|
|
|
|
|
|
|
# repos in configuration can have repo url set to variant UID,
|
|
|
|
# update it to have the actual url that we just translated.
|
2017-03-27 21:53:08 +00:00
|
|
|
new_config.update({'repo': repos})
|
[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
|
|
|
|
|
|
|
# remove unnecessary (for 'pungi-make-ostree tree' script ) elements
|
|
|
|
# from config, it doesn't hurt to have them, however remove them can
|
|
|
|
# reduce confusion
|
|
|
|
for k in ['ostree_repo', 'treefile', 'config_url', 'config_branch',
|
|
|
|
'failable', 'version', 'update_summary']:
|
|
|
|
new_config.pop(k, None)
|
|
|
|
|
2017-03-27 21:53:08 +00:00
|
|
|
# write a json file to save the configuration, so 'pungi-make-ostree tree'
|
|
|
|
# can take use of it
|
|
|
|
extra_config_file = os.path.join(workdir, 'extra_config.json')
|
|
|
|
with open(extra_config_file, 'w') as f:
|
|
|
|
json.dump(new_config, f, indent=4)
|
2016-04-07 12:33:37 +00:00
|
|
|
|
2016-05-09 13:59:02 +00:00
|
|
|
# Ensure target directory exists, otherwise Koji task will fail to
|
|
|
|
# mount it.
|
|
|
|
util.makedirs(config['ostree_repo'])
|
|
|
|
|
2019-03-21 09:58:13 +00:00
|
|
|
self._run_ostree_cmd(compose, variant, arch, config, repodir,
|
2017-03-15 15:17:17 +00:00
|
|
|
extra_config_file=extra_config_file)
|
2016-03-23 09:38:34 +00:00
|
|
|
|
2016-09-15 11:09:06 +00:00
|
|
|
if compose.notifier:
|
2018-12-05 10:20:17 +00:00
|
|
|
original_ref = get_ref_from_treefile(
|
|
|
|
os.path.join(repodir, config["treefile"]),
|
|
|
|
arch,
|
|
|
|
logger=self.pool._logger,
|
|
|
|
)
|
|
|
|
ref = config.get("ostree_ref") or original_ref
|
2019-01-09 20:39:33 +00:00
|
|
|
ref = ref.replace("${basearch}", getBaseArch(arch))
|
2018-09-13 13:50:22 +00:00
|
|
|
# 'pungi-make-ostree tree' writes commitid to commitid.log in
|
|
|
|
# logdir, except if there was no new commit we will get None
|
|
|
|
# instead. If the commit id could not be read, an exception will be
|
|
|
|
# raised.
|
|
|
|
commitid = get_commitid_from_commitid_file(
|
|
|
|
os.path.join(self.logdir, 'commitid.log')
|
|
|
|
)
|
2016-09-15 11:09:06 +00:00
|
|
|
compose.notifier.send('ostree',
|
|
|
|
variant=variant.uid,
|
|
|
|
arch=arch,
|
|
|
|
ref=ref,
|
2017-06-29 11:04:29 +00:00
|
|
|
commitid=commitid,
|
|
|
|
repo_path=translate_path(compose, config['ostree_repo']),
|
|
|
|
local_repo_path=config['ostree_repo'])
|
2016-09-15 11:09:06 +00:00
|
|
|
|
2019-03-21 09:58:13 +00:00
|
|
|
self.pool.log_info('[DONE ] %s' % (msg))
|
2016-03-23 09:38:34 +00:00
|
|
|
|
[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
|
|
|
def _run_ostree_cmd(self, compose, variant, arch, config, config_repo, extra_config_file=None):
|
2016-03-23 09:38:34 +00:00
|
|
|
cmd = [
|
|
|
|
'pungi-make-ostree',
|
[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
|
|
|
'tree',
|
|
|
|
'--repo=%s' % config['ostree_repo'],
|
|
|
|
'--log-dir=%s' % self.logdir,
|
2016-05-25 11:37:39 +00:00
|
|
|
'--treefile=%s' % os.path.join(config_repo, config['treefile']),
|
2016-03-23 09:38:34 +00:00
|
|
|
]
|
|
|
|
|
2017-03-29 13:49:21 +00:00
|
|
|
version = util.version_generator(compose, config.get('version'))
|
2016-11-04 08:07:26 +00:00
|
|
|
if version:
|
|
|
|
cmd.append('--version=%s' % version)
|
|
|
|
|
[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 extra_config_file:
|
|
|
|
cmd.append('--extra-config=%s' % extra_config_file)
|
|
|
|
|
2016-11-03 12:59:00 +00:00
|
|
|
if config.get('update_summary', False):
|
|
|
|
cmd.append('--update-summary')
|
|
|
|
|
2017-11-28 15:31:20 +00:00
|
|
|
ostree_ref = config.get('ostree_ref')
|
|
|
|
if ostree_ref:
|
|
|
|
cmd.append('--ostree-ref=%s' % ostree_ref)
|
|
|
|
|
2018-01-11 14:08:07 +00:00
|
|
|
if config.get('force_new_commit', False):
|
|
|
|
cmd.append('--force-new-commit')
|
|
|
|
|
2016-03-23 09:38:34 +00:00
|
|
|
packages = ['pungi', 'ostree', 'rpm-ostree']
|
|
|
|
log_file = os.path.join(self.logdir, 'runroot.log')
|
2016-04-07 12:04:50 +00:00
|
|
|
mounts = [compose.topdir, config['ostree_repo']]
|
2019-03-21 09:58:13 +00:00
|
|
|
|
|
|
|
runroot = Runroot(compose)
|
|
|
|
runroot.run(
|
|
|
|
cmd, log_file=log_file, arch=arch, packages=packages,
|
|
|
|
mounts=mounts, new_chroot=True,
|
|
|
|
weight=compose.conf['runroot_weights'].get('ostree'))
|
2016-04-07 12:33:37 +00:00
|
|
|
|
|
|
|
def _clone_repo(self, repodir, url, branch):
|
|
|
|
scm.get_dir_from_scm({'scm': 'git', 'repo': url, 'branch': branch, 'dir': '.'},
|
|
|
|
repodir, logger=self.pool._logger)
|