Skip to content

perf(docker): improve pd/store/server image build cache efficiency#3025

Open
bitflicker64 wants to merge 2 commits into
apache:masterfrom
bitflicker64:improve-docker-build-cache
Open

perf(docker): improve pd/store/server image build cache efficiency#3025
bitflicker64 wants to merge 2 commits into
apache:masterfrom
bitflicker64:improve-docker-build-cache

Conversation

@bitflicker64
Copy link
Copy Markdown
Contributor

Purpose of the PR

close #2977

Main Changes

.dockerignore (new file)

  • Minimal, intentionally lean — only Docker-specific extras (.git, .github, compose files, docs)
  • Most patterns already covered by .gitignore, not duplicated per maintainer guidance

All 4 Dockerfiles

  • Added COPY --parents **/pom.xml ./ before COPY . . — pom layer only invalidates on pom changes, not source changes
  • Added --mount=type=cache,target=/root/.m2 on mvn package — deps cached across repeated builds
  • Removed vim, cron, service cron start, rm /var/lib/dpkg/info/libc-bin.*, dead code from runtime stage

Note: dependency:go-offline not used — inter-module deps like hg-pd-client aren't on Maven Central and would cause it to fail.

Verifying these changes

  • Need tests and can be verified as follows:
docker build -f hugegraph-pd/Dockerfile -t hugegraph-pd:cache-test .
docker build -f hugegraph-store/Dockerfile -t hugegraph-store:cache-test .
docker build -f hugegraph-server/Dockerfile -t hugegraph-server:cache-test .
docker build -f hugegraph-server/Dockerfile-hstore -t hugegraph-server-hstore:cache-test .

Does this PR potentially affect the following parts?

  • Dependencies (add/update license info & regenerate_known_dependencies.sh)
  • Modify configurations
  • The public API
  • Other affects (typed here)
  • Nope

Documentation Status

  • Doc - No Need

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. ci-cd Build or deploy perf labels May 13, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 1.56%. Comparing base (e108076) to head (4cc2e42).

❗ There is a different number of reports uploaded between BASE (e108076) and HEAD (4cc2e42). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (e108076) HEAD (4cc2e42)
3 2
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #3025       +/-   ##
============================================
- Coverage     35.85%   1.56%   -34.30%     
+ Complexity      338      43      -295     
============================================
  Files           802     780       -22     
  Lines         67995   65480     -2515     
  Branches       8902    8454      -448     
============================================
- Hits          24381    1026    -23355     
- Misses        41008   64368    +23360     
+ Partials       2606      86     -2520     

☔ 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to improve Docker build cache efficiency for HugeGraph PD, Store, and Server images by adding Docker context filtering and BuildKit/Maven cache-related Dockerfile changes.

Changes:

  • Adds a new root .dockerignore.
  • Updates four Dockerfiles to use a pom-only copy layer and Maven cache mounts.
  • Removes some runtime packages and cleanup/startup commands from image build stages.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 15 comments.

Show a summary per file
File Description
.dockerignore Adds Docker build-context exclusions.
hugegraph-pd/Dockerfile Refactors PD image build layers and runtime dependency install.
hugegraph-store/Dockerfile Refactors Store image build layers and runtime dependency install.
hugegraph-server/Dockerfile Refactors Server image build layers and runtime dependency install.
hugegraph-server/Dockerfile-hstore Refactors hstore Server image build layers and runtime dependency install.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread hugegraph-pd/Dockerfile
Comment thread hugegraph-store/Dockerfile
Comment thread hugegraph-server/Dockerfile
Comment thread hugegraph-server/Dockerfile-hstore
Comment thread hugegraph-pd/Dockerfile
Comment on lines +25 to 29
# Copy pom files first — layer is only invalidated when pom files change,
# keeping the Maven cache mount warm across source-only changes.
COPY --parents **/pom.xml ./
ARG MAVEN_ARGS

Comment thread .dockerignore
Comment thread hugegraph-pd/Dockerfile
Comment thread hugegraph-store/Dockerfile
Comment thread hugegraph-server/Dockerfile
Comment thread hugegraph-server/Dockerfile-hstore
- Add .dockerignore to reduce build context noise (defer to .gitignore,
  add **/target/ and Docker-specific extras explicitly)
- Refactor all 4 Dockerfiles: pom-first COPY layer + BuildKit .m2 cache mount
- Add # syntax=docker/dockerfile:1 for compatibility with older Docker versions
- Restore cron in runtime stage to preserve optional monitor support
- Remove dead code: vim, service cron start, rm libc-bin hack, set -x, pwd&&cd
- Update server-ci.yml ubuntu-22.04 -> ubuntu-latest (resolves existing TODO)
@bitflicker64 bitflicker64 requested a review from Copilot May 14, 2026 12:33
Copy link
Copy Markdown
Member

@imbajin imbajin left a comment

Choose a reason for hiding this comment

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

Direction is right but a few blockers remain. See inline for net-new findings; +1'd Copilot's threads on the labs syntax / pom-only layer / root-pom glob (those are correct). Body-level: README/BUILDING should also note the new BuildKit ≥ 0.20 requirement, and removing vim is a behavioral change worth calling out in the commit body for ops folks who exec into containers.

Comment thread .dockerignore
# NOTE: This file intentionally stays minimal.
**/target/
# Most patterns (IDE files, build artifacts, logs, OS files) are already
# covered by .gitignore. Only Docker-specific extras are listed here.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

‼️ The premise here is incorrect — Docker's build context exclusion does not inherit .gitignore. As a result, locally-extracted release dirs (apache-hugegraph-*/, measured at ~790 MB on a normal dev checkout), .idea/, node_modules/, logs/, *.iml, *.class, gen-java/, upload-files/, .vscode/, *.tar.gz, dist/, build/ all leak into every build's context, defeating the cache work in this PR (and risking IDE / secret leakage into image layers).

Suggested change
# covered by .gitignore. Only Docker-specific extras are listed here.
**/target/
# IMPORTANT: .dockerignore does NOT inherit .gitignore — patterns must be restated.
# Pre-extracted release dirs / archives
apache-hugegraph-*/
**/*.tar
**/*.tar.gz*
**/*.zip
**/*.war
# IDE / OS
.idea/
.vscode/
**/*.iml
**/*.iws
**/.DS_Store
# Build / runtime artifacts
**/logs/
**/*.log
**/*.class
**/gen-java/
**/upload-files/
**/dist/
**/build/
**/node_modules/
# Env files
.env.local
.env.*.local
# Git internals
.git
.gitignore
.gitattributes
.github
# Compose / docs not needed in build context
**/docker-compose*.yml
**/docker-compose*.yaml
**/*.md
docs/

build-server:
# TODO: we need test & replace it to ubuntu-24.04 or ubuntu-latest
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

⚠️ Two concerns on this line:

  1. Scope creep: bumping ubuntu-22.04 → ubuntu-latest is unrelated to the Docker cache work in this PR. The original # TODO was a deliberate guard (Ubuntu 24.04 changed default Java, removed legacy packages). Suggest reverting in this PR and splitting into a focused follow-up.
  2. ubuntu-latest drifts when GitHub flips the alias — pin explicitly:
Suggested change
runs-on: ubuntu-latest
runs-on: ubuntu-24.04

Flagging here since it's the only CI file touched: there is no CI workflow that exercises any Dockerfile (verified — zero docker build references under .github/workflows/). PR's verification is "run docker build locally". Future regressions will ship silently. Consider adding a build-only smoke job:

docker-build:
  runs-on: ubuntu-24.04
  strategy:
    matrix:
      dockerfile:
        - hugegraph-pd/Dockerfile
        - hugegraph-store/Dockerfile
        - hugegraph-server/Dockerfile
        - hugegraph-server/Dockerfile-hstore
  steps:
    - uses: actions/checkout@v4
    - uses: docker/setup-buildx-action@v3
    - run: docker buildx build -f ${{ matrix.dockerfile }} --load .

dumb-init \
procps \
curl \
lsof \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🧹 Pre-existing issue (not a regression from this PR, but worth fixing while in the area): the cron package stays installed in the runtime image (~3 MB), but no cron daemon is ever started — dumb-init only execs docker-entrypoint.sh. This means start-hugegraph.sh -m true silently fails to fire its scheduled monitor job, even though crontab_append returns success. Either:

  • Drop cron entirely (saves ~3 MB and removes the false impression that monitor mode works), or
  • Start cron in docker-entrypoint.sh (cron & before the server start) so the feature actually works.

Same applies to Dockerfile-hstore and the PD / Store Dockerfiles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-cd Build or deploy perf size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants