incubator-hugegraph icon indicating copy to clipboard operation
incubator-hugegraph copied to clipboard

[Task] Improve Docker build cache efficiency for pd/store/server images

Open imbajin opened this issue 8 months ago • 7 comments

Background

The Docker images for hugegraph-pd, hugegraph-store, and hugegraph-server currently build with this pattern:

  1. COPY . /pkg
  2. RUN mvn package ...
  3. Copy build outputs into runtime image

This causes low cache efficiency:

  • Any repository file change (even non-Java files) can invalidate the COPY layer.
  • The expensive mvn package step is re-run too often.
  • CI time stays high even when Java code is unchanged.

Goal

Improve the Docker build cache hit rate and reduce unnecessary Maven rebuild time, without changing image runtime behavior.

Scope (Starter Task / Phase A)

Please focus on the low-risk, high-impact subset:

  • Improve .dockerignore to exclude files that should not affect the image build cache (for example: IDE files, some markdown/text files. etc).
  • Refactor Dockerfile layer order so dependency-related files are copied before source files where practical.
  • Use BuildKit Maven cache mount (--mount=type=cache,target=/root/.m2) in Maven build steps.
  • Keep existing image entrypoints/ports/runtime behavior unchanged.

Out of Scope (Do NOT include in this issue)

  • Full artifact pipeline split ("build once, package many images").
  • Cross-repo CI architecture redesign.
  • New release logic or tag strategy changes.

Deliverables

  • A PR with Dockerfile and/or .dockerignore updates.
  • A short before/after note from CI showing cache behavior and build time delta.

Acceptance Criteria

  • A second build with no Java source changes shows a clear improvement in build time and/or cache hits.
  • Existing image smoke/integration checks still pass.
  • No functional regression in generated images.

Suggested Starting Points

  • hugegraph-pd/Dockerfile
  • hugegraph-store/Dockerfile
  • hugegraph-server/Dockerfile
  • hugegraph-server/Dockerfile-hstore

If the scope starts growing, keep this issue focused on Phase A and open follow-up issues for larger refactors.

imbajin avatar Mar 22 '26 13:03 imbajin

To provide a full roadmap, here is the suggested follow-up plan after Phase A.

Roadmap overview
Phase A (this issue) -> Phase B (build once/package many) -> Phase C (long-term maintainability)

Phase B (Core Efficiency): Build Once, Package Many

Objective

Remove repeated Maven builds across pd/store/server image pipelines by producing reusable build artifacts once per commit.

Suggested Scope

  • Add a CI step/job that runs Maven once and produces standardized artifacts for:
    • pd
    • store
    • server-hstore
    • server-standalone
  • Publish these artifacts via CI artifact storage.
  • Refactor image builds to consume artifacts instead of running mvn package inside each image Dockerfile.
  • Keep runtime image behavior unchanged (entrypoint, ports, env defaults).

Acceptance Criteria

  • Maven build is executed once per commit in the image publish flow.
  • pd/store/server images are packaged from the produced artifacts.
  • Functional parity with current images is verified by smoke/integration checks.
  • End-to-end CI time for the full image set shows a significant reduction.

Recommendation

Track Phase B in one dedicated issue/PR series, because it changes build architecture and cross-job artifact flow.

Phase C (Maintainability): Configuration and Script Convergence

Objective

Reduce long-term maintenance overhead and avoid drift between server variants.

Suggested Scope

  • Consolidate duplicated startup/config templating logic where possible.
  • Clearly model variant-specific behavior (standalone vs hstore) through parameters/templates.
  • Add lightweight build observability:
    • module-level build duration
    • cache hit/miss indicators
    • architecture-level trend tracking (amd64 / arm64)

Acceptance Criteria

  • Shared logic is centralized and variant differences remain explicit.
  • No runtime behavior regression for either server mode.
  • Build metrics are visible enough to validate future optimization impact.

Recommendation

Treat Phase C as incremental improvements across multiple small PRs after Phase B is stable.


Could use sub-issue / task for each step

imbajin avatar Mar 22 '26 13:03 imbajin

I would like to work on it. Could you assign it to me?

zeel2104 avatar Mar 23 '26 19:03 zeel2104

I would like to work on it. Could you assign it to me?

@zeel2104 Fine, u could attach/comment a plan doc for it firstly~ (we'll review it)

imbajin avatar Mar 24 '26 03:03 imbajin

Hey @imbajin, I’d like to work on this.

For Phase A, I’m planning to start with improving the .dockerignore across pd, store, and server to avoid unnecessary cache invalidation (e.g., excluding .git, IDE files, logs, target dirs, etc.).

Then I’ll refactor the Dockerfiles (pd, store, server, and hstore) to copy dependency related files (like pom.xml) before the source code so Docker can cache dependencies more effectively.

I’ll also add BuildKit cache mounts for Maven (--mount=type=cache,target=/root/.m2) to avoid re downloading dependencies on each build.

For validation, I’ll run two builds back to back without Java changes and include a before/after comparison in the PR.

I won’t be changing any runtime behavior (entrypoints, ports, etc.).

Let me know if that approach sounds good!

zeel2104 avatar Mar 24 '26 03:03 zeel2104

Hey @imbajin, I’d like to work on this.

For Phase A, I’m planning to start with improving the .dockerignore across pd, store, and server to avoid unnecessary cache invalidation (e.g., excluding .git, IDE files, logs, target dirs, etc.).

Then I’ll refactor the Dockerfiles (pd, store, server, and hstore) to copy dependency related files (like pom.xml) before the source code so Docker can cache dependencies more effectively.

I’ll also add BuildKit cache mounts for Maven (--mount=type=cache,target=/root/.m2) to avoid re downloading dependencies on each build.

For validation, I’ll run two builds back to back without Java changes and include a before/after comparison in the PR.

I won’t be changing any runtime behavior (entrypoints, ports, etc.).

Let me know if that approach sounds good!

Sounds good to me, and remember the .dockerignore should refer .gitignore first (avoid duplicate)

imbajin avatar Mar 24 '26 13:03 imbajin

Hi, this issue aseems to be incomplete. Could you assign it to me?

peakxy avatar Apr 13 '26 08:04 peakxy

Hey @imbajin, hope you don't mind since the previous attempt went inactive I went ahead and opened a pr

bitflicker64 avatar May 13 '26 20:05 bitflicker64