Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 72 additions & 17 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,99 @@
# limitations under the License.
#

version: "3"
name: hugegraph-single

networks:
hg-net:
driver: bridge

Comment thread
bitflicker64 marked this conversation as resolved.
volumes:
hg-pd-data:
hg-store-data:

services:
pd:
image: hugegraph/pd
container_name: pd
build:
context: ..
dockerfile: hugegraph-pd/Dockerfile
image: hugegraph/pd:${HUGEGRAPH_VERSION:-1.7.0}
Comment thread
bitflicker64 marked this conversation as resolved.
Outdated
container_name: hg-pd
hostname: pd
network_mode: host
restart: unless-stopped
networks: [hg-net]
environment:
HG_PD_GRPC_HOST: pd
HG_PD_GRPC_PORT: "8686"
Comment thread
bitflicker64 marked this conversation as resolved.
HG_PD_REST_PORT: "8620"
HG_PD_RAFT_ADDRESS: pd:8610
HG_PD_RAFT_PEERS_LIST: pd:8610
HG_PD_INITIAL_STORE_LIST: store:8500
HG_PD_DATA_PATH: /hugegraph-pd/pd_data
ports:
- "8620:8620"
Comment thread
bitflicker64 marked this conversation as resolved.
- "8686:8686"
volumes:
- hg-pd-data:/hugegraph-pd/pd_data
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8620"]
test: ["CMD-SHELL", "curl -fsS http://localhost:8620/v1/health >/dev/null || exit 1"]
interval: 10s
timeout: 5s
retries: 3
retries: 12
start_period: 20s

store:
image: hugegraph/store
container_name: store
build:
context: ..
dockerfile: hugegraph-store/Dockerfile
image: hugegraph/store:${HUGEGRAPH_VERSION:-1.7.0}
container_name: hg-store
hostname: store
network_mode: host
restart: unless-stopped
networks: [hg-net]
depends_on:
pd:
condition: service_healthy
Comment thread
bitflicker64 marked this conversation as resolved.
environment:
HG_STORE_PD_ADDRESS: pd:8686
HG_STORE_GRPC_HOST: store
HG_STORE_GRPC_PORT: "8500"
HG_STORE_REST_PORT: "8520"
HG_STORE_RAFT_ADDRESS: store:8510
HG_STORE_DATA_PATH: /hugegraph-store/storage
ports:
- "8520:8520"
- "8500:8500"
- "8510:8510"
volumes:
- hg-store-data:/hugegraph-store/storage
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8520"]
test: ["CMD-SHELL", "curl -fsS http://localhost:8520/v1/health >/dev/null && curl -fsS http://pd:8620/v1/health >/dev/null || exit 1"]
Comment thread
bitflicker64 marked this conversation as resolved.
Outdated
interval: 10s
timeout: 5s
retries: 3
timeout: 10s
retries: 30
start_period: 30s

server:
image: hugegraph/server
container_name: server
build:
context: ..
dockerfile: hugegraph-server/Dockerfile-hstore
image: hugegraph/server:${HUGEGRAPH_VERSION:-1.7.0}
container_name: hg-server
Comment thread
bitflicker64 marked this conversation as resolved.
hostname: server
network_mode: host
restart: unless-stopped
networks: [hg-net]
depends_on:
store:
condition: service_healthy
Comment thread
bitflicker64 marked this conversation as resolved.
environment:
HG_GRAPH: hugegraph
Comment thread
bitflicker64 marked this conversation as resolved.
Outdated
HG_SERVER_BACKEND: hstore
HG_SERVER_PD_PEERS: pd:8686
ports:
- "8080:8080"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080"]
test: ["CMD-SHELL", "curl -fsS http://localhost:8080/versions >/dev/null || exit 1"]
interval: 10s
timeout: 5s
retries: 3
retries: 30
start_period: 60s
68 changes: 66 additions & 2 deletions hugegraph-pd/hg-pd-dist/docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,72 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
set -euo pipefail

# start hugegraph pd
./bin/start-hugegraph-pd.sh -j "$JAVA_OPTS"
log() { echo "[hugegraph-pd-entrypoint] $*"; }

fail_on_deprecated() {
local old_name="$1" new_name="$2"
if [[ -n "${!old_name:-}" ]]; then
echo "ERROR: deprecated env '${old_name}' detected. Use '${new_name}' instead." >&2
exit 2
fi
}

