Skip to content
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

rpm2img: use latest rpm release for inventory #342

Merged
merged 1 commit into from
Aug 2, 2024

Conversation

cbgbt
Copy link
Contributor

@cbgbt cbgbt commented Aug 2, 2024

Description of changes:
In cases where Kits contained RPMs built from multiple git checkouts, the Release field in the inventory could be malformed.

This always selects the most-recent release present for the inventory.

Testing done:

  • test using multiple COMMIT_SHAs present
    Before:
  "Content": [
    {
      "Name": "acpid",
      "Publisher": "Bottlerocket",
      "Version": "2.3.0",
      "Release": "2c1d0136\n27f37680\nbr1",
      "InstalledTime": "2024-08-02T19:22:04Z",
      "ApplicationType": "Unspecified",
      "Architecture": "aarch64",
      "Url": "http://sourceforge.net/projects/acpid2/",
      "Summary": "ACPI event daemon"
    },
    {
      "Name": "apiclient",
      "Publisher": "Bottlerocket",
      "Version": "2.3.0",
      "Release": "2c1d0136\n27f37680\nbr1",
      "InstalledTime": "2024-08-02T19:22:04Z",
      "ApplicationType": "Unspecified",
      "Architecture": "aarch64",
      "Url": "https://github.com/bottlerocket-os/bottlerocket",
      "Summary": "Bottlerocket API client"
    },

After:

  "Content": [
    {
      "Name": "acpid",
      "Publisher": "Bottlerocket",
      "Version": "2.3.0",
      "Release": "2c1d0136",
      "InstalledTime": "2024-08-02T19:29:12Z",
      "ApplicationType": "Unspecified",
      "Architecture": "aarch64",
      "Url": "http://sourceforge.net/projects/acpid2/",
      "Summary": "ACPI event daemon"
    },
    {
      "Name": "apiclient",
      "Publisher": "Bottlerocket",
      "Version": "2.3.0",
      "Release": "2c1d0136",
      "InstalledTime": "2024-08-02T19:29:12Z",
      "ApplicationType": "Unspecified",
      "Architecture": "aarch64",
      "Url": "https://github.com/bottlerocket-os/bottlerocket",
      "Summary": "Bottlerocket API client"
    },
  • test a situation in which the GIT_SHA is empty
    I actually couldn't create a package with no BUILD_ID. RPM rejected it.

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

Comment on lines 200 to 204
sort -r -k 1,2 | \
head -n 1 | \
cut -d ' ' -f 3 | \
awk '/^1/{print $1}' | \
cut -d '.' -f 3)"
Copy link
Contributor

Choose a reason for hiding this comment

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

head usage often leads to SIGPIPE since it doesn't keep reading from the pipe after a match, and we have -o pipefail set.

I would just pass it to awk after the initial sort:

Suggested change
sort -r -k 1,2 | \
head -n 1 | \
cut -d ' ' -f 3 | \
awk '/^1/{print $1}' | \
cut -d '.' -f 3)"
sort -r -k 1,2 | \
awk -F '.' 'END {print $--NF}' )"

and maybe add a check that CORE_KIT_GIT_SHA is actually non-zero length.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, I really need to learn more awk. Only modification I made here was to undo the -r since we're grabbing the release from the last line instead of the first.

@cbgbt
Copy link
Contributor Author

cbgbt commented Aug 2, 2024

^ Makes suggestions from @bcressey. Still testing that the if statements catch the failure cases.

@cbgbt cbgbt marked this pull request as ready for review August 2, 2024 19:34
echo "Extracted invalid Git sha from bottlerocket-core-kit: '${CORE_KIT_GIT_SHA}'" >&2
exit 1
fi

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change

@cbgbt cbgbt merged commit 361c3ea into bottlerocket-os:develop Aug 2, 2024
1 check passed
@cbgbt cbgbt deleted the multi-release branch August 2, 2024 19:58
@gthao313 gthao313 mentioned this pull request Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants