diff --git a/.github/workflows/docker-build-ci.yml b/.github/workflows/docker-build-ci.yml index ada012be80..052fe1cfa1 100644 --- a/.github/workflows/docker-build-ci.yml +++ b/.github/workflows/docker-build-ci.yml @@ -25,11 +25,71 @@ on: pull_request: paths: - '**/Dockerfile*' + - 'docker-bake.hcl' - '.dockerignore' - 'hugegraph-server/hugegraph-dist/docker/**' - 'hugegraph-server/hugegraph-dist/src/assembly/static/bin/util.sh' jobs: + docker-bake-check: + runs-on: ubuntu-24.04 + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Verify shared Maven stages stay identical + shell: bash + run: | + set -euo pipefail + + extract_build_stage() { + awk ' + /^FROM .* AS build$/ { + in_build = 1 + } + in_build && seen && /^FROM / { + exit + } + in_build { + print + seen = 1 + } + ' "$1" + } + + reference="hugegraph-pd/Dockerfile" + for dockerfile in \ + hugegraph-store/Dockerfile \ + hugegraph-server/Dockerfile \ + hugegraph-server/Dockerfile-hstore; do + diff -u \ + <(extract_build_stage "$reference") \ + <(extract_build_stage "$dockerfile") + done + + - name: Validate shared image build graph + run: | + set -euo pipefail + + docker buildx bake --print > /tmp/hugegraph-bake.json + jq -e ' + .group.default.targets == [ + "build-cache", + "pd", + "server-hstore", + "server-standalone", + "store" + ] and + ([.target[] | .platforms] | + all(. == ["linux/amd64", "linux/arm64"])) and + .target["build-cache"].target == "build" and + .target["build-cache"].output[0].type == "cacheonly" and + ([.target | to_entries[] | + select(.key != "build-cache") | + .value.output[0].type] | + all(. == "docker")) + ' /tmp/hugegraph-bake.json + docker-build: runs-on: ubuntu-24.04 strategy: diff --git a/docker-bake.hcl b/docker-bake.hcl new file mode 100644 index 0000000000..94fe0981c4 --- /dev/null +++ b/docker-bake.hcl @@ -0,0 +1,116 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +variable "MAVEN_ARGS" { + default = "" +} + +variable "SOURCE_REVISION" { + default = "local" +} + +variable "IMAGE_TAG" { + default = "local" +} + +variable "CACHE_CHANNEL" { + default = "latest" +} + +variable "EXPORT_CACHE" { + default = false +} + +target "_common" { + context = "." + args = { + MAVEN_ARGS = MAVEN_ARGS + SOURCE_REVISION = SOURCE_REVISION + } + platforms = [ + "linux/amd64", + "linux/arm64", + ] +} + +target "build-cache" { + inherits = ["_common"] + dockerfile = "hugegraph-pd/Dockerfile" + target = "build" + output = ["type=cacheonly"] + cache-from = [ + "type=registry,ref=hugegraph/hugegraph:shared-${CACHE_CHANNEL}", + "type=registry,ref=hugegraph/pd:buildcache-${CACHE_CHANNEL}", + ] + cache-to = EXPORT_CACHE ? [ + "type=registry,ref=hugegraph/hugegraph:shared-${CACHE_CHANNEL},mode=max", + ] : [] +} + +target "pd" { + inherits = ["_common"] + dockerfile = "hugegraph-pd/Dockerfile" + tags = ["hugegraph/pd:${IMAGE_TAG}"] + output = ["type=docker"] + cache-from = [ + "type=registry,ref=hugegraph/hugegraph:shared-${CACHE_CHANNEL}", + "type=registry,ref=hugegraph/pd:buildcache-${CACHE_CHANNEL}", + ] +} + +target "store" { + inherits = ["_common"] + dockerfile = "hugegraph-store/Dockerfile" + tags = ["hugegraph/store:${IMAGE_TAG}"] + output = ["type=docker"] + cache-from = [ + "type=registry,ref=hugegraph/hugegraph:shared-${CACHE_CHANNEL}", + "type=registry,ref=hugegraph/store:buildcache-${CACHE_CHANNEL}", + ] +} + +target "server-hstore" { + inherits = ["_common"] + dockerfile = "hugegraph-server/Dockerfile-hstore" + tags = ["hugegraph/server:${IMAGE_TAG}"] + output = ["type=docker"] + cache-from = [ + "type=registry,ref=hugegraph/hugegraph:shared-${CACHE_CHANNEL}", + "type=registry,ref=hugegraph/server:buildcache-${CACHE_CHANNEL}", + ] +} + +target "server-standalone" { + inherits = ["_common"] + dockerfile = "hugegraph-server/Dockerfile" + tags = ["hugegraph/hugegraph:${IMAGE_TAG}"] + output = ["type=docker"] + cache-from = [ + "type=registry,ref=hugegraph/hugegraph:shared-${CACHE_CHANNEL}", + "type=registry,ref=hugegraph/hugegraph:buildcache-${CACHE_CHANNEL}", + ] +} + +group "default" { + targets = [ + "build-cache", + "pd", + "store", + "server-hstore", + "server-standalone", + ] +} diff --git a/docker/README.md b/docker/README.md index 0ee1f586b6..636e3b13e0 100644 --- a/docker/README.md +++ b/docker/README.md @@ -97,6 +97,10 @@ Builds images locally from source Dockerfiles. Best for **developers** who want Build the matching `hugegraph-toolchain` Hubble source as `local/hugegraph-hubble:dev` before starting this stack. +The publishing pipeline uses the repository-root `docker-bake.hcl` to compile +the Java reactor once and build the PD, Store, HStore Server, and standalone +Server runtime images from that shared result. + ```bash ( cd docker diff --git a/hugegraph-pd/Dockerfile b/hugegraph-pd/Dockerfile index 68e6e2555b..ca526b7757 100644 --- a/hugegraph-pd/Dockerfile +++ b/hugegraph-pd/Dockerfile @@ -25,9 +25,10 @@ WORKDIR /pkg COPY . . ARG MAVEN_ARGS +ARG SOURCE_REVISION=local -RUN --mount=type=cache,target=/root/.m2 \ - mvn package $MAVEN_ARGS -e -B -ntp -Dmaven.test.skip=true -Dmaven.javadoc.skip=true \ +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 \ && rm ./hugegraph-server/*.tar.gz ./hugegraph-pd/*.tar.gz ./hugegraph-store/*.tar.gz # 2nd stage: runtime env diff --git a/hugegraph-server/Dockerfile b/hugegraph-server/Dockerfile index 5caadd23cb..44bc9aa515 100644 --- a/hugegraph-server/Dockerfile +++ b/hugegraph-server/Dockerfile @@ -25,9 +25,10 @@ WORKDIR /pkg COPY . . ARG MAVEN_ARGS +ARG SOURCE_REVISION=local -RUN --mount=type=cache,target=/root/.m2 \ - mvn package $MAVEN_ARGS -e -B -ntp -Dmaven.test.skip=true -Dmaven.javadoc.skip=true \ +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 \ && rm ./hugegraph-server/*.tar.gz ./hugegraph-pd/*.tar.gz ./hugegraph-store/*.tar.gz # 2nd stage: runtime env diff --git a/hugegraph-server/Dockerfile-hstore b/hugegraph-server/Dockerfile-hstore index 7cd64e8f3b..fc99034728 100644 --- a/hugegraph-server/Dockerfile-hstore +++ b/hugegraph-server/Dockerfile-hstore @@ -25,9 +25,10 @@ WORKDIR /pkg COPY . . ARG MAVEN_ARGS +ARG SOURCE_REVISION=local -RUN --mount=type=cache,target=/root/.m2 \ - mvn package $MAVEN_ARGS -e -B -ntp -DskipTests -Dmaven.javadoc.skip=true \ +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 \ && rm ./hugegraph-server/*.tar.gz ./hugegraph-pd/*.tar.gz ./hugegraph-store/*.tar.gz # 2nd stage: runtime env diff --git a/hugegraph-store/Dockerfile b/hugegraph-store/Dockerfile index f1b9db5fd4..90b5228a1a 100644 --- a/hugegraph-store/Dockerfile +++ b/hugegraph-store/Dockerfile @@ -25,9 +25,10 @@ WORKDIR /pkg COPY . . ARG MAVEN_ARGS +ARG SOURCE_REVISION=local -RUN --mount=type=cache,target=/root/.m2 \ - mvn package $MAVEN_ARGS -e -B -ntp -Dmaven.test.skip=true -Dmaven.javadoc.skip=true \ +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 \ && rm ./hugegraph-server/*.tar.gz ./hugegraph-pd/*.tar.gz ./hugegraph-store/*.tar.gz # 2nd stage: runtime env