require_env() {
local name="$1"
if [[ -z "${!name:-}" ]]; then
echo "ERROR: missing required env '${name}'" >&2; exit 2
fi
}

json_escape() {
local s="$1"
s=${s//\\/\\\\}; s=${s//\"/\\\"}; s=${s//$'\n'/}
printf "%s" "$s"
}

# ── Guard deprecated vars ─────────────────────────────────────────────
fail_on_deprecated "GRPC_HOST" "HG_PD_GRPC_HOST"
fail_on_deprecated "RAFT_ADDRESS" "HG_PD_RAFT_ADDRESS"
fail_on_deprecated "RAFT_PEERS" "HG_PD_RAFT_PEERS_LIST"
fail_on_deprecated "PD_INITIAL_STORE_LIST" "HG_PD_INITIAL_STORE_LIST"

# ── Required vars ─────────────────────────────────────────────────────
require_env "HG_PD_GRPC_HOST"
require_env "HG_PD_RAFT_ADDRESS"
require_env "HG_PD_RAFT_PEERS_LIST"
require_env "HG_PD_INITIAL_STORE_LIST"
Comment thread
bitflicker64 marked this conversation as resolved.

# ── Defaults ──────────────────────────────────────────────────────────
: "${HG_PD_GRPC_PORT:=8686}"
: "${HG_PD_REST_PORT:=8620}"
: "${HG_PD_DATA_PATH:=/hugegraph-pd/pd_data}"
: "${HG_PD_INITIAL_STORE_COUNT:=1}"

# ── Build SPRING_APPLICATION_JSON ─────────────────────────────────────
SPRING_APPLICATION_JSON="$(cat <<JSON
{
"grpc": { "host": "$(json_escape "${HG_PD_GRPC_HOST}")",
"port": "$(json_escape "${HG_PD_GRPC_PORT}")" },
"server": { "port": "$(json_escape "${HG_PD_REST_PORT}")" },
"raft": { "address": "$(json_escape "${HG_PD_RAFT_ADDRESS}")",
"peers-list": "$(json_escape "${HG_PD_RAFT_PEERS_LIST}")" },
"pd": { "data-path": "$(json_escape "${HG_PD_DATA_PATH}")",
"initial-store-list": "$(json_escape "${HG_PD_INITIAL_STORE_LIST}")" }
Comment thread
bitflicker64 marked this conversation as resolved.
Outdated
Comment thread
bitflicker64 marked this conversation as resolved.
Outdated
}
JSON
)"
export SPRING_APPLICATION_JSON

log "effective config:"
log " grpc.host=${HG_PD_GRPC_HOST}"
log " grpc.port=${HG_PD_GRPC_PORT}"
log " server.port=${HG_PD_REST_PORT}"
log " raft.address=${HG_PD_RAFT_ADDRESS}"
log " raft.peers-list=${HG_PD_RAFT_PEERS_LIST}"
log " pd.initial-store-list=${HG_PD_INITIAL_STORE_LIST}"
log " pd.data-path=${HG_PD_DATA_PATH}"

./bin/start-hugegraph-pd.sh -j "${JAVA_OPTS:-}"
tail -f /dev/null
Comment thread
bitflicker64 marked this conversation as resolved.
70 changes: 52 additions & 18 deletions hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,66 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
set -euo pipefail

# create a folder to save the docker-related file
DOCKER_FOLDER='./docker'
mkdir -p $DOCKER_FOLDER

DOCKER_FOLDER="./docker"
INIT_FLAG_FILE="init_complete"
GRAPH_CONF="./conf/graphs/hugegraph.properties"

mkdir -p "${DOCKER_FOLDER}"

log() { echo "[hugegraph-server-entrypoint] $*"; }

fail_on_deprecated() {
local old_name="$1" new_name="$2"
if [[ -n "${!old_name:-}" ]]; then
echo "ERROR: deprecated env '${old_name}' detected. Use '${new_name}' instead." >&2
exit 2
fi
}

set_prop() {
local key="$1" val="$2" file="$3"
Comment thread
bitflicker64 marked this conversation as resolved.
if grep -q -E "^[[:space:]]*${key}[[:space:]]*=" "${file}"; then
sed -ri "s#^([[:space:]]*${key}[[:space:]]*=).*#\\1${val}#" "${file}"
else
echo "${key}=${val}" >> "${file}"
fi
}

if [ ! -f "${DOCKER_FOLDER}/${INIT_FLAG_FILE}" ]; then
# wait for storage backend
./bin/wait-storage.sh
if [ -z "$PASSWORD" ]; then
echo "init hugegraph with non-auth mode"
# ── Guard deprecated vars ─────────────────────────────────────────────
fail_on_deprecated "BACKEND" "HG_SERVER_BACKEND"
Comment thread
bitflicker64 marked this conversation as resolved.
Outdated
fail_on_deprecated "PD_PEERS" "HG_SERVER_PD_PEERS"

# ── Map env → properties file ─────────────────────────────────────────
[[ -n "${HG_SERVER_BACKEND:-}" ]] && set_prop "backend" "${HG_SERVER_BACKEND}" "${GRAPH_CONF}"
[[ -n "${HG_SERVER_PD_PEERS:-}" ]] && set_prop "pd.peers" "${HG_SERVER_PD_PEERS}" "${GRAPH_CONF}"

# ── Build wait-storage env ─────────────────────────────────────────────
WAIT_ENV=()
[[ -n "${HG_SERVER_BACKEND:-}" ]] && WAIT_ENV+=("hugegraph.backend=${HG_SERVER_BACKEND}")
[[ -n "${HG_SERVER_PD_PEERS:-}" ]] && WAIT_ENV+=("hugegraph.pd.peers=${HG_SERVER_PD_PEERS}")

