Skip to content

split app into layers for more efficent building - #112

Merged
fmazmz merged 3 commits into
mainfrom
fix/103-docker-image-optimization
Feb 23, 2026
Merged

split app into layers for more efficent building#112
fmazmz merged 3 commits into
mainfrom
fix/103-docker-image-optimization

Conversation

@jesperlarsson1910

@jesperlarsson1910 jesperlarsson1910 commented Feb 22, 2026

Copy link
Copy Markdown

Updater dockerfile to handle the different layers instead of entire jar

Summary by CodeRabbit

  • Chores
    • Updated runtime packaging to extract and include application dependencies alongside compiled classes.
    • Modified startup to use an explicit classpath that loads compiled classes and dependency libraries separately, improving deployment reliability and enabling smaller runtime images.

Signed-off-by: Jesper Larsson <jesper.larsson@iths.se>
@jesperlarsson1910 jesperlarsson1910 linked an issue Feb 22, 2026 that may be closed by this pull request
@coderabbitai

coderabbitai Bot commented Feb 22, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Dockerfile changed build and startup: Maven now extracts runtime dependencies to target/deps and package is built without shading; Docker copies dependency jars to libs/, compiled classes to classes/, and ENTRYPOINT starts the app with java -cp "classes:libs/*" org.juv25d.App. (45 words)

Changes

Cohort / File(s) Summary
Docker Configuration
Dockerfile
Add Maven step to copy runtime dependencies to target/deps and use -Dmaven.shade.skip=true; copy dependencies into libs/ and compiled classes into classes/; switch ENTRYPOINT from a single bundled jar to java -cp "classes:libs/*" org.juv25d.App.

Sequence Diagram(s)

