-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This elevates extensions to be "first-class" artifacts. We include a tarball of the extensions in the build dir, as well as details in `meta.json`. This command replaces the `download-extensions` script and leverages rpm-ostree's new support for extension composes: coreos/rpm-ostree#2439
- Loading branch information
Showing
10 changed files
with
245 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
#!/usr/bin/python3 -u | ||
|
||
import argparse | ||
import os | ||
import shutil | ||
import sys | ||
|
||
import createrepo_c as cr | ||
|
||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | ||
|
||
from cosalib import cmdlib | ||
from cosalib.builds import Builds | ||
from cosalib.meta import GenericBuildMeta | ||
|
||
|
||
def main(): | ||
args = parse_args() | ||
|
||
workdir = os.path.abspath(os.getcwd()) | ||
|
||
builds = Builds() | ||
builddir = builds.get_build_dir(args.build) | ||
buildmeta = GenericBuildMeta(workdir=workdir, build=args.build) | ||
|
||
if 'extensions' in buildmeta and not args.force: | ||
print(f"Extensions already exist: {buildmeta['extensions']['path']}") | ||
print("Use --force to force a rebuild") | ||
return | ||
|
||
treefile_src = 'src/config/manifest.yaml' | ||
extensions_src = 'src/config/extensions.yaml' | ||
if not os.path.exists(extensions_src): | ||
raise Exception(f"Missing {extensions_src}") | ||
|
||
commit = buildmeta['ostree-commit'] | ||
cmdlib.import_ostree_commit('tmp/repo', commit, | ||
buildmeta['images']['ostree']['path']) | ||
|
||
tmpworkdir = prepare_tmpworkdir() | ||
changed = run_rpmostree(tmpworkdir, commit, treefile_src, extensions_src) | ||
if not changed: | ||
# For now, rpm-ostree will always detect a change because we don't seed | ||
# state from the previous build, so we won't hit this. Need to rework | ||
# how change detection is wired in `cmd-build` to do this properly. | ||
return | ||
|
||
outputdir = f"{tmpworkdir}/output" | ||
with open(f'{outputdir}/.rpm-ostree-state-chksum', encoding='utf-8') as f: | ||
rpm_ostree_state_chksum = f.read() | ||
|
||
pkglist = create_yumrepo(outputdir) | ||
extensions_tarball = create_tarball(buildmeta, outputdir, tmpworkdir) | ||
extensions_tarball_base = os.path.basename(extensions_tarball) | ||
|
||
buildmeta['extensions'] = { | ||
"path": extensions_tarball_base, | ||
"sha256": cmdlib.sha256sum_file(extensions_tarball), | ||
"rpm-ostree-state": rpm_ostree_state_chksum, | ||
"manifest": pkglist, | ||
} | ||
|
||
cmdlib.rm_allow_noent(f'{builddir}/{extensions_tarball_base}') | ||
shutil.move(extensions_tarball, builddir) | ||
buildmeta.write(artifact_name='extensions') | ||
|
||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--build", help="Build ID", default='latest') | ||
parser.add_argument("--force", help="Force rebuild", action='store_true') | ||
return parser.parse_args() | ||
|
||
|
||
def prepare_tmpworkdir(): | ||
tmpworkdir = 'tmp/extensions' | ||
if os.path.exists(tmpworkdir): | ||
shutil.rmtree(tmpworkdir) | ||
os.mkdir(tmpworkdir) | ||
return tmpworkdir | ||
|
||
|
||
def run_rpmostree(workdir, commit, treefile, extensions): | ||
cmdlib.cmdlib_sh(f''' | ||
changed_stamp={workdir}/changed | ||
runcompose_extensions {workdir}/output {treefile} {extensions} \ | ||
--base-rev {commit}''') | ||
return os.path.exists(f'{workdir}/changed') | ||
|
||
|
||
def create_yumrepo(repodir): | ||
cmdlib.run_verbose(['createrepo_c', repodir]) | ||
# we could also have rpm-ostree output the pkglist for us, but meh... we | ||
# need to run createrepo_c anyway and it's nice that we're using it as the | ||
# source of truth, since that's what rpm-ostree clients will also use | ||
repomd = cr.Repomd(os.path.join(repodir, "repodata/repomd.xml")) | ||
pkglist = {} | ||
|
||
def cb(pkg): | ||
epoch = '' | ||
if pkg.epoch and int(pkg.epoch) > 0: | ||
epoch = f'{pkg.epoch}:' | ||
pkglist[pkg.name] = f'{epoch}{pkg.version}-{pkg.release}.{pkg.arch}' | ||
|
||
for record in repomd.records: | ||
if record.type == 'primary': | ||
primary_xml = os.path.join(repodir, record.location_href) | ||
cr.xml_parse_primary(primary_xml, do_files=False, pkgcb=cb) | ||
break | ||
|
||
if len(pkglist) == 0: | ||
raise Exception("No RPMs found in output dir") | ||
return pkglist | ||
|
||
|
||
def create_tarball(buildmeta, srcdir, destdir): | ||
destdir = os.path.abspath(destdir) | ||
basearch = buildmeta['coreos-assembler.basearch'] | ||
tarfile = f'{destdir}/{buildmeta["name"]}-{buildmeta["buildid"]}-extensions.{basearch}.tar' | ||
cmdlib.run_verbose(['tar', '-cf', tarfile, '.'], cwd=srcdir) | ||
return tarfile | ||
|
||
|
||
if __name__ == '__main__': | ||
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.