Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@devfbe
Copy link
Contributor

@devfbe devfbe commented Aug 24, 2023

Introduce the -f / --fail-on-update-available flag for the "db check" command. If set, the update check command will now return exit code 100 if an db upgrade is available.

This is useful in CICD environments where grype container images, containing the database, should automatically be rebuilt when an database upgrade is available . I have this use case in my container image build pipelines where I have many check jobs for my container images (e.g. my custom grype image) which decide, if a rebuild is necessary.

Use the exit code 100 here (instead of 1), because 1 indicates an error and you want to distinguish errors like a broken internet connection and the fact, that an update is available.

Exit code 100 was a free exit code which is not reserved by any other meaning, so I chose this randomly.

@devfbe devfbe force-pushed the add-return-failure-option-to-update-db-check branch from e259c43 to 58040c2 Compare August 24, 2023 20:55
@tgerla
Copy link
Contributor

tgerla commented Sep 7, 2023

Hey @devfbe, thank you for this patch! We are talking over this idea and wondering if the -f flag is even necessary--what if we skipped the flag and just had "grype db check" return the error code 100 on an available update?

@devfbe
Copy link
Contributor Author

devfbe commented Sep 7, 2023

That's a good question @tgerla!

My thoughts were that this could be a breaking change for people that currently use | grep to check If there is an update available (when pipefail is set as shell opt).

On the other hand side, it's definitely a better approach to signal the result directly without the explicit flag - feels more unix like.

So depending on your choice (breaking change or not) I'll update the merge request. At the Moment I personally would prefer removing the -f flag.

@devfbe devfbe force-pushed the add-return-failure-option-to-update-db-check branch from 58040c2 to 62189f0 Compare September 8, 2023 10:08
Implement that the db update check returns exit code 100 instead of 0,
when a database upgrade is available. This is useful especially in
automated environments which want to decide if they pull the new grype
database / rebuild a grype container image, which contains the current
database.

Signed-off-by: Felix Becker <[email protected]>
@devfbe devfbe force-pushed the add-return-failure-option-to-update-db-check branch from 62189f0 to 1f3371c Compare September 8, 2023 10:17
@devfbe
Copy link
Contributor Author

devfbe commented Sep 8, 2023

Because there were breaking changes in the earlier releases of grype, I guess this is okay to do it again here - It should not affect many users and it's really simple to fix. And returning 100 when db updates are available, really makes sense without a toggle.

I updated the merge request, added only the os.exit(100) lines (removed the old stuff).
Rebased and reworded the commit.

@tgerla
Copy link
Contributor

tgerla commented Sep 8, 2023

Thanks @devfbe, we had the same thoughts--better to get a change like this in before 1.0, anyway! I agree that it probably won't affect too many folks.

Thanks for the updated patch, we'll take a look ASAP.

@spiffcs
Copy link
Contributor

spiffcs commented Sep 8, 2023

Looks like updating to 1.21.1 had some unseen affects and has made contributing harder - I'll take a look at the Go 1.21 articles to see if we can pin down the best setup here so we're not constantly seeing go mod tidy update the toolchain directive across different branches and commits.

@ahoz
Copy link

ahoz commented Sep 14, 2023

Hi all 👋
when can we expect this pr to be merged?
It would be a nice feature for grype automations in pipelines 🚀

@willmurphyscode willmurphyscode self-assigned this Sep 14, 2023
Signed-off-by: Keith Zantow <[email protected]>
Copy link
Contributor

@kzantow kzantow left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @devfbe!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants