diff --git a/.gitignore b/.gitignore index 47bbf40170..9dfe436992 100644 --- a/.gitignore +++ b/.gitignore @@ -83,3 +83,5 @@ hs_err_pid* .mtj.tmp/ # blueJ files *.ctxt + +*swagger-ui* diff --git a/Dockerfile b/Dockerfile index e096f3430a..4e11b36e13 100644 --- a/Dockerfile +++ b/Dockerfile @@ -50,11 +50,10 @@ 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 EXPOSE 8080 VOLUME /hugegraph ENTRYPOINT ["/usr/bin/dumb-init", "--"] -CMD ["./bin/start-hugegraph.sh", "-d false -j $JAVA_OPTS -g zgc"] +CMD ["./bin/docker-entrypoint.sh"] 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 0000000000..0dfe7b3305 --- /dev/null +++ b/hugegraph-dist/docker/example/docker-compose-cassandra.yml @@ -0,0 +1,44 @@ +version: "3" + +services: + graph: + image: hugegraph/hugegraph + container_name: ca-graph + ports: + - 18080:8080 + environment: + hugegraph.backend: cassandra + hugegraph.serializer: cassandra + hugegraph.cassandra.host: ca-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:3.11 + container_name: ca-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/src/assembly/static/bin/docker-entrypoint.sh b/hugegraph-dist/src/assembly/static/bin/docker-entrypoint.sh new file mode 100644 index 0000000000..e1fad4a9ff --- /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 b8a0fadbd2..edcdc0c403 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 0000000000..552e2b427e --- /dev/null +++ b/hugegraph-dist/src/assembly/static/bin/wait-storage.sh @@ -0,0 +1,55 @@ +#!/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. +# + +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_PROP="$TOP/conf/graphs/hugegraph.properties" +HUGE_STORAGE_TIMEOUT_S=60 +TRY_STORAGE="$TOP/scripts/try-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_PROP}; then + sed -ri "s#^(\s*${envvar_key}\s*=).*#\\1${envvar_val}#" ${GRAPH_PROP} + else + echo "${envvar_key}=${envvar_val}" >> ${GRAPH_PROP} + fi + else + continue + fi +done < <(env | sort -r | awk -F= '{ st = index($0, "="); print $1 " " substr($0, st+1) }') + +# wait for storage +if ! [ -z "${HUGE_STORAGE_TIMEOUT_S:-}" ]; then + timeout "${HUGE_STORAGE_TIMEOUT_S}s" bash -c \ + "until bin/gremlin-console.sh -- -e $TRY_STORAGE > /dev/null 2>&1; do echo \"waiting for storage...\"; sleep 5; done" +fi diff --git a/hugegraph-dist/src/assembly/static/scripts/remote-connect.groovy b/hugegraph-dist/src/assembly/static/scripts/remote-connect.groovy new file mode 100644 index 0000000000..e352cdc7e9 --- /dev/null +++ b/hugegraph-dist/src/assembly/static/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/src/assembly/static/scripts/try-storage.groovy b/hugegraph-dist/src/assembly/static/scripts/try-storage.groovy new file mode 100644 index 0000000000..9b344131f2 --- /dev/null +++ b/hugegraph-dist/src/assembly/static/scripts/try-storage.groovy @@ -0,0 +1,14 @@ +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')