-
Notifications
You must be signed in to change notification settings - Fork 184
move diff calculations into cosa import
#4340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+36
−14
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -24,6 +24,7 @@ from cosalib.cmdlib import ( | |
get_basearch, | ||
sha256sum_file, | ||
import_oci_archive) | ||
from cosalib.meta import GenericBuildMeta | ||
|
||
|
||
def main(): | ||
|
@@ -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() | ||
calculate_and_log_diffs(builds, buildid, arch, starting_buildid) | ||
|
||
if not args.skip_prune: | ||
subprocess.check_call(['/usr/lib/coreos-assembler/cmd-prune']) | ||
|
||
|
@@ -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() | ||
|
||
|
||
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm right, I was thinking that we could directly write the updated |
||
|
||
# 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])) | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line can be simplified by using the
or
operator, which is more concise and idiomatic in Python for this type of assignment.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.