This is an automated email from the ASF dual-hosted git repository.

jin pushed a commit to branch pd-store
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git

commit 1bac4807103f7ad1c86652bb5d3eac9175770672
Author: Dandelion <[email protected]>
AuthorDate: Mon Aug 28 15:36:21 2023 +0800

    feat(dist): support pre-load test graph data in docker container (#2241)
    
    - Provide the related conf and groovy for user to pre load some data.
    - Change the start-hugegraph.sh to get the environment variables to decide 
to pre-load or not.
    
    ---------
    
    Co-authored-by: imbajin <[email protected]>
---
 hugegraph-server/hugegraph-dist/README.md          | 56 ++++++++++++++++++++++
 .../src/assembly/static/bin/start-hugegraph.sh     | 30 +++++++++---
 2 files changed, 80 insertions(+), 6 deletions(-)

diff --git a/hugegraph-server/hugegraph-dist/README.md 
b/hugegraph-server/hugegraph-dist/README.md
new file mode 100644
index 000000000..b8e649928
--- /dev/null
+++ b/hugegraph-server/hugegraph-dist/README.md
@@ -0,0 +1,56 @@
+# Deploy Hugegraph server with docker
+
+## 1. Deploy
+
+We can use docker to quickly start an inner HugeGraph server with RocksDB in 
background.
+
+1. Using docker run
+
+    Use `docker run -itd --name=graph -p 18080:8080 hugegraph/hugegraph` to 
start hugegraph server.
+
+2. Using docker compose
+
+    We can also use `docker-compose up -d`.  The `docker-compose.yaml` is 
below:
+
+    ```yaml
+    version: '3'
+    services:
+      graph:
+        image: hugegraph/hugegraph
+        ports:
+          - 18080:8080
+    ```
+
+## 2. Create Sample Graph on Server Startup
+
+If you want to **pre-load** some (test) data or graphs in container(by 
default), you can set the env `PRELOAD=ture`
+
+If you want to customize the pre-loaded data, please mount the the groovy 
scripts (not necessary).
+
+
+
+1. Using docker run
+
+    Use `docker run -itd --name=graph -p 18080:8080 -e PRELOAD=true -v 
/path/to/yourScript:/hugegraph/scripts/example.groovy hugegraph/hugegraph`
+    to start hugegraph server.
+
+2. Using docker compose 
+    
+    We can also use `docker-compose up -d` to quickly start. The 
`docker-compose.yaml` is below:
+
+    ```yaml
+    version: '3'
+    services:
+      graph:
+        image: hugegraph/hugegraph
+        environment:
+          - PRELOAD=true
+        volumes:
+          - /path/to/yourscript:/hugegraph/scripts/example.groovy
+        ports:
+          - 18080:8080
+    ```
+
+3. Using start-hugegraph.sh
+
+    If you deploy HugeGraph server without docker, you can also pass arguments 
using `-p`, like this: `bin/start-hugegraph.sh -p true`.
\ No newline at end of file
diff --git 
a/hugegraph-server/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh 
b/hugegraph-server/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh
index 85d259d3c..c53df91b9 100644
--- a/hugegraph-server/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh
+++ b/hugegraph-server/hugegraph-dist/src/assembly/static/bin/start-hugegraph.sh
@@ -18,33 +18,40 @@
 OPEN_MONITOR="false"
 OPEN_SECURITY_CHECK="true"
 DAEMON="true"
+PRELOAD="false"
 #VERBOSE=""
 GC_OPTION=""
 USER_OPTION=""
 SERVER_STARTUP_TIMEOUT_S=30
 
-while getopts "d:g:m:s:j:t:v" arg; do
+while getopts "d:g:m:p:s:j:t:v" arg; do
     case ${arg} in
         d) DAEMON="$OPTARG" ;;
         g) GC_OPTION="$OPTARG" ;;
         m) OPEN_MONITOR="$OPTARG" ;;
+        p) PRELOAD="$OPTARG" ;;
         s) OPEN_SECURITY_CHECK="$OPTARG" ;;
         j) USER_OPTION="$OPTARG" ;;
         t) SERVER_STARTUP_TIMEOUT_S="$OPTARG" ;;
         # TODO: should remove it in future (check the usage carefully)
         v) VERBOSE="verbose" ;;
-        ?) echo "USAGE: $0 [-d true|false] [-g g1] [-m true|false] [-s 
true|false] [-j java_options]
+        ?) echo "USAGE: $0 [-d true|false] [-g g1] [-m true|false] [-p 
true|false] [-s true|false] [-j java_options]
                 [-t timeout]" && exit 1 ;;
     esac
 done
 
 if [[ "$OPEN_MONITOR" != "true" && "$OPEN_MONITOR" != "false" ]]; then
-    echo "USAGE: $0 [-d true|false] [-g g1] [-m true|false] [-s true|false] 
[-j java_options]"
+    echo "USAGE: $0 [-d true|false] [-g g1] [-m true|false] [-p true|false] 
[-s true|false] [-j java_options]"
     exit 1
 fi
 
 if [[ "$OPEN_SECURITY_CHECK" != "true" && "$OPEN_SECURITY_CHECK" != "false" 
]]; then
-    echo "USAGE: $0 [-d true|false] [-g g1] [-m true|false] [-s true|false] 
[-j java_options]"
+    echo "USAGE: $0 [-d true|false] [-g g1] [-m true|false] [-p true|false] 
[-s true|false] [-j java_options]"
+    exit 1
+fi
+
+if [[ "$PRELOAD" != "true" && "$PRELOAD" != "false" ]]; then
+    echo "USAGE: $0 [-d true|false] [-g g1] [-m true|false] [-p true|false] 
[-s true|false] [-j java_options]"
     exit 1
 fi
 
@@ -62,6 +69,7 @@ BIN=$(abs_path)
 TOP="$(cd "$BIN"/../ && pwd)"
 CONF="$TOP/conf"
 LOGS="$TOP/logs"
+SCRIPTS="$TOP/scripts"
 PID_FILE="$BIN/pid"
 
 . "$BIN"/util.sh
@@ -79,13 +87,23 @@ if [ ! -d "$LOGS" ]; then
     mkdir -p "$LOGS"
 fi
 
+GREMLIN_SERVER_CONF="gremlin-server.yaml"
+if [[ $PRELOAD == "true" ]]; then
+    GREMLIN_SERVER_CONF="gremlin-server-preload.yaml"
+    EXAMPLE_SCRPIT="example-preload.groovy"
+    cp "${CONF}"/gremlin-server.yaml "${CONF}/${GREMLIN_SERVER_CONF}"
+    cp "${SCRIPTS}"/example.groovy "${SCRIPTS}/${EXAMPLE_SCRPIT}"
+    sed -i -e "s/empty-sample.groovy/$EXAMPLE_SCRPIT/g" 
"${CONF}/${GREMLIN_SERVER_CONF}"
+    sed -i -e '/registerRocksDB/d; /serverStarted/d' 
"${SCRIPTS}/${EXAMPLE_SCRPIT}"
+fi
+
 if [[ $DAEMON == "true" ]]; then
     echo "Starting HugeGraphServer in daemon mode..."
-    "${BIN}"/hugegraph-server.sh "${CONF}"/gremlin-server.yaml 
"${CONF}"/rest-server.properties \
+    "${BIN}"/hugegraph-server.sh "${CONF}/${GREMLIN_SERVER_CONF}" 
"${CONF}"/rest-server.properties \
     "${OPEN_SECURITY_CHECK}" "${USER_OPTION}" "${GC_OPTION}" 
>>"${LOGS}"/hugegraph-server.log 2>&1 &
 else
     echo "Starting HugeGraphServer in foreground mode..."
-    "${BIN}"/hugegraph-server.sh "${CONF}"/gremlin-server.yaml 
"${CONF}"/rest-server.properties \
+    "${BIN}"/hugegraph-server.sh "${CONF}/${GREMLIN_SERVER_CONF}" 
"${CONF}"/rest-server.properties \
     "${OPEN_SECURITY_CHECK}" "${USER_OPTION}" "${GC_OPTION}" 
>>"${LOGS}"/hugegraph-server.log 2>&1
 fi
 

Reply via email to