ostree: Use the write-commitid-to feature rather than parsing ostree logs
This depends on an rpm-ostree release with
98332a3be4
Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>
This commit is contained in:
parent
c5bd99da9e
commit
754458823c
@ -678,6 +678,7 @@ def _make_schema():
|
||||
"ostree_repo": {"type": "string"},
|
||||
"failable": {"$ref": "#/definitions/list_of_strings"},
|
||||
"config_branch": {"type": "string"},
|
||||
"tag_ref": {"type": "boolean"},
|
||||
},
|
||||
"required": ["treefile", "config_url", "source_repo_from", "ostree_repo"],
|
||||
"additionalProperties": False,
|
||||
|
@ -39,7 +39,9 @@ def init_ostree_repo(repo, log_dir=None):
|
||||
|
||||
def make_ostree_repo(repo, config, log_dir=None):
|
||||
log_file = make_log_file(log_dir, 'create-ostree-repo')
|
||||
shortcuts.run(['rpm-ostree', 'compose', 'tree', '--repo=%s' % repo, config],
|
||||
shortcuts.run(['rpm-ostree', 'compose', 'tree', '--repo=%s' % repo,
|
||||
'--write-commitid-to=%s' % make_log_file(log_dir, 'commitid'),
|
||||
config],
|
||||
show_cmd=True, stdout=True, logfile=log_file)
|
||||
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import json
|
||||
import os
|
||||
from kobo.threads import ThreadPool, WorkerThread
|
||||
import re
|
||||
@ -58,9 +59,21 @@ class OSTreeThread(WorkerThread):
|
||||
util.makedirs(config['ostree_repo'])
|
||||
|
||||
self._run_ostree_cmd(compose, variant, arch, config, repodir)
|
||||
ref, commitid = self._get_commit_info(config, repodir)
|
||||
if config.get('tag_ref', True) and ref and commitid:
|
||||
# Let's write the tag out ourselves
|
||||
heads_dir = os.path.join(config['ostree_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)
|
||||
if not os.path.exists(os.path.dirname(ref_path)):
|
||||
os.makedirs(os.path.dirname(ref_path))
|
||||
|
||||
with open(ref_path, 'w') as f:
|
||||
f.write(commitid + '\n')
|
||||
|
||||
if compose.notifier:
|
||||
ref, commitid = self._get_commit_info()
|
||||
compose.notifier.send('ostree',
|
||||
variant=variant.uid,
|
||||
arch=arch,
|
||||
@ -69,14 +82,21 @@ class OSTreeThread(WorkerThread):
|
||||
|
||||
self.pool.log_info('[DONE ] %s' % msg)
|
||||
|
||||
def _get_commit_info(self):
|
||||
with open(os.path.join(self.logdir, 'create-ostree-repo.log'), 'r') as f:
|
||||
for line in f.readlines():
|
||||
if ' => ' in line:
|
||||
line = line.replace('\n', '')
|
||||
ref, _, commitid = line.partition(' => ')
|
||||
return ref, commitid
|
||||
def _get_commit_info(self, config, config_repo):
|
||||
ref = None
|
||||
commitid = None
|
||||
with open(os.path.join(config_repo, config['treefile']), 'r') as f:
|
||||
try:
|
||||
parsed = json.loads(f.read())
|
||||
ref = parsed['ref']
|
||||
except ValueError:
|
||||
return None, None
|
||||
if os.path.exists(os.path.join(self.logdir, 'commitid')):
|
||||
with open(os.path.join(self.logdir, 'commitid'), 'r') as f:
|
||||
commitid = f.read().replace('\n', '')
|
||||
else:
|
||||
return None, None
|
||||
return ref, commitid
|
||||
|
||||
def _run_ostree_cmd(self, compose, variant, arch, config, config_repo):
|
||||
cmd = [
|
||||
|
@ -33,6 +33,7 @@ class OstreeScriptTest(helpers.PungiTestCase):
|
||||
[mock.call(['ostree', 'init', '--repo=%s' % repo, '--mode=archive-z2'],
|
||||
logfile=self.topdir + '/logs/Atomic/init-ostree-repo.log', show_cmd=True, stdout=True),
|
||||
mock.call(['rpm-ostree', 'compose', 'tree', '--repo=%s' % repo,
|
||||
'--write-commitid-to=%s' % (self.topdir + '/logs/Atomic/commitid.log'),
|
||||
self.topdir + '/fedora-atomic-docker-host.json'],
|
||||
logfile=self.topdir + '/logs/Atomic/create-ostree-repo.log', show_cmd=True, stdout=True)])
|
||||
|
||||
@ -54,6 +55,7 @@ class OstreeScriptTest(helpers.PungiTestCase):
|
||||
[mock.call(['ostree', 'init', '--repo=%s' % repo, '--mode=archive-z2'],
|
||||
logfile=self.topdir + '/logs/Atomic/init-ostree-repo.log', show_cmd=True, stdout=True),
|
||||
mock.call(['rpm-ostree', 'compose', 'tree', '--repo=%s' % repo,
|
||||
'--write-commitid-to=%s' % (self.topdir + '/logs/Atomic/commitid.log'),
|
||||
self.topdir + '/fedora-atomic-docker-host.json'],
|
||||
logfile=self.topdir + '/logs/Atomic/create-ostree-repo.log', show_cmd=True, stdout=True)])
|
||||
|
||||
@ -73,6 +75,7 @@ class OstreeScriptTest(helpers.PungiTestCase):
|
||||
self.assertItemsEqual(
|
||||
run.call_args_list,
|
||||
[mock.call(['rpm-ostree', 'compose', 'tree', '--repo=%s' % repo,
|
||||
'--write-commitid-to=%s' % (self.topdir + '/logs/Atomic/commitid.log'),
|
||||
self.topdir + '/fedora-atomic-docker-host.json'],
|
||||
logfile=self.topdir + '/logs/Atomic/create-ostree-repo.log', show_cmd=True, stdout=True)])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user