feat: lazy Java/Maven installation to reduce Docker image size#93
Merged
vpetersson merged 3 commits intomasterfrom Jan 7, 2026
Merged
feat: lazy Java/Maven installation to reduce Docker image size#93vpetersson merged 3 commits intomasterfrom
vpetersson merged 3 commits intomasterfrom
Conversation
Remove Maven and JDK from the base Docker image and install them on-demand only when processing Java or Scala projects. This reduces the image size by ~330MB (from 1.49GB to 1.16GB). Changes: - Add ensure_java_maven_installed() utility that checks for Maven and installs it via apt-get if not present - Call the lazy installer from cdxgen generator for java/scala ecosystems - Remove maven/default-jdk-headless from Dockerfile final stage - Update tests to mock the new installation function The installation is cached for the container lifetime, so subsequent Java SBOM generations in the same run are instant. First Java project adds ~20-30 seconds for the one-time installation.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements lazy installation of Java/Maven dependencies to optimize Docker image size. Instead of including these tools in the base image, they are installed on-demand when processing Java or Scala projects, reducing the image size by approximately 330MB.
Key changes:
- Added
ensure_java_maven_installed()utility function with caching to handle on-demand installation - Integrated lazy installation into the cdxgen generator for Java/Scala ecosystems
- Removed Maven and JDK from the Dockerfile base image
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| sbomify_action/_generation/utils.py | Adds ensure_java_maven_installed() function with global state tracking and apt-get installation logic |
| sbomify_action/_generation/generators/cdxgen.py | Imports and calls the lazy installer before processing Java/Scala projects |
| tests/test_generation_plugin.py | Updates test mocks to include the new ensure_java_maven_installed function |
| Dockerfile | Removes Maven and JDK installation from base image with explanatory comment |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add threading lock to prevent race conditions during concurrent installs - Remove time estimate from log message (varies by machine) - Update Dockerfile comment to actual measured size (~330MB)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Remove Maven and JDK from the base Docker image and install them
on-demand only when processing Java or Scala projects. This reduces
the image size by ~330MB (from 1.49GB to 1.16GB).
Changes:
and installs it via apt-get if not present
The installation is cached for the container lifetime, so subsequent
Java SBOM generations in the same run are instant. First Java project
adds ~20-30 seconds for the one-time installation.