# ── Init store (once) ─────────────────────────────────────────────────
if [[ ! -f "${DOCKER_FOLDER}/${INIT_FLAG_FILE}" ]]; then
if (( ${#WAIT_ENV[@]} > 0 )); then
env "${WAIT_ENV[@]}" ./bin/wait-storage.sh
else
./bin/wait-storage.sh
fi

if [[ -z "${PASSWORD:-}" ]]; then
log "init hugegraph with non-auth mode"
./bin/init-store.sh
else
echo "init hugegraph with auth mode"
log "init hugegraph with auth mode"
./bin/enable-auth.sh
echo "$PASSWORD" | ./bin/init-store.sh
echo "${PASSWORD}" | ./bin/init-store.sh
fi
Comment thread
bitflicker64 marked this conversation as resolved.
# create a flag file to avoid re-init when restarting
touch ${DOCKER_FOLDER}/${INIT_FLAG_FILE}
touch "${DOCKER_FOLDER}/${INIT_FLAG_FILE}"
else
echo "Hugegraph Initialization already done. Skipping re-init..."
log "HugeGraph initialization already done. Skipping re-init..."
fi

# start hugegraph-server
# remove "-g zgc" now, which is only available on ARM-Mac with java > 13
./bin/start-hugegraph.sh -j "$JAVA_OPTS"

./bin/start-hugegraph.sh -j "${JAVA_OPTS:-}"
tail -f /dev/null
Comment thread
bitflicker64 marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function abs_path() {
BIN=$(abs_path)
TOP="$(cd "$BIN"/../ && pwd)"
GRAPH_CONF="$TOP/conf/graphs/hugegraph.properties"
WAIT_STORAGE_TIMEOUT_S=120
WAIT_STORAGE_TIMEOUT_S=300
DETECT_STORAGE="$TOP/scripts/detect-storage.groovy"

. "$BIN"/util.sh
Expand Down Expand Up @@ -70,7 +70,28 @@ done < <(env | sort -r | awk -F= '{ st = index($0, "="); print $1 " " substr($0,
# wait for storage
if env | grep '^hugegraph\.' > /dev/null; then
if [ -n "${WAIT_STORAGE_TIMEOUT_S:-}" ]; then
timeout "${WAIT_STORAGE_TIMEOUT_S}s" bash -c \
"until bin/gremlin-console.sh -- -e $DETECT_STORAGE > /dev/null 2>&1; do echo \"Hugegraph server are waiting for storage backend...\"; sleep 5; done"
# Extract pd.peers from config or environment
PD_PEERS="${hugegraph_pd_peers:-}"
if [ -z "$PD_PEERS" ]; then
PD_PEERS=$(grep -E "^\s*pd\.peers\s*=" "$GRAPH_CONF" | sed 's/.*=\s*//' | tr -d ' ')
fi

if [ -n "$PD_PEERS" ]; then
# Convert gRPC address to REST address (8686 -> 8620)
PD_REST=$(echo "$PD_PEERS" | sed 's/:8686/:8620/g' | cut -d',' -f1)
Comment thread
bitflicker64 marked this conversation as resolved.
Outdated
echo "Waiting for PD REST endpoint at $PD_REST..."

timeout "${WAIT_STORAGE_TIMEOUT_S}s" bash -c "
until curl -fsS http://${PD_REST}/v1/health >/dev/null 2>&1; do
echo 'Hugegraph server are waiting for storage backend...'
sleep 5
done
echo 'PD is reachable, waiting extra 10s for store registration...'
sleep 10
echo 'Storage backend is ready!'
" || echo "Warning: Timeout waiting for storage, proceeding anyway..."
else
echo "No pd.peers configured, skipping storage wait..."
fi
Comment thread
bitflicker64 marked this conversation as resolved.
fi
fi
64 changes: 62 additions & 2 deletions hugegraph-store/hg-store-dist/docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,68 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
set -euo pipefail

# start hugegraph store
./bin/start-hugegraph-store.sh -j "$JAVA_OPTS"
log() { echo "[hugegraph-store-entrypoint] $*"; }

fail_on_deprecated() {
local old_name="$1" new_name="$2"
if [[ -n "${!old_name:-}" ]]; then
echo "ERROR: deprecated env '${old_name}' detected. Use '${new_name}' instead." >&2
exit 2
fi
}

require_env() {
local name="$1"
if [[ -z "${!name:-}" ]]; then
echo "ERROR: missing required env '${name}'" >&2; exit 2
fi
}

json_escape() {
local s="$1"
s=${s//\\/\\\\}; s=${s//\"/\\\"}; s=${s//$'\n'/}
printf "%s" "$s"
}

# ── Guard deprecated vars ─────────────────────────────────────────────
fail_on_deprecated "PD_ADDRESS" "HG_STORE_PD_ADDRESS"
fail_on_deprecated "GRPC_HOST" "HG_STORE_GRPC_HOST"
fail_on_deprecated "RAFT_ADDRESS" "HG_STORE_RAFT_ADDRESS"
fail_on_deprecated "RAFT_PEERS" "HG_PD_RAFT_PEERS_LIST"
Comment thread
bitflicker64 marked this conversation as resolved.
Outdated

# ── Required vars ─────────────────────────────────────────────────────
require_env "HG_STORE_PD_ADDRESS"
require_env "HG_STORE_GRPC_HOST"
require_env "HG_STORE_RAFT_ADDRESS"
Comment on lines +48 to +51
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

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

This entrypoint now hard-requires HG_STORE_GRPC_HOST and HG_STORE_RAFT_ADDRESS (in addition to PD address). The documented docker run example in hugegraph-store/README.md only sets PD_ADDRESS + mounts conf/, so it will now fail immediately. Consider defaulting these values to what’s in conf/application.yml and only requiring/overriding them when env vars are provided.

Copilot uses AI. Check for mistakes.

# ── Defaults ──────────────────────────────────────────────────────────
: "${HG_STORE_GRPC_PORT:=8500}"
: "${HG_STORE_REST_PORT:=8520}"
: "${HG_STORE_DATA_PATH:=/hugegraph-store/storage}"

# ── Build SPRING_APPLICATION_JSON ─────────────────────────────────────
SPRING_APPLICATION_JSON="$(cat <<JSON
{
"pdserver": { "address": "$(json_escape "${HG_STORE_PD_ADDRESS}")" },
"grpc": { "host": "$(json_escape "${HG_STORE_GRPC_HOST}")",
"port": "$(json_escape "${HG_STORE_GRPC_PORT}")" },
"raft": { "address": "$(json_escape "${HG_STORE_RAFT_ADDRESS}")" },
"server": { "port": "$(json_escape "${HG_STORE_REST_PORT}")" },
"app": { "data-path": "$(json_escape "${HG_STORE_DATA_PATH}")" }
}
JSON
)"
export SPRING_APPLICATION_JSON

log "effective config:"
log " pdserver.address=${HG_STORE_PD_ADDRESS}"
log " grpc.host=${HG_STORE_GRPC_HOST}"
log " grpc.port=${HG_STORE_GRPC_PORT}"
log " raft.address=${HG_STORE_RAFT_ADDRESS}"
log " server.port=${HG_STORE_REST_PORT}"
log " app.data-path=${HG_STORE_DATA_PATH}"

./bin/start-hugegraph-store.sh -j "${JAVA_OPTS:-}"
tail -f /dev/null
Comment thread
bitflicker64 marked this conversation as resolved.
Loading