From 423725188a5c97391c3d56c17157b41ec0a5df56 Mon Sep 17 00:00:00 2001 From: Dandelion <49650772+aroundabout@users.noreply.github.com> Date: Fri, 26 Jan 2024 16:48:41 +0800 Subject: [PATCH] fix(chore): remove zgc in dockerfile for ARM env (#2421) * remove zgc * Apply suggestions from code review Co-authored-by: imbajin * add comment for hugegraph-server.sh * fix enable-auth.sh * init store in entrypoint * use flag file to skip re-init * delete tar.gz * simply dockerfile * mvn optimize * simply dockerfile * add init log in docker --------- Co-authored-by: imbajin --- hugegraph-server/Dockerfile | 19 ++++++------ .../docker/docker-entrypoint.sh | 31 ++++++++++++------- .../src/assembly/static/bin/enable-auth.sh | 26 +++++++++------- .../assembly/static/bin/hugegraph-server.sh | 1 + .../src/assembly/static/bin/util.sh | 3 ++ 5 files changed, 46 insertions(+), 34 deletions(-) diff --git a/hugegraph-server/Dockerfile b/hugegraph-server/Dockerfile index 45a725786d..8eef58c5f7 100644 --- a/hugegraph-server/Dockerfile +++ b/hugegraph-server/Dockerfile @@ -23,13 +23,13 @@ COPY . /pkg WORKDIR /pkg ARG MAVEN_ARGS -RUN mvn package $MAVEN_ARGS -e -B -ntp -DskipTests -Dmaven.javadoc.skip=true && pwd && ls -l +RUN mvn package $MAVEN_ARGS -e -B -ntp -DskipTests -Dmaven.javadoc.skip=true && pwd && ls -l && rm ./hugegraph-server/*.tar.gz # 2nd stage: runtime env +# Note: ZGC (The Z Garbage Collector) is only supported on ARM-Mac with java > 13 FROM openjdk:11-slim -# TODO: get the version from the pom.xml -ENV version=1.2.0 -COPY --from=build /pkg/hugegraph-server/apache-hugegraph-incubating-$version/ /hugegraph-server + +COPY --from=build /pkg/hugegraph-server/apache-hugegraph-incubating-*/ /hugegraph-server/ LABEL maintainer="HugeGraph Docker Maintainers " # TODO: use g1gc or zgc as default @@ -39,7 +39,7 @@ ENV JAVA_OPTS="-XX:+UnlockExperimentalVMOptions -XX:+UseContainerSupport -XX:Max #COPY . /hugegraph/hugegraph-server WORKDIR /hugegraph-server/ -# 1. Install environment +# 1. Install environment and init HugeGraph Sever RUN set -x \ && apt-get -q update \ && apt-get -q install -y --no-install-recommends --no-install-suggests \ @@ -48,15 +48,14 @@ RUN set -x \ curl \ lsof \ vim \ + cron \ && apt-get clean \ - && rm -rf /var/lib/apt/lists/* - -# 2. Init HugeGraph Sever -RUN set -e \ + && rm -rf /var/lib/apt/lists/* \ + && service cron start \ && pwd && cd /hugegraph-server/ \ && sed -i "s/^restserver.url.*$/restserver.url=http:\/\/0.0.0.0:8080/g" ./conf/rest-server.properties -# 3. Init docker script +# 2. Init docker script COPY hugegraph-server/hugegraph-dist/docker/scripts/remote-connect.groovy ./scripts COPY hugegraph-server/hugegraph-dist/docker/scripts/detect-storage.groovy ./scripts COPY hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh . diff --git a/hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh b/hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh index 716dbf8c93..aa503f3566 100644 --- a/hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh +++ b/hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh @@ -16,24 +16,31 @@ # under the License. # -# wait for storage like cassandra -./bin/wait-storage.sh +# create a folder to save the docker-related file +DOCKER_FOLDER='./docker' +mkdir -p $DOCKER_FOLDER -# set auth if needed -if [[ $AUTH == "true" ]]; then - # set password if use do not provide +INIT_FLAG_FILE="init_complete" + +if [ ! -f "${DOCKER_FOLDER}/${INIT_FLAG_FILE}" ]; then + # wait for storage backend + ./bin/wait-storage.sh if [ -z "$PASSWORD" ]; then - echo "you have not set the password, we will use the default password" - PASSWORD="hugegraph" + echo "init hugegraph with non-auth mode" + ./bin/init-store.sh + else + echo "init hugegraph with auth mode" + ./bin/enable-auth.sh + echo "$PASSWORD" | ./bin/init-store.sh fi - echo "init hugegraph with auth" - ./bin/enable-auth.sh - echo "$PASSWORD" | ./bin/init-store.sh + # create a flag file to avoid re-init when restarting + touch ${DOCKER_FOLDER}/${INIT_FLAG_FILE} else - ./bin/init-store.sh + echo "Hugegraph Initialization already done. Skipping re-init..." fi # start hugegraph -./bin/start-hugegraph.sh -j "$JAVA_OPTS" -g zgc +# remove "-g zgc" now, which is only available on ARM-Mac with java > 13 +./bin/start-hugegraph.sh -j "$JAVA_OPTS" tail -f /dev/null diff --git a/hugegraph-server/hugegraph-dist/src/assembly/static/bin/enable-auth.sh b/hugegraph-server/hugegraph-dist/src/assembly/static/bin/enable-auth.sh index 924bf58f78..2f975872ca 100644 --- a/hugegraph-server/hugegraph-dist/src/assembly/static/bin/enable-auth.sh +++ b/hugegraph-server/hugegraph-dist/src/assembly/static/bin/enable-auth.sh @@ -36,19 +36,21 @@ GRAPH_CONF="hugegraph.properties" # make a backup BAK_CONF="$TOP/conf-bak" -mkdir -p "$BAK_CONF" -cp "${CONF}/${GREMLIN_SERVER_CONF}" "${BAK_CONF}/${GREMLIN_SERVER_CONF}.bak" -cp "${CONF}/${REST_SERVER_CONF}" "${BAK_CONF}/${REST_SERVER_CONF}.bak" -cp "${CONF}/graphs/${GRAPH_CONF}" "${BAK_CONF}/${GRAPH_CONF}.bak" +if [ ! -d "$BAK_CONF" ]; then + mkdir -p "$BAK_CONF" + cp "${CONF}/${GREMLIN_SERVER_CONF}" "${BAK_CONF}/${GREMLIN_SERVER_CONF}.bak" + cp "${CONF}/${REST_SERVER_CONF}" "${BAK_CONF}/${REST_SERVER_CONF}.bak" + cp "${CONF}/graphs/${GRAPH_CONF}" "${BAK_CONF}/${GRAPH_CONF}.bak" -sed -i -e '$a\authentication: {' \ - -e '$a\ authenticator: org.apache.hugegraph.auth.StandardAuthenticator,' \ - -e '$a\ authenticationHandler: org.apache.hugegraph.auth.WsAndHttpBasicAuthHandler,' \ - -e '$a\ config: {tokens: conf/rest-server.properties}' \ - -e '$a\}' ${CONF}/${GREMLIN_SERVER_CONF} + sed -i -e '$a\authentication: {' \ + -e '$a\ authenticator: org.apache.hugegraph.auth.StandardAuthenticator,' \ + -e '$a\ authenticationHandler: org.apache.hugegraph.auth.WsAndHttpBasicAuthHandler,' \ + -e '$a\ config: {tokens: conf/rest-server.properties}' \ + -e '$a\}' ${CONF}/${GREMLIN_SERVER_CONF} -sed -i -e '$a\auth.authenticator=org.apache.hugegraph.auth.StandardAuthenticator' \ - -e '$a\auth.graph_store=hugegraph' ${CONF}/${REST_SERVER_CONF} + sed -i -e '$a\auth.authenticator=org.apache.hugegraph.auth.StandardAuthenticator' \ + -e '$a\auth.graph_store=hugegraph' ${CONF}/${REST_SERVER_CONF} -sed -i 's/gremlin.graph=org.apache.hugegraph.HugeFactory/gremlin.graph=org.apache.hugegraph.auth.HugeFactoryAuthProxy/g' ${CONF}/graphs/${GRAPH_CONF} + sed -i 's/gremlin.graph=org.apache.hugegraph.HugeFactory/gremlin.graph=org.apache.hugegraph.auth.HugeFactoryAuthProxy/g' ${CONF}/graphs/${GRAPH_CONF} +fi diff --git a/hugegraph-server/hugegraph-dist/src/assembly/static/bin/hugegraph-server.sh b/hugegraph-server/hugegraph-dist/src/assembly/static/bin/hugegraph-server.sh index a643986833..24b10a8e9d 100644 --- a/hugegraph-server/hugegraph-dist/src/assembly/static/bin/hugegraph-server.sh +++ b/hugegraph-server/hugegraph-dist/src/assembly/static/bin/hugegraph-server.sh @@ -127,6 +127,7 @@ if [[ $JAVA_VERSION -gt 9 ]]; then fi # Using G1GC as the default garbage collector (Recommended for large memory machines) +# mention: zgc is only available on ARM-Mac with java > 13 case "$GC_OPTION" in g1|G1|g1gc) echo "Using G1GC as the default garbage collector" diff --git a/hugegraph-server/hugegraph-dist/src/assembly/static/bin/util.sh b/hugegraph-server/hugegraph-dist/src/assembly/static/bin/util.sh index 47d18e9954..5f7489e60f 100755 --- a/hugegraph-server/hugegraph-dist/src/assembly/static/bin/util.sh +++ b/hugegraph-server/hugegraph-dist/src/assembly/static/bin/util.sh @@ -139,6 +139,9 @@ function wait_for_startup() { process_status "$server_name" "$pid" >/dev/null if [ $? -eq 1 ]; then echo "Starting $server_name failed" + if [ -e "$error_file_name" ]; then + rm "$error_file_name" + fi return 1 fi