This is an automated email from the ASF dual-hosted git repository.
jin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git
The following commit(s) were added to refs/heads/master by this push:
new d4b95ca32 feat: support Cassandra with docker-compose in server (#2307)
d4b95ca32 is described below
commit d4b95ca32371dfdee60d448fa3e5ab38fc4e288e
Author: Dandelion <[email protected]>
AuthorDate: Mon Oct 23 16:29:42 2023 +0800
feat: support Cassandra with docker-compose in server (#2307)
## Main Changes
1. change the dockerfile, adding the shell to wait for storage backend and
use a docker-entrypoint.sh to manage the starting process.
2. delete a deprecated class in gremlin-console.sh (reference: [doc of
ScriptExecutor](https://tinkerpop.apache.org/javadocs/3.2.3/full/org/apache/tinkerpop/gremlin/groovy/jsr223/ScriptExecutor.html))
3. add a healthy check in docker-compose
4. add an example folder where we can put all the template
docker-compose.yml here
5. add `*swagger-ui*` in gitignore, which appears after you compile the
source code locally.
---------
Co-authored-by: imbajin <[email protected]>
---
.licenserc.yaml | 1 +
Dockerfile | 14 +++--
LICENSE | 1 +
hugegraph-dist/docker/docker-entrypoint.sh | 24 +++++++++
.../docker/example/docker-compose-cassandra.yml | 61 ++++++++++++++++++++++
.../docker/scripts/detect-storage.groovy | 31 +++++++++++
.../docker/scripts/remote-connect.groovy | 19 +++++++
hugegraph-dist/release-docs/LICENSE | 1 +
.../src/assembly/static/bin/docker-entrypoint.sh | 24 +++++++++
.../src/assembly/static/bin/gremlin-console.sh | 10 ++--
.../src/assembly/static/bin/wait-storage.sh | 54 +++++++++++++++++++
11 files changed, 229 insertions(+), 11 deletions(-)
diff --git a/.licenserc.yaml b/.licenserc.yaml
index 334d89b51..db7af8d8d 100644
--- a/.licenserc.yaml
+++ b/.licenserc.yaml
@@ -96,6 +96,7 @@ header: # `header` section is configurations for source codes
license header.
- '**/util/StringEncoding.java'
-
'hugegraph-api/src/main/java/org/apache/hugegraph/opencypher/CypherOpProcessor.java'
-
'hugegraph-api/src/main/java/org/apache/hugegraph/opencypher/CypherPlugin.java'
+ - 'hugegraph-dist/src/assembly/static/bin/wait-storage.sh'
comment: on-failure # on what condition license-eye will comment on the pull
request, `on-failure`, `always`, `never`.
# license-location-threshold specifies the index threshold where the license
header can be located,
diff --git a/Dockerfile b/Dockerfile
index e096f3430..7dcbf2131 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -31,7 +31,8 @@ COPY --from=build /pkg/apache-hugegraph-incubating-$version/
/hugegraph
LABEL maintainer="HugeGraph Docker Maintainers <[email protected]>"
# TODO: use g1gc or zgc as default
-ENV JAVA_OPTS="-XX:+UnlockExperimentalVMOptions -XX:+UseContainerSupport
-XX:MaxRAMPercentage=50 -XshowSettings:vm"
+ENV JAVA_OPTS="-XX:+UnlockExperimentalVMOptions -XX:+UseContainerSupport
-XX:MaxRAMPercentage=50 -XshowSettings:vm" \
+ HUGEGRAPH_HOME="hugegraph"
#COPY . /hugegraph/hugegraph-server
WORKDIR /hugegraph/
@@ -50,11 +51,16 @@ RUN set -x \
# 2. Init HugeGraph Sever
RUN set -e \
&& pwd && cd /hugegraph/ \
- && sed -i "s/^restserver.url.*$/restserver.url=http:\/\/0.0.0.0:8080/g"
./conf/rest-server.properties \
- && ./bin/init-store.sh
+ && sed -i "s/^restserver.url.*$/restserver.url=http:\/\/0.0.0.0:8080/g"
./conf/rest-server.properties
+
+# 3. Init docker script
+COPY hugegraph-dist/docker/scripts/remote-connect.groovy ./scripts
+COPY hugegraph-dist/docker/scripts/detect-storage.groovy ./scripts
+COPY hugegraph-dist/docker/docker-entrypoint.sh .
+RUN chmod 755 ./docker-entrypoint.sh
EXPOSE 8080
VOLUME /hugegraph
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
-CMD ["./bin/start-hugegraph.sh", "-d false -j $JAVA_OPTS -g zgc"]
+CMD ["./docker-entrypoint.sh"]
diff --git a/LICENSE b/LICENSE
index ad08080e3..cea0b74f4 100644
--- a/LICENSE
+++ b/LICENSE
@@ -214,5 +214,6 @@
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeScriptT
hugegraph-core/src/main/java/org/apache/hugegraph/type/Nameable.java from
https://github.com/JanusGraph/janusgraph
hugegraph-core/src/main/java/org/apache/hugegraph/type/define/Cardinality.java
from https://github.com/JanusGraph/janusgraph
hugegraph-core/src/main/java/org/apache/hugegraph/util/StringEncoding.java
from https://github.com/JanusGraph/janusgraph
+hugegraph-dist/src/assembly/static/bin/wait-storage.sh from
https://github.com/JanusGraph/janusgraph
hugegraph-api/src/main/java/org/apache/hugegraph/opencypher/CypherOpProcessor.java
from https://github.com/opencypher/cypher-for-gremlin
hugegraph-api/src/main/java/org/apache/hugegraph/opencypher/CypherPlugin.java
from https://github.com/opencypher/cypher-for-gremlin
diff --git a/hugegraph-dist/docker/docker-entrypoint.sh
b/hugegraph-dist/docker/docker-entrypoint.sh
new file mode 100644
index 000000000..e1fad4a9f
--- /dev/null
+++ b/hugegraph-dist/docker/docker-entrypoint.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+#
+# 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.
+#
+
+
+./bin/wait-storage.sh
+
+./bin/init-store.sh
+
+./bin/start-hugegraph.sh -d false -j "$JAVA_OPTS" -g zgc
diff --git a/hugegraph-dist/docker/example/docker-compose-cassandra.yml
b/hugegraph-dist/docker/example/docker-compose-cassandra.yml
new file mode 100644
index 000000000..3682b02f9
--- /dev/null
+++ b/hugegraph-dist/docker/example/docker-compose-cassandra.yml
@@ -0,0 +1,61 @@
+#
+# 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.
+#
+
+version: "3"
+
+services:
+ graph:
+ image: hugegraph/hugegraph
+ container_name: cas-graph
+ ports:
+ - 18080:8080
+ environment:
+ hugegraph.backend: cassandra
+ hugegraph.serializer: cassandra
+ hugegraph.cassandra.host: cas-cassandra
+ hugegraph.cassandra.port: 9042
+ networks:
+ - ca-network
+ depends_on:
+ - cassandra
+ healthcheck:
+ test: ["CMD", "bin/gremlin-console.sh", "--" ,"-e",
"scripts/remote-connect.groovy"]
+ interval: 10s
+ timeout: 30s
+ retries: 3
+
+ cassandra:
+ image: cassandra:4
+ container_name: cas-cassandra
+ ports:
+ - 7000:7000
+ - 9042:9042
+ security_opt:
+ - seccomp:unconfined
+ networks:
+ - ca-network
+ healthcheck:
+ test: ["CMD", "cqlsh", "--execute", "describe keyspaces;"]
+ interval: 10s
+ timeout: 30s
+ retries: 5
+
+networks:
+ ca-network:
+
+volumes:
+ hugegraph-data:
diff --git a/hugegraph-dist/docker/scripts/detect-storage.groovy
b/hugegraph-dist/docker/scripts/detect-storage.groovy
new file mode 100644
index 000000000..df57ade98
--- /dev/null
+++ b/hugegraph-dist/docker/scripts/detect-storage.groovy
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+import org.apache.hugegraph.HugeFactory
+import org.apache.hugegraph.dist.RegisterUtil
+
+// register all the backend to avoid changes if docker needs to support othre
backend
+RegisterUtil.registerPlugins()
+RegisterUtil.registerRocksDB()
+RegisterUtil.registerCassandra()
+RegisterUtil.registerScyllaDB()
+RegisterUtil.registerHBase()
+RegisterUtil.registerMysql()
+RegisterUtil.registerPalo()
+RegisterUtil.registerPostgresql()
+
+graph = HugeFactory.open('./conf/graphs/hugegraph.properties')
diff --git a/hugegraph-dist/docker/scripts/remote-connect.groovy
b/hugegraph-dist/docker/scripts/remote-connect.groovy
new file mode 100644
index 000000000..e352cdc7e
--- /dev/null
+++ b/hugegraph-dist/docker/scripts/remote-connect.groovy
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+
+:remote connect tinkerpop.server conf/remote.yaml
+:> hugegraph
diff --git a/hugegraph-dist/release-docs/LICENSE
b/hugegraph-dist/release-docs/LICENSE
index f1cc9686c..25c50c2fb 100644
--- a/hugegraph-dist/release-docs/LICENSE
+++ b/hugegraph-dist/release-docs/LICENSE
@@ -220,6 +220,7 @@ The text of each license is the standard Apache 2.0 license.
hugegraph-core/src/main/java/org/apache/hugegraph/type/Nameable.java from
https://github.com/JanusGraph/janusgraph
hugegraph-core/src/main/java/org/apache/hugegraph/type/define/Cardinality.java
from https://github.com/JanusGraph/janusgraph
hugegraph-core/src/main/java/org/apache/hugegraph/util/StringEncoding.java
from https://github.com/JanusGraph/janusgraph
+hugegraph-dist/src/assembly/static/bin/wait-storage.sh from
https://github.com/JanusGraph/janusgraph
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeScriptTraversal.java
from https://github.com/apache/tinkerpop
hugegraph-test/src/main/java/org/apache/hugegraph/tinkerpop/ProcessBasicSuite.java
from https://github.com/apache/tinkerpop
hugegraph-test/src/main/java/org/apache/hugegraph/tinkerpop/StructureBasicSuite.java
from https://github.com/apache/tinkerpop
diff --git a/hugegraph-dist/src/assembly/static/bin/docker-entrypoint.sh
b/hugegraph-dist/src/assembly/static/bin/docker-entrypoint.sh
new file mode 100644
index 000000000..e1fad4a9f
--- /dev/null
+++ b/hugegraph-dist/src/assembly/static/bin/docker-entrypoint.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+#
+# 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.
+#
+
+
+./bin/wait-storage.sh
+
+./bin/init-store.sh
+
+./bin/start-hugegraph.sh -d false -j "$JAVA_OPTS" -g zgc
diff --git a/hugegraph-dist/src/assembly/static/bin/gremlin-console.sh
b/hugegraph-dist/src/assembly/static/bin/gremlin-console.sh
index b8a0fadbd..edcdc0c40 100755
--- a/hugegraph-dist/src/assembly/static/bin/gremlin-console.sh
+++ b/hugegraph-dist/src/assembly/static/bin/gremlin-console.sh
@@ -84,14 +84,10 @@ PROFILING_ENABLED=false
# Process options
MAIN_CLASS=org.apache.tinkerpop.gremlin.console.Console
-while getopts "elpv" opt; do
+while getopts "lpv" opt; do
case "$opt" in
- e) MAIN_CLASS=org.apache.tinkerpop.gremlin.groovy.jsr223.ScriptExecutor
- # Stop processing gremlin-console.sh arguments as soon as the -e switch
- # is seen; everything following -e becomes arguments to the
- # ScriptExecutor main class. This maintains compatibility with
- # older deployments.
- break;;
+ # class ScriptExecutor has been Deprecated.
+ # reference
https://tinkerpop.apache.org/javadocs/3.2.3/full/org/apache/tinkerpop/gremlin/groovy/jsr223/ScriptExecutor.html
l) eval GREMLIN_LOG_LEVEL=\$$OPTIND
OPTIND="$(( $OPTIND + 1 ))"
if [ "$GREMLIN_LOG_LEVEL" = "TRACE" -o \
diff --git a/hugegraph-dist/src/assembly/static/bin/wait-storage.sh
b/hugegraph-dist/src/assembly/static/bin/wait-storage.sh
new file mode 100644
index 000000000..3a98e8c56
--- /dev/null
+++ b/hugegraph-dist/src/assembly/static/bin/wait-storage.sh
@@ -0,0 +1,54 @@
+#!/bin/bash
+#
+# Copyright 2023 JanusGraph Authors
+#
+# Licensed 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.
+#
+
+function abs_path() {
+ SOURCE="${BASH_SOURCE[0]}"
+ while [[ -h "$SOURCE" ]]; do
+ DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
+ SOURCE="$(readlink "$SOURCE")"
+ [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
+ done
+ cd -P "$(dirname "$SOURCE")" && pwd
+}
+
+BIN=$(abs_path)
+TOP="$(cd "$BIN"/../ && pwd)"
+GRAPH_CONF="$TOP/conf/graphs/hugegraph.properties"
+WAIT_STORAGE_TIMEOUT_S=120
+DETECT_STORAGE="$TOP/scripts/detect-storage.groovy"
+
+. "$BIN"/util.sh
+
+# apply config from env
+while IFS=' ' read -r envvar_key envvar_val; do
+ if [[ "${envvar_key}" =~ hugegraph\. ]] && [[ ! -z ${envvar_val} ]]; then
+ envvar_key=${envvar_key#"hugegraph."}
+ if grep -q -E "^\s*${envvar_key}\s*=\.*" ${GRAPH_CONF}; then
+ sed -ri "s#^(\s*${envvar_key}\s*=).*#\\1${envvar_val}#"
${GRAPH_CONF}
+ else
+ echo "${envvar_key}=${envvar_val}" >> ${GRAPH_CONF}
+ fi
+ else
+ continue
+ fi
+done < <(env | sort -r | awk -F= '{ st = index($0, "="); print $1 " "
substr($0, st+1) }')
+
+# wait for storage
+if ! [ -z "${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 \"waiting for storage...\"; sleep 5; done"
+fi