Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support docker use the auth when starting #2403

Merged
merged 15 commits into from
Jan 15, 2024
17 changes: 15 additions & 2 deletions hugegraph-server/hugegraph-dist/docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,24 @@
# under the License.
#


# wait for storage like cassandra
./bin/wait-storage.sh

./bin/init-store.sh
# set auth if needed
if [[ $AUTH == "true" ]]; then
# set password if use do not provide
if [ -z "$PASSWORD" ]; then
echo "you have not set the password, we will use the default password"
PASSWORD="hugegraph"
fi
echo "init hugegraph with auth"
./bin/set-auth.sh
echo "$PASSWORD" | ./bin/init-store.sh
else
./bin/init-store.sh
fi

# start hugegraph
./bin/start-hugegraph.sh -j "$JAVA_OPTS" -g zgc

tail -f /dev/null
35 changes: 35 additions & 0 deletions hugegraph-server/hugegraph-dist/download_keystore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/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.
#

curl --version >/dev/null 2>&1 ||
Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove a redundant docker-entrypoint.sh, not move the file to download_keystore.sh

{
echo 'ERROR: Please install `curl` first if you need `hugegraph-server.keystore`'
exit
}

# TODO: perhaps it's necessary verify the checksum before reusing the existing tar
imbajin marked this conversation as resolved.
Show resolved Hide resolved
if [[ ! -f hugegraph-server.keystore ]]; then
curl -s -S -L -o hugegraph-server.keystore \
https://github.com/apache/hugegraph-doc/raw/binary-1.0/dist/server/hugegraph-server.keystore ||
{
echo 'ERROR: Download `hugegraph-server.keystore` failed, please check your network connection'
aroundabout marked this conversation as resolved.
Show resolved Hide resolved
exit
}
fi

echo 'INFO: Successfully download `hugegraph-server.keystore`'
39 changes: 39 additions & 0 deletions hugegraph-server/hugegraph-dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,45 @@
</target>
</configuration>
</execution>
<execution>
<id>download-keystore</id>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<exec executable="${shell-executable}"
dir="${project.basedir}"
failonerror="false">
<arg line="./download_keystore.sh"/>
VGalaxies marked this conversation as resolved.
Show resolved Hide resolved
</exec>
</target>
</configuration>
</execution>
<execution>
<id>cp-keystore</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<exec executable="cp"
dir="${project.basedir}"
failonerror="false">
<arg value="hugegraph-server.keystore"/>
<arg value="../${final.name}/conf/hugegraph-server.keystore"/>
</exec>
<exec executable="rm"
dir="${project.basedir}"
failonerror="false">
<arg value="-rf"/>
<arg value="hugegraph-server.keystore"/>
</exec>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
aroundabout marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/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)"
CONF="$TOP/conf"

GREMLIN_SERVER_CONF="gremlin-server.yaml"
REST_SERVER_CONF="rest-server.properties"
GRAPH_CONF="hugegraph.properties"

# make a backup
cp "${CONF}/${GREMLIN_SERVER_CONF}" "${CONF}/${GREMLIN_SERVER_CONF}.bak"
cp "${CONF}/${REST_SERVER_CONF}" "${CONF}/${REST_SERVER_CONF}.bak"
cp "${CONF}/graphs/${GRAPH_CONF}" "${CONF}/graphs/${GRAPH_CONF}.bak"
aroundabout marked this conversation as resolved.
Show resolved Hide resolved


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 's/gremlin.graph=org.apache.hugegraph.HugeFactory/gremlin.graph=org.apache.hugegraph.auth.HugeFactoryAuthProxy/g' ${CONF}/graphs/${GRAPH_CONF}
28 changes: 20 additions & 8 deletions hugegraph-server/hugegraph-dist/src/assembly/static/bin/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
#
function command_available() {
local cmd=$1
if [ "$(command -v "$cmd" >/dev/null 2>&1)" ]; then
return 1
else
if [[ -x "$(command -v "$cmd")" ]]; then
return 0
else
return 1
fi
}

Expand Down Expand Up @@ -131,6 +131,7 @@ function wait_for_startup() {
local stop_s=$((now_s + timeout_s))

local status
local error_file_name="wait_for_startup_error.txt"
aroundabout marked this conversation as resolved.
Show resolved Hide resolved

echo -n "Connecting to $server_name ($server_url)"
while [ "$now_s" -le $stop_s ]; do
Expand All @@ -141,16 +142,22 @@ function wait_for_startup() {
return 1
fi

status=$(curl -I -s -k -w "%{http_code}" -o /dev/null "$server_url")
status=$(curl -I -sS -k -w "%{http_code}" -o /dev/null "$server_url" 2> "$error_file_name")
if [[ $status -eq 200 || $status -eq 401 ]]; then
echo "OK"
echo "Started [pid $pid]"
if [ -e "$error_file_name" ]; then
rm "$error_file_name"
fi
return 0
fi
sleep 2
now_s=$(date '+%s')
done

echo ""
cat "$error_file_name"
rm "$error_file_name"
echo "The operation timed out(${timeout_s}s) when attempting to connect to $server_url" >&2
return 1
}
Expand Down Expand Up @@ -268,12 +275,17 @@ function get_ip() {
function download() {
local path=$1
local link_url=$2
aroundabout marked this conversation as resolved.
Show resolved Hide resolved

if command_available "wget"; then
if command_available "curl"; then
if [ ! -d "$path" ]; then
mkdir -p "$path" || {
echo "Failed to create directory: $path"
exit 1
}
fi
curl -L "${link_url}" -o "${path}/$(basename "${link_url}")"
elif command_available "wget"; then
wget --help | grep -q '\--show-progress' && progress_opt="-q --show-progress" || progress_opt=""
wget "${link_url}" -P "${path}" $progress_opt
elif command_available "curl"; then
curl "${link_url}" -o "${path}"/"${link_url}"
else
echo "Required wget or curl but they are unavailable"
aroundabout marked this conversation as resolved.
Show resolved Hide resolved
exit 1
Expand Down
Loading