sequenceDiagram
  participant Maven as Build (Maven)
  participant Docker as Docker build
  participant Image as Runtime image FS
  participant JVM as Container JVM

  Maven->>Docker: produce `target/deps`, compiled `classes/`
  Docker->>Image: COPY dependency jars -> `libs/`
  Docker->>Image: COPY compiled classes -> `classes/`
  Image->>JVM: container starts
  JVM->>Image: run `java -cp "classes:libs/*" org.juv25d.App`
  JVM-->>Image: application uses explicit classpath
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A rabbit packs jars in rows with care,
Classes hop home, dependencies share,
No shaded jar, just a tidy path,
java -cp sings the startup math. 🐇

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: splitting Docker build layers to handle dependencies separately from application classes for more efficient building.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/103-docker-image-optimization

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Dockerfile`:
- Line 31: The Dockerfile currently copies processed resources from the source
path using the COPY instruction "COPY --from=build /app/src/main/resources/
resources/", which bypasses Maven resource filtering; change the COPY to pull
processed classes/resources from Maven's output (e.g., use "COPY --from=build
/app/target/classes/ classes/" or collapse class/resource copies into a single
"COPY --from=build /app/target/classes/ classes/") so the Docker image contains
Maven-filtered/processed resources rather than raw src files.
- Line 11: Update the Dockerfile RUN that executes mvn
dependency:copy-dependencies so it passes -DincludeScope=runtime (leave the rest
of the command intact) to ensure only compile+runtime artifacts are copied into
target/deps and therefore into the libs/ layer of the runtime image; locate the
RUN line invoking mvn dependency:copy-dependencies and add the
-DincludeScope=runtime flag.
- Around line 19-29: The Dockerfile currently copies each org/juv25d subpackage
individually (the multiple COPY --from=build ... org/juv25d/... lines), which
will miss any new packages; replace those explicit per-package COPY lines with a
single recursive copy of the entire Maven output (COPY --from=build
/app/target/classes/ classes/) and remove the now-redundant separate resources
copy and the extra resources classpath entry in the ENTRYPOINT; also update the
ENTRYPOINT to reference only the classes path (drop the former resources entry)
so runtime classpath uses the full target/classes tree.

Comment thread Dockerfile Outdated
Comment thread Dockerfile Outdated
Comment thread Dockerfile Outdated
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@Dockerfile`:
- Line 31: The Dockerfile copies raw resources from the source tree with the
COPY instruction "COPY --from=build /app/src/main/resources/ resources/", which
bypasses Maven resource filtering; change it to copy processed resources from
the build output (e.g., /app/target/classes/ or the build stage path where Maven
writes processed resources) so that Maven property substitutions and Spring
placeholders are resolved before they are baked into the image; update the COPY
target used in the Dockerfile to reference the processed resources location
instead of /app/src/main/resources/.
- Around line 19-29: The Dockerfile currently enumerates each org/juv25d
subpackage with many COPY lines (e.g., the multiple "COPY --from=build
/app/target/classes/org/juv25d/..." entries) which is fragile and will miss new
packages; replace those per-package COPYs with a single recursive copy of the
entire target/classes directory (copy /app/target/classes/ to classes/), and
remove the separate resources COPY and the corresponding resources entry from
the ENTRYPOINT since Maven already places processed resources into
target/classes; ensure only the single recursive classes copy remains and update
ENTRYPOINT to use the classes classpath entry that matches this change.

@fmazmz

fmazmz commented Feb 23, 2026

Copy link
Copy Markdown
Member

hmm, does this not mean we have to keep updating the docker file whenever we change our package structure, or add a new package, or remove a package, etc...?

Seems like that will be a burden and an easy point of failure?

@jesperlarsson1910

Copy link
Copy Markdown
Author

@fmazmz indeed, after looking into it based on the rabbit feedback it's also redundant. So changing it to only split the dependencies from the classes which should work with changes to our packages.

… the .jar

Signed-off-by: Jesper Larsson <jesper.larsson@iths.se>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
Dockerfile (2)

9-10: Consider combining both mvn invocations into a single RUN step.

Two separate Maven JVM startups cost a few seconds each on every build. They can be collapsed into one command without losing anything:

♻️ Proposed refactor
-RUN mvn clean package -DskipTests -Dmaven.shade.skip=true
-RUN mvn dependency:copy-dependencies -DoutputDirectory=target/deps -DincludeScope=runtime
+RUN mvn -B clean package dependency:copy-dependencies \
+        -DskipTests \
+        -Dmaven.shade.skip=true \
+        -DoutputDirectory=target/deps \
+        -DincludeScope=runtime

This also makes the -B (batch/no-progress) flag consistent with how go-offline is called on line 6.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Dockerfile` around lines 9 - 10, Combine the two separate Maven RUN steps
into a single RUN to avoid two JVM startups: run mvn with both goals in one
invocation (clean package -DskipTests -Dmaven.shade.skip=true
dependency:copy-dependencies -DoutputDirectory=target/deps
-DincludeScope=runtime) and add the -B flag for batch mode to match the existing
go-offline invocation; update the Dockerfile by replacing the two RUN lines
referencing "mvn clean package ..." and "mvn dependency:copy-dependencies ..."
with a single RUN that includes both goals and -B.

12-12: Prefer explicit Alpine-version tag for consistency with Java 25 security patches.

The eclipse-temurin:25-jre-alpine tag exists and builds successfully. However, unversioned alpine tags (e.g., 25-jre-alpine) can lag behind newer Alpine minor versions in the official-images manifest. To ensure you pull the latest Alpine security patches, use the explicit version-pinned variant:

Suggested improvement
-FROM eclipse-temurin:25-jre-alpine
+FROM eclipse-temurin:25-jre-alpine-3.23

This is a best-practice recommendation, not a blocking issue.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@Dockerfile` at line 12, The FROM line currently uses an unpinned Alpine image
tag; update the Dockerfile's FROM directive (the line 'FROM
eclipse-temurin:25-jre-alpine') to a version-pinned Alpine variant (for example
'eclipse-temurin:25-jre-alpine3.18' or another current alpine3.x minor) so Java
25 images receive explicit Alpine security patching, then rebuild to verify
compatibility and update any Docker documentation if needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@Dockerfile`:
- Around line 9-10: Combine the two separate Maven RUN steps into a single RUN
to avoid two JVM startups: run mvn with both goals in one invocation (clean
package -DskipTests -Dmaven.shade.skip=true dependency:copy-dependencies
-DoutputDirectory=target/deps -DincludeScope=runtime) and add the -B flag for
batch mode to match the existing go-offline invocation; update the Dockerfile by
replacing the two RUN lines referencing "mvn clean package ..." and "mvn
dependency:copy-dependencies ..." with a single RUN that includes both goals and
-B.
- Line 12: The FROM line currently uses an unpinned Alpine image tag; update the
Dockerfile's FROM directive (the line 'FROM eclipse-temurin:25-jre-alpine') to a
version-pinned Alpine variant (for example 'eclipse-temurin:25-jre-alpine3.18'
or another current alpine3.x minor) so Java 25 images receive explicit Alpine
security patching, then rebuild to verify compatibility and update any Docker
documentation if needed.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5d610b2 and 41bb18a.

📒 Files selected for processing (1)
  • Dockerfile

@fmazmz

fmazmz commented Feb 23, 2026

Copy link
Copy Markdown
Member

Nice, looks better.
Can we push a tag in this branch and trigger the docker build to run so we can test it before merging?

@fmazmz

fmazmz commented Feb 23, 2026

Copy link
Copy Markdown
Member

Looks good, I was able to run the docker image fine with no errors.
We can delete the tag & merge this PR.

Later we can deploy a new tag to main to get all the new features and deploy a new release!

@fmazmz
fmazmz requested a review from kristinaxm February 23, 2026 20:15
@fmazmz
fmazmz merged commit 7453592 into main Feb 23, 2026
3 checks passed
@fmazmz
fmazmz deleted the fix/103-docker-image-optimization branch February 23, 2026 20:18
@jesperlarsson1910

Copy link
Copy Markdown
Author

Looks good, I was able to run the docker image fine with no errors. We can delete the tag & merge this PR.

Later we can deploy a new tag to main to get all the new features and deploy a new release!

Nice, thanks for cleaning up and merging!

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.

Docker image optimization, copy individual files

3 participants