Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions src/cmd-build-with-buildah
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ DIRECT=
AUTOLOCK_VERSION=
SKIP_PRUNE=
STRICT=
PARENT_BUILD=
rc=0
options=$(getopt --options h,d --longoptions help,version:,versionary,direct,autolock:,skip-prune,parent-build:,force,strict -- "$@") || rc=$?
[ $rc -eq 0 ] || {
Expand Down Expand Up @@ -231,22 +232,10 @@ build_with_buildah() {
fi

if [ -z "${skip_import:-}" ]; then
/usr/lib/coreos-assembler/cmd-import "${final_ref}" ${SKIP_PRUNE:+--skip-prune}
/usr/lib/coreos-assembler/cmd-import "${final_ref}" \
${PARENT_BUILD:+--parent-build=${PARENT_BUILD}} ${SKIP_PRUNE:+--skip-prune}
fi

# For the logs, print the RPM diff
/usr/lib/coreos-assembler/cmd-diff \
--rpms ${PARENT_BUILD:+--from=$PARENT_BUILD}

# For meta.json let's record the RPM diff and advisory diff information
/usr/lib/coreos-assembler/cmd-diff \
--rpms-json ${PARENT_BUILD:+--from=$PARENT_BUILD} |
jq '{"pkgdiff": .pkgdiff, "advisories-diff": .advisories}' > "${tempdir}/diff.json"
/usr/lib/coreos-assembler/cmd-meta --build="${VERSION}" \
--skip-validation --artifact-json "${tempdir}/diff.json"
# Run a 'dump' now to perform schema validation since we skipped it above.
/usr/lib/coreos-assembler/cmd-meta --dump --build="${VERSION}" > /dev/null

rm -rf "${tempdir}"
}

Expand Down
33 changes: 33 additions & 0 deletions src/cmd-import
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ from cosalib.cmdlib import (
get_basearch,
sha256sum_file,
import_oci_archive)
from cosalib.meta import GenericBuildMeta


def main():
Expand Down Expand Up @@ -63,6 +64,14 @@ def main():
# move into official location
finalize_build(builds, build_meta, tmp_oci_archive, tmp_oci_manifest, tmp_lockfile, tmp_commitmeta)

# Now that the build has been created (i.e. files put into the
# right places) let's use `cosa diff` to insert package and
# advisory diffs into the meta.json and log the RPM diff, but
# only if we have something to diff against.
if args.parent_build or len(builds.get_builds()) > 1:
starting_buildid = args.parent_build if args.parent_build else builds.get_previous()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This line can be simplified by using the or operator, which is more concise and idiomatic in Python for this type of assignment.

Suggested change
starting_buildid = args.parent_build if args.parent_build else builds.get_previous()
starting_buildid = args.parent_build or builds.get_previous()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ehh. I'm lukewarm on this suggestion. Will implement if reviewers like it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've started using that idiom more but yeah, it can look weird if you're not used to it. Fine as is.

calculate_and_log_diffs(builds, buildid, arch, starting_buildid)

if not args.skip_prune:
subprocess.check_call(['/usr/lib/coreos-assembler/cmd-prune'])

Expand All @@ -73,6 +82,8 @@ def parse_args():
help="image to import (containers-transports(5) format)")
parser.add_argument("--skip-prune", action='store_true',
help="Skip prunning previous builds")
parser.add_argument("--parent-build",
help="The parent build to diff against")
return parser.parse_args()


Expand Down Expand Up @@ -228,6 +239,28 @@ def finalize_build(builds, build_meta, tmp_oci_archive, tmp_oci_manifest, tmp_lo
print(f'Imported OCI image as build {buildid}')


def calculate_and_log_diffs(builds, buildid, arch, starting_buildid):
# Get the RPM/Advisory diff info
diff_cmd_json = ['/usr/lib/coreos-assembler/cmd-diff', '--rpms-json',
'--from', starting_buildid, '--to', buildid]
diff_json_str = subprocess.check_output(diff_cmd_json)
diff_data = json.loads(diff_json_str)

# Update the meta.json file with the RPM/Advisory diff info. Yes we
# just created this file, but let's use the library now for access.
meta = GenericBuildMeta(workdir=os.getcwd(), build=buildid, basearch=arch)
meta.update({
'pkgdiff': diff_data.get('pkgdiff'),
'advisories-diff': diff_data.get('advisories')
})
meta.write()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm right, I was thinking that we could directly write the updated meta.json on first shot, but indeed cosa diff doesn't know how to work with staged builds. And meh... doesn't seem worth it for this.


# For the logs let's output the RPM diff
diff_cmd_log = ['/usr/lib/coreos-assembler/cmd-diff', '--rpms',
'--from', starting_buildid, '--to', buildid]
subprocess.check_call(diff_cmd_log)


def skopeo_inspect(image):
return json.loads(subprocess.check_output(['skopeo', 'inspect', '-n', image]))

Expand Down
Loading