-
Notifications
You must be signed in to change notification settings - Fork 2k
Ensure packages are installed on images #7991
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
base: main
Are you sure you want to change the base?
Conversation
import docker | ||
|
||
client = docker.from_env() | ||
images = json.loads(open("tests/data/modules/data.json").read()) |
Check warning
Code scanning / CodeQL
File is not always closed Warning test
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 7 days ago
To fix the issue, the file should be opened using a with
statement. This ensures that the file is automatically closed when the block is exited, even if an exception occurs. The with
statement is the most concise and reliable way to handle file operations in Python.
The specific change involves replacing open("tests/data/modules/data.json").read()
with a with
statement that reads the file content and passes it to json.loads
.
-
Copy modified lines R9-R10
@@ -8,3 +8,4 @@ | ||
client = docker.from_env() | ||
images = json.loads(open("tests/data/modules/data.json").read()) | ||
with open("tests/data/modules/data.json") as file: | ||
images = json.loads(file.read()) | ||
|
I'm also thinking from a code perspective, we have 3 pairs of cmd/regex based on base os. I wonder if it'd be better to specify the OS in the json, and have a map to grab the cmd / regex. Super tiny nit, just preference, so feel free to ignore it. Reason for including: in case a change only affects only some of the regexes / commands for the same base os. I do really like the idea! Excellent work! 🙌🏻 |
stretch goal: generate report as a part of workflow after the images are built, similar to DockerScout action in CI jobs where we get list of CVEs. Instead we get list of modules installed. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7991 +/- ##
=======================================
Coverage 52.95% 52.96%
=======================================
Files 90 90
Lines 21729 21729
=======================================
+ Hits 11506 11508 +2
+ Misses 9746 9744 -2
Partials 477 477 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Proposed changes
Describe the use case and detail of the change. If this PR addresses an issue on GitHub, make sure to include a link to
that issue here in this description (not in the title of the PR).
Checklist
Before creating a PR, run through this checklist and mark each as complete.