From 683f91026cf0cfa9308e255d690835941d411693 Mon Sep 17 00:00:00 2001 From: zstadler Date: Tue, 22 Nov 2022 10:04:25 +0200 Subject: [PATCH] Both `--input` and `--url` are optional (#24) - They are no longer mutually exclusive - Input-independent default graph-cache location - `/data/default-gh' - Resolve #23 Technical changes: - Simplify handling: of script variables and their defaults - Remove complex configuration handling and copy - Remove unused variables - Modify "our" copy of `config-example.yml` to enable http connections from outside of the container - Update and clarify the help text --- Dockerfile | 5 +++- graphhopper.sh | 65 ++++++++++++++------------------------------------ 2 files changed, 22 insertions(+), 48 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2ae189b..f1da1ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,9 +18,12 @@ COPY --from=build /graphhopper/web/target/graphhopper*.jar . COPY graphhopper.sh graphhopper/config-example.yml . +# Enable connections from outside of the container +RUN sed -i '/^ *bind_host/s/^ */&# /p' config-example.yml + VOLUME [ "/data" ] -EXPOSE 8989 +EXPOSE 8989 8990 HEALTHCHECK --interval=5s --timeout=3s CMD curl --fail http://localhost:8989/health || exit 1 diff --git a/graphhopper.sh b/graphhopper.sh index 109837f..2e4cef4 100644 --- a/graphhopper.sh +++ b/graphhopper.sh @@ -17,21 +17,20 @@ echo "## using java $vers from $JAVA_HOME" function printBashUsage { echo "$(basename $0): Start a Gpahhopper server." - echo "user access at 0.0.0.0:8989 and API access at 0.0.0.0:8989/route" + echo "Default user access at 0.0.0.0:8989 and API access at 0.0.0.0:8989/route" echo "" echo "Usage" - echo "$(basename $0) -i | --input [ ...] " - echo "$(basename $0) --url [ ...] " + echo "$(basename $0) [ ...] " echo "" echo "parameters:" - echo "--import only create the graph cache, to be used later for faster starts" - echo "-c | --config specify the application configuration" - echo "-i | --input path to the input file in the file system" + echo "-i | --input OSM local input file location" echo "--url download input file from a url and save as data.pbf" + echo "--import only create the graph cache, to be used later for faster starts" + echo "-c | --config application configuration file location" echo "-o | --graph-cache directory for graph cache output" echo "-p | --profiles comma separated list of vehicle profiles" - echo "--port start web server at the given port rather than 8989" - echo "--host specify to which host the service should be bound rather than 0.0.0.0" + echo "--port port for web server [default: 8989]" + echo "--host host address of the web server [default: 0.0.0.0]" echo "-h | --help display this message" } @@ -55,49 +54,21 @@ while [ ! -z $1 ]; do esac done +# Defaults : "${ACTION:=server}" - -if [[ "$CONFIG" == *properties ]]; then - echo "$CONFIG not allowed as configuration. Use yml" - exit -fi - -# default init, https://stackoverflow.com/a/28085062/194609 -: "${CONFIG:=config.yml}" -if [[ -f $CONFIG && $CONFIG != config.yml ]]; then - echo "Copying non-default config file: $CONFIG" - cp $CONFIG config.yml -fi -if [ ! -f "config.yml" ]; then - echo "No config file was specified, using config-example.yml" - cp config-example.yml $CONFIG -fi - -if [ "$URL" != "" ]; then - wget -S -nv -O "data.pbf" "$URL" - FILE="data.pbf" -fi - -if [ "$FILE" = "" ]; then - echo -e "No file or url were specified." - printBashUsage - exit 2 -fi - -# DATA_DIR = directories path to the file if any (if current directory, return .) -DATADIR=$(dirname "${FILE}") -# create the directories if needed -mkdir -p $DATADIR -# BASENAME = filename (file without the directories) -BASENAME=$(basename "${FILE}") -# NAME = file without extension if any -NAME="${BASENAME%.*}" - +: "${GRAPH:=/data/default-gh}" +: "${CONFIG:=config-example.yml}" : "${JAVA_OPTS:=-Xmx1g -Xms1g}" : "${JAR:=$(find . -type f -name "*.jar")}" -: "${GRAPH:=$DATADIR/$NAME-gh}" + +if [ "$URL" != "" ]; then + wget -S -nv -O "${FILE:=data.pbf}" "$URL" +fi + +# create the directories if needed +mkdir -p $(dirname "${GRAPH}") echo "## Executing $ACTION. JAVA_OPTS=$JAVA_OPTS" -exec "$JAVA" $JAVA_OPTS -Ddw.graphhopper.datareader.file="$FILE" -Ddw.graphhopper.graph.location="$GRAPH" \ +exec "$JAVA" $JAVA_OPTS ${FILE:+-Ddw.graphhopper.datareader.file="$FILE"} -Ddw.graphhopper.graph.location="$GRAPH" \ $GH_WEB_OPTS -jar "$JAR" $ACTION $CONFIG