Skip to content

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Conversation

pdabelf5
Copy link
Collaborator

@pdabelf5 pdabelf5 commented Jul 4, 2025

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.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

@github-actions github-actions bot added python Pull requests that update Python code tests Pull requests that update tests labels Jul 4, 2025
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

File is opened but is not closed.

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.


Suggested changeset 1
tests/suite/test_docker_packages.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/tests/suite/test_docker_packages.py b/tests/suite/test_docker_packages.py
--- a/tests/suite/test_docker_packages.py
+++ b/tests/suite/test_docker_packages.py
@@ -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())
 
EOF
@@ -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())

Copilot is powered by AI and may make mistakes. Always verify output.
@javorszky
Copy link
Contributor

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! 🙌🏻

@vepatel
Copy link
Contributor

vepatel commented Jul 4, 2025

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.

@github-actions github-actions bot added the github_actions Pull requests that update Github_actions code label Jul 4, 2025
Copy link

codecov bot commented Jul 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 52.96%. Comparing base (5744fbc) to head (d2bfa29).
Report is 2 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
github_actions Pull requests that update Github_actions code python Pull requests that update Python code tests Pull requests that update tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants