diff --git a/docker/README.md b/docker/README.md index 0bb74cf81f..5123f6b75c 100644 --- a/docker/README.md +++ b/docker/README.md @@ -309,6 +309,56 @@ HUBBLE_PULL_POLICY=never \ docker compose -f docker-compose-hstore.yml up -d --wait ``` +### Image build arguments and cache refresh + +The four Dockerfiles share an identical Maven build stage. `MAVEN_PROJECTS` +selects the Server, PD, and Store distribution modules by default; `-am` +includes their reactor dependencies. Override `MAVEN_PROJECTS` to replace the +selection, and use `MAVEN_ARGS` for other Maven options. Custom selections must +still produce all three distributions used by the shared build and archive +cleanup. + +For example, include the PD CLI in addition to the three distributions. Run +these build commands from the repository root, rather than the `docker/` +directory used by the Compose commands above: + +```bash +MAVEN_PROJECTS=':hugegraph-dist,:hg-pd-dist,:hg-store-dist,:hg-pd-cli' \ +docker buildx bake -f docker/bake.hcl +``` + +Runtime packages are installed before application artifacts are copied, so +source changes reuse the package layer with either local or imported registry +caches. Cached `apt-get update` and installation steps do not check for newer +packages on each build. To refresh them, change `RUNTIME_DEPS_EPOCH` (default +`1`) to a new value when package updates are required: + +```bash +RUNTIME_DEPS_EPOCH=2 docker buildx bake -f docker/bake.hcl +``` + +Keep that value for subsequent builds to reuse the refreshed layer, and choose +a new value for the next refresh. The argument is declared only in the runtime +stage, immediately before the package installation step; overriding it does not +invalidate the Maven build stage. Changes to the base image digest or package +installation instructions also invalidate the package layer. Bake registry +cache export remains opt-in through `EXPORT_CACHE=true`. + +Both arguments also work with direct Dockerfile builds, for example: + +```bash +docker build -f hugegraph-server/Dockerfile \ + --build-arg RUNTIME_DEPS_EPOCH=2 \ + --build-arg MAVEN_PROJECTS=':hugegraph-dist,:hg-pd-dist,:hg-store-dist,:hg-pd-cli' \ + -t hugegraph-standalone:local . +``` + +Build-context narrowing remains a follow-up: sources outside the default +reactor selection still participate in `COPY . .` and can invalidate the Maven +layer. Any future exclusions must preserve the `pom.xml` files referenced by +the reactor and account for custom `MAVEN_PROJECTS` selections and assembly +inputs; excluding entire module directories is not safe. + ### Hubble configuration The three small files under `conf/hubble/` contain only topology-specific diff --git a/docker/bake.hcl b/docker/bake.hcl index da98fa9ace..96087fa128 100644 --- a/docker/bake.hcl +++ b/docker/bake.hcl @@ -19,6 +19,14 @@ variable "MAVEN_ARGS" { default = "" } +variable "MAVEN_PROJECTS" { + default = "hugegraph-server/hugegraph-dist,hugegraph-pd/hg-pd-dist,hugegraph-store/hg-store-dist" +} + +variable "RUNTIME_DEPS_EPOCH" { + default = "1" +} + variable "SOURCE_REVISION" { default = "local" } @@ -38,8 +46,10 @@ variable "EXPORT_CACHE" { target "_common" { context = "." args = { - MAVEN_ARGS = MAVEN_ARGS - SOURCE_REVISION = SOURCE_REVISION + MAVEN_ARGS = MAVEN_ARGS + MAVEN_PROJECTS = MAVEN_PROJECTS + RUNTIME_DEPS_EPOCH = RUNTIME_DEPS_EPOCH + SOURCE_REVISION = SOURCE_REVISION } platforms = [ "linux/amd64", diff --git a/hugegraph-pd/Dockerfile b/hugegraph-pd/Dockerfile index ca526b7757..655860d407 100644 --- a/hugegraph-pd/Dockerfile +++ b/hugegraph-pd/Dockerfile @@ -25,17 +25,18 @@ WORKDIR /pkg COPY . . ARG MAVEN_ARGS +ARG MAVEN_PROJECTS="hugegraph-server/hugegraph-dist,hugegraph-pd/hg-pd-dist,hugegraph-store/hg-store-dist" ARG SOURCE_REVISION=local RUN --mount=type=cache,id=hugegraph-maven-${SOURCE_REVISION},target=/root/.m2,sharing=locked \ - mvn install $MAVEN_ARGS -e -B -ntp -Dmaven.test.skip=true -Dmaven.javadoc.skip=true \ + mvn install -pl "$MAVEN_PROJECTS" \ + -am $MAVEN_ARGS -e -B -ntp -Dmaven.test.skip=true -Dmaven.javadoc.skip=true \ && rm ./hugegraph-server/*.tar.gz ./hugegraph-pd/*.tar.gz ./hugegraph-store/*.tar.gz # 2nd stage: runtime env # Note: ZGC (The Z Garbage Collector) is only supported on ARM-Mac with java > 13 FROM eclipse-temurin:11-jre-jammy -COPY --from=build /pkg/hugegraph-pd/apache-hugegraph-pd-*/ /hugegraph-pd/ LABEL maintainer="HugeGraph Docker Maintainers " # TODO: use g1gc or zgc as default @@ -49,6 +50,7 @@ WORKDIR /hugegraph-pd/ # Note: lsof is gone because its only consumer was the dead check_port removed # from hg-pd-dist bin/util.sh. PD runs no port preflight, so unlike the server # images this needs no socket-table tool in its place. +ARG RUNTIME_DEPS_EPOCH=1 RUN apt-get -q update \ && apt-get -q install -y --no-install-recommends --no-install-suggests \ dumb-init \ @@ -58,6 +60,8 @@ RUN apt-get -q update \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* +COPY --from=build /pkg/hugegraph-pd/apache-hugegraph-pd-*/ /hugegraph-pd/ + # 2. Init docker script COPY hugegraph-pd/hg-pd-dist/docker/docker-entrypoint.sh . RUN chmod 755 ./docker-entrypoint.sh diff --git a/hugegraph-server/Dockerfile b/hugegraph-server/Dockerfile index 44bc9aa515..67866974cf 100644 --- a/hugegraph-server/Dockerfile +++ b/hugegraph-server/Dockerfile @@ -25,17 +25,18 @@ WORKDIR /pkg COPY . . ARG MAVEN_ARGS +ARG MAVEN_PROJECTS="hugegraph-server/hugegraph-dist,hugegraph-pd/hg-pd-dist,hugegraph-store/hg-store-dist" ARG SOURCE_REVISION=local RUN --mount=type=cache,id=hugegraph-maven-${SOURCE_REVISION},target=/root/.m2,sharing=locked \ - mvn install $MAVEN_ARGS -e -B -ntp -Dmaven.test.skip=true -Dmaven.javadoc.skip=true \ + mvn install -pl "$MAVEN_PROJECTS" \ + -am $MAVEN_ARGS -e -B -ntp -Dmaven.test.skip=true -Dmaven.javadoc.skip=true \ && rm ./hugegraph-server/*.tar.gz ./hugegraph-pd/*.tar.gz ./hugegraph-store/*.tar.gz # 2nd stage: runtime env # Note: ZGC (The Z Garbage Collector) is only supported on ARM-Mac with java > 13 FROM eclipse-temurin:11-jre-jammy -COPY --from=build /pkg/hugegraph-server/apache-hugegraph-server-*/ /hugegraph-server/ LABEL maintainer="HugeGraph Docker Maintainers " # TODO: use g1gc or zgc as default @@ -46,11 +47,12 @@ ENV JAVA_OPTS="-XX:+UnlockExperimentalVMOptions -XX:+UseContainerSupport -XX:Max WORKDIR /hugegraph-server/ -# 1. Install runtime dependencies and configure server +# 1. Install runtime dependencies # Note: iproute2 provides `ss`, which the bin/util.sh port preflight needs. The # jammy base image ships neither ss nor netstat, so without it the preflight is # permanently inconclusive and a duplicate start is no longer caught. It # replaces lsof, which no shipped script calls any more. +ARG RUNTIME_DEPS_EPOCH=1 RUN apt-get -q update \ && apt-get -q install -y --no-install-recommends --no-install-suggests \ dumb-init \ @@ -59,8 +61,10 @@ RUN apt-get -q update \ iproute2 \ vim \ && apt-get clean \ - && rm -rf /var/lib/apt/lists/* \ - && sed -i "s/^restserver.url.*$/restserver.url=http:\/\/0.0.0.0:8080/g" ./conf/rest-server.properties + && rm -rf /var/lib/apt/lists/* + +COPY --from=build /pkg/hugegraph-server/apache-hugegraph-server-*/ /hugegraph-server/ +RUN sed -i "s/^restserver.url.*$/restserver.url=http:\/\/0.0.0.0:8080/g" ./conf/rest-server.properties # 2. Init docker script COPY hugegraph-server/hugegraph-dist/docker/scripts/remote-connect.groovy ./scripts diff --git a/hugegraph-server/Dockerfile-hstore b/hugegraph-server/Dockerfile-hstore index fc99034728..e90979563b 100644 --- a/hugegraph-server/Dockerfile-hstore +++ b/hugegraph-server/Dockerfile-hstore @@ -25,21 +25,18 @@ WORKDIR /pkg COPY . . ARG MAVEN_ARGS +ARG MAVEN_PROJECTS="hugegraph-server/hugegraph-dist,hugegraph-pd/hg-pd-dist,hugegraph-store/hg-store-dist" ARG SOURCE_REVISION=local RUN --mount=type=cache,id=hugegraph-maven-${SOURCE_REVISION},target=/root/.m2,sharing=locked \ - mvn install $MAVEN_ARGS -e -B -ntp -Dmaven.test.skip=true -Dmaven.javadoc.skip=true \ + mvn install -pl "$MAVEN_PROJECTS" \ + -am $MAVEN_ARGS -e -B -ntp -Dmaven.test.skip=true -Dmaven.javadoc.skip=true \ && rm ./hugegraph-server/*.tar.gz ./hugegraph-pd/*.tar.gz ./hugegraph-store/*.tar.gz # 2nd stage: runtime env # Note: ZGC (The Z Garbage Collector) is only supported on ARM-Mac with java > 13 FROM eclipse-temurin:11-jre-jammy -COPY --from=build /pkg/hugegraph-server/apache-hugegraph-server-*/ /hugegraph-server/ -# remove hugegraph.properties and rename hstore.properties.template for default hstore backend -RUN cd /hugegraph-server/conf/graphs \ - && rm hugegraph.properties && mv hstore.properties.template hugegraph.properties - LABEL maintainer="HugeGraph Docker Maintainers " # TODO: use g1gc or zgc as default @@ -48,11 +45,12 @@ ENV JAVA_OPTS="-XX:+UnlockExperimentalVMOptions -XX:+UseContainerSupport -XX:Max WORKDIR /hugegraph-server/ -# 1. Install runtime dependencies and configure server +# 1. Install runtime dependencies # Note: iproute2 provides `ss`, which the bin/util.sh port preflight needs. The # jammy base image ships neither ss nor netstat, so without it the preflight is # permanently inconclusive and a duplicate start is no longer caught. It # replaces lsof, which no shipped script calls any more. +ARG RUNTIME_DEPS_EPOCH=1 RUN apt-get -q update \ && apt-get -q install -y --no-install-recommends --no-install-suggests \ dumb-init \ @@ -61,7 +59,13 @@ RUN apt-get -q update \ iproute2 \ vim \ && apt-get clean \ - && rm -rf /var/lib/apt/lists/* \ + && rm -rf /var/lib/apt/lists/* + +COPY --from=build /pkg/hugegraph-server/apache-hugegraph-server-*/ /hugegraph-server/ +# Configure the default HStore backend and REST listen address +RUN cd /hugegraph-server/conf/graphs \ + && rm hugegraph.properties && mv hstore.properties.template hugegraph.properties \ + && cd /hugegraph-server \ && sed -i "s/^restserver.url.*$/restserver.url=http:\/\/0.0.0.0:8080/g" ./conf/rest-server.properties # 2. Init docker script diff --git a/hugegraph-store/Dockerfile b/hugegraph-store/Dockerfile index 90b5228a1a..988b472b09 100644 --- a/hugegraph-store/Dockerfile +++ b/hugegraph-store/Dockerfile @@ -25,17 +25,18 @@ WORKDIR /pkg COPY . . ARG MAVEN_ARGS +ARG MAVEN_PROJECTS="hugegraph-server/hugegraph-dist,hugegraph-pd/hg-pd-dist,hugegraph-store/hg-store-dist" ARG SOURCE_REVISION=local RUN --mount=type=cache,id=hugegraph-maven-${SOURCE_REVISION},target=/root/.m2,sharing=locked \ - mvn install $MAVEN_ARGS -e -B -ntp -Dmaven.test.skip=true -Dmaven.javadoc.skip=true \ + mvn install -pl "$MAVEN_PROJECTS" \ + -am $MAVEN_ARGS -e -B -ntp -Dmaven.test.skip=true -Dmaven.javadoc.skip=true \ && rm ./hugegraph-server/*.tar.gz ./hugegraph-pd/*.tar.gz ./hugegraph-store/*.tar.gz # 2nd stage: runtime env # Note: ZGC (The Z Garbage Collector) is only supported on ARM-Mac with java > 13 FROM eclipse-temurin:11-jre-jammy -COPY --from=build /pkg/hugegraph-store/apache-hugegraph-store-*/ /hugegraph-store/ LABEL maintainer="HugeGraph Docker Maintainers " # TODO: use g1gc or zgc as default @@ -49,6 +50,7 @@ WORKDIR /hugegraph-store/ # Note: lsof is gone because its only consumer was the dead check_port removed # from hg-store-dist bin/util.sh. Store runs no port preflight, so unlike the # server images this needs no socket-table tool in its place. +ARG RUNTIME_DEPS_EPOCH=1 RUN apt-get -q update \ && apt-get -q install -y --no-install-recommends --no-install-suggests \ dumb-init \ @@ -58,6 +60,8 @@ RUN apt-get -q update \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* +COPY --from=build /pkg/hugegraph-store/apache-hugegraph-store-*/ /hugegraph-store/ + # 2. Init docker script COPY hugegraph-store/hg-store-dist/docker/docker-entrypoint.sh . RUN chmod 755 ./docker-entrypoint.sh