From 7fa3b094a919b24284b5a2deb60de20fbd4d39fc Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Wed, 31 Jan 2024 19:03:39 +0100 Subject: [PATCH 01/42] feat(docker): Add the docker setup with jar This introduces a completely revamped docker setup. The missing parts are the workflows and the docker-compose.yml. Without any configuration the container uses an example yml config shipped with it. Graph locations are parsed from envs, json and yml files - Introduce container log levels and add adjustments - Upgrade build image to java 21 (still compiled to 17) --- Dockerfile | 97 ++++------- docker-compose.yml | 48 ++++-- docker-entrypoint.sh | 374 ++++++++++++++++++++++++++++++++++++++----- 3 files changed, 394 insertions(+), 125 deletions(-) diff --git a/Dockerfile b/Dockerfile index b7a01e2d13..a1c1d55634 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,53 +1,22 @@ -# Image is reused in the workflow builds for main and the latest version -FROM maven:3.8-openjdk-17-slim as base - +# Image is reused in the workflow builds for master and the latest version +FROM docker.io/maven:3.8.7-openjdk-18-slim AS build ARG DEBIAN_FRONTEND=noninteractive - -# hadolint ignore=DL3002 -USER root - -# Install dependencies and locales -# hadolint ignore=DL3008 -RUN apt-get update -qq && \ - apt-get install -qq -y --no-install-recommends nano moreutils jq wget && \ - apt-get clean && \ - rm -rf /var/lib/apt/lists/* - -FROM base as tomcat -ARG TOMCAT_MAJOR=10 -ARG TOMCAT_VERSION=10.1.11 - # hadolint ignore=DL3002 USER root -WORKDIR /tmp -# Prepare tomcat -RUN wget -q https://archive.apache.org/dist/tomcat/tomcat-${TOMCAT_MAJOR}/v${TOMCAT_VERSION}/bin/apache-tomcat-${TOMCAT_VERSION}.tar.gz -O /tmp/tomcat.tar.gz && \ - tar xf tomcat.tar.gz && \ - mv /tmp/apache-tomcat-${TOMCAT_VERSION}/ /tmp/tomcat && \ - echo "org.apache.catalina.level = WARNING" >> /tmp/tomcat/conf/logging.properties +WORKDIR /tmp/ors -FROM base as build +COPY ors-api /tmp/ors/ors-api +COPY ors-engine /tmp/ors/ors-engine +COPY pom.xml /tmp/ors/pom.xml +COPY ors-report-aggregation /tmp/ors/ors-report-aggregation -# hadolint ignore=DL3002 -USER root - -ENV MAVEN_OPTS="-Dmaven.repo.local=.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true" -ENV MAVEN_CLI_OPTS="--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true" - -WORKDIR /ors-core - -COPY ors-api /ors-core/ors-api -COPY ors-engine /ors-core/ors-engine -COPY pom.xml /ors-core/pom.xml -COPY ors-report-aggregation /ors-core/ors-report-aggregation - -# Build the project and ignore the report aggregation module as not needed for the API build war -RUN mvn package -DskipTests -P buildWar +# Build the project +RUN mvn clean package -DskipTests # build final image, just copying stuff inside -FROM amazoncorretto:17.0.7-alpine3.17 as publish +FROM docker.io/amazoncorretto:21.0.2-alpine3.19 AS publish # Build ARGS ARG UID=1000 @@ -55,44 +24,36 @@ ARG GID=1000 ARG OSM_FILE=./ors-api/src/test/files/heidelberg.osm.gz ARG BASE_FOLDER=/home/ors -# Runtime ENVs for tomcat -ENV CATALINA_BASE=${BASE_FOLDER}/tomcat -ENV CATALINA_HOME=${BASE_FOLDER}/tomcat -ENV CATALINA_PID=${BASE_FOLDER}/tomcat/temp/tomcat.pid - # Set the default language ENV LANG='en_US' LANGUAGE='en_US' LC_ALL='en_US' # Setup the target system with the right user and folders. -RUN apk add --no-cache bash=~'5' openssl=~'3' && \ - addgroup -g ${GID} ors && \ - adduser -D -h ${BASE_FOLDER} -u ${UID} -G ors ors && \ - mkdir -p ${BASE_FOLDER}/ors-core/logs ${BASE_FOLDER}/ors-conf ${BASE_FOLDER}/ors-core/data ${BASE_FOLDER}/tomcat/logs && \ - chown -R ors ${BASE_FOLDER}/tomcat ${BASE_FOLDER}/ors-core/logs ${BASE_FOLDER}/ors-conf ${BASE_FOLDER}/ors-core/data ${BASE_FOLDER}/tomcat/logs +RUN apk update && apk add --no-cache bash openssl yq jq curl && \ + addgroup ors && \ + mkdir -p ${BASE_FOLDER}/logs ${BASE_FOLDER}/files ${BASE_FOLDER}/graphs ${BASE_FOLDER}/elevation_cache && \ + adduser -D -h ${BASE_FOLDER} --system -G ors ors && \ + chown -R ors ${BASE_FOLDER} WORKDIR ${BASE_FOLDER} # Copy over the needed bits and pieces from the other stages. -COPY --chown=ors:ors --from=tomcat /tmp/tomcat ${BASE_FOLDER}/tomcat -COPY --chown=ors:ors --from=build /ors-core/ors-api/target/ors.war ${BASE_FOLDER}/tomcat/webapps/ors.war -COPY --chown=ors:ors ./docker-entrypoint.sh ${BASE_FOLDER}/docker-entrypoint.sh -COPY --chown=ors:ors ./ors-config.yml ${BASE_FOLDER}/tmp/ors-config.yml -COPY --chown=ors:ors ./$OSM_FILE ${BASE_FOLDER}/tmp/osm_file.pbf +COPY --chown=ors:ors --from=build /tmp/ors/ors-api/target/ors.jar /ors.jar +COPY --chown=ors:ors ./ors-config.yml /example-ors-config.yml +COPY --chown=ors:ors ./ors-config.env /example-ors-config.env +COPY --chown=ors:ors ./$OSM_FILE /heidelberg.osm.gz +COPY ./docker-entrypoint.sh /entrypoint.sh -USER ${UID}:${GID} +# Set permissions +RUN chmod +x /ors.jar && chown -R ors:ors /entrypoint.sh && chown -R ors:ors ${BASE_FOLDER} && chown -R ors:ors /example-ors-config.yml && chown -R ors:ors /example-ors-config.env && \ + # Rewrite the example config to use the right files in the container + sed -i "/ors.engine.source_file=.*/s/.*/ors.engine.source_file=\/heidelberg.osm.gz/" "/example-ors-config.env" && \ + sed -i "/ source_file:.*/s/.*/ source_file: \/heidelberg.osm.gz/" "/example-ors-config.yml" -# Rewrite the ' source_file: ors-api/src/test/files/heidelberg.osm.gz' line in the config file to ' source_file: ${BASE_FOLDER}/ors-core/data/osm_file.pbf' -RUN sed -i "s| source_file: ors-api/src/test/files/heidelberg.osm.gz| source_file: ${BASE_FOLDER}/ors-core/data/osm_file.pbf|g" ${BASE_FOLDER}/tmp/ors-config.yml -# Rewrite the '# graphs_root_path: ./graphs' line in the config file to ' graphs_root_path: ${BASE_FOLDER}/ors-core/data/graphs' -RUN sed -i "s|# graphs_root_path: ./graphs| graphs_root_path: ${BASE_FOLDER}/ors-core/data/graphs|g" ${BASE_FOLDER}/tmp/ors-config.yml -# Rewrite the '# elevation:' line in the config file to ' elevation:' -RUN sed -i "s|# elevation:| elevation:|g" ${BASE_FOLDER}/tmp/ors-config.yml -# Rewrite the '# cache_path: ./elevation_cache' line in the config file to ' cache_path: ${BASE_FOLDER}/ors-core/data/elevation_cache' -RUN sed -i "s|# cache_path: ./elevation_cache| cache_path: ${BASE_FOLDER}/ors-core/data/elevation_cache|g" ${BASE_FOLDER}/tmp/ors-config.yml +#USER ${UID}:${GID} ENV BUILD_GRAPHS="False" -ENV ORS_CONFIG_LOCATION=ors-conf/ors-config.yml +# Set the ARG to an ENV. Else it will be lost. +ENV BASE_FOLDER=${BASE_FOLDER} # Start the container -ENTRYPOINT ["/home/ors/docker-entrypoint.sh"] -CMD ["/home/ors"] \ No newline at end of file +ENTRYPOINT ["/entrypoint.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index 11bb9eba78..5526982484 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,26 +1,40 @@ -version: '2.4' +# Docker Compose file for the openrouteservice (ORS) application +# Documentation and examples can be found on https://giscience.github.io/openrouteservice/run-instance/installation/running-with-docker +version: '3.8' services: ors-app: + # Activate the following lines to build the container from the repository + #build: + # context: ./ container_name: ors-app ports: - - "8080:8080" + - "8080:8082" - "9001:9001" image: openrouteservice/openrouteservice:nightly - # For versioned images see https://giscience.github.io/openrouteservice/run-instance/installation/running-with-docker user: "${UID:-0}:${GID:-0}" -# build: -# context: ./ -# args: -# OSM_FILE: ./ors-api/src/test/files/heidelberg.osm.gz volumes: - - ./docker/graphs:/home/ors/ors-core/data/graphs - - ./docker/elevation_cache:/home/ors/ors-core/data/elevation_cache - - ./docker/logs/ors:/home/ors/logs - - ./docker/logs/tomcat:/home/ors/tomcat/logs - - ./docker/conf:/home/ors/ors-conf - - ./docker/data:/home/ors/ors-core/data + - ./graphs:/home/ors/graphs + - ./elevation_cache:/home/ors/elevation_cache + - ./config:/home/ors/config + - ./logs:/home/ors/logs + - ./files:/home/ors/files environment: - - BUILD_GRAPHS=False # Forces the container to rebuild the graphs, e.g. when PBF is changed - - "JAVA_OPTS=-Djava.awt.headless=true -server -XX:TargetSurvivorRatio=75 -XX:SurvivorRatio=64 -XX:MaxTenuringThreshold=3 -XX:+UseG1GC -XX:+ScavengeBeforeFullGC -XX:ParallelGCThreads=4 -Xms1g -Xmx2g" - - "CATALINA_OPTS=-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9001 -Dcom.sun.management.jmxremote.rmi.port=9001 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost" - - ORS_CONFIG=/home/ors/ors-conf/ors-config.json \ No newline at end of file + BUILD_GRAPHS: False + CONTAINER_LOG_LEVEL: INFO # DEBUG, INFO, WARN, ERROR + # Configure your whole container with only property ENVs. + # These can be set alternatively or additional to the yml configuration file. + # See the ors-config.env file for more options. + # To have a configuration file-less container, set at least the following properties: + #ors.engine.source_file: /home/ors/files/example-heidelberg.osm.gz + #ors.engine.graphs_root_path=/home/ors/graphs + #ors.engine.elevation.cache_path=/home/ors/elevation_cache + #ors.engine.profiles.car.enabled: true + # Too much under 'environment:'? Use an env_file instead and define everything in there: + #env_file: ors-config.env + #healthcheck: + # test: curl --fail http://localhost:8080/ors/v2/health || exit 1 + # start_period: 1m + # interval: 10s + # timeout: 2s + # retries: 3 + # disable: false \ No newline at end of file diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 7c50aef244..f08b99391d 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -1,61 +1,355 @@ #!/usr/bin/env bash -echo "Running container as user $(whoami) with id $(id -u)" +######################## +# Set Helper functions # +######################## +# Log level functions +CONTAINER_LOG_LEVEL=${CONTAINER_LOG_LEVEL:-"INFO"} +# Success message in green. Always printed +function success() { + echo -e "\e[32m✓ $1\e[0m" + return 0 +} +# Critical message in bold red and exit. Always printed +function critical() { + echo -e "\e[1;31m $1\e[0m" + exit 1 +} +# Error message in red. +function error() { + echo -e "\e[31m✗ $1\e[0m" + return 0 +} +# Warning message in yellow +function warning() { + if [ "${container_log_level_int}" -le 30 ]; then + echo -e "\e[33m⚠ $1\e[0m" + fi + return 0 +} +# Info message in blue +function info() { + if [ "${container_log_level_int}" -le 20 ]; then + echo -e "\e[34mⓘ $1\e[0m" + fi + return 0 +} +# Debug message in cyan +function debug() { + if [ "${container_log_level_int}" -le 10 ]; then + echo -e "\e[36m▢ $1\e[0m" + fi + return 0 +} +function set_log_level() { + case ${CONTAINER_LOG_LEVEL} in + "DEBUG") + container_log_level_int=10 + ;; + "INFO") + container_log_level_int=20 + ;; + "WARN") + container_log_level_int=30 + ;; + "ERROR") + container_log_level_int=40 + ;; + "CRITICAL") + container_log_level_int=50 + ;; + *) + debug "No matching log level found: ${CONTAINER_LOG_LEVEL}." + debug "Defaulting to INFO." + CONTAINER_LOG_LEVEL="INFO" + container_log_level_int=20 + ;; + esac + success "CONTAINER_LOG_LEVEL: ${CONTAINER_LOG_LEVEL}. Set CONTAINER_LOG_LEVEL=DEBUG for more details." +} + +check_folder_writability() { + local folder="$1" + + if ! touch "${folder}"/.test 2>/dev/null; then + # Echo error with a red x instead of a check + return 1 + else + rm -rf "${folder:?}"/.test + return 0 + fi +} + +update_file() { + local target_file_path="$1" + local original_file_path="$2" + # Default to false + local print_migration_info_on_update="${3:-false}" + + if [ ! -f "${target_file_path}" ] || ! cmp -s "${original_file_path}" "${target_file_path}"; then + success "Update the file ${target_file_path} with ${original_file_path}" + cp -f "${original_file_path}" "${target_file_path}" || warning "Could not copy ${original_file_path} to ${target_file_path}" + if [ "${print_migration_info_on_update}" = "true" ]; then + print_migration_info="true" + fi + else + success "The file ${target_file_path} is up to date" + fi +} + +extract_config_info() { + local config_location="$1" + local config_variable="$2" + local config_value="" + if [[ "${config_location}" = *.yml ]]; then + config_value=$(yq -r "${config_variable}" "${config_location}") + elif [[ "${config_location}" = *.json ]]; then + config_value=$(jq -r "${config_variable}" "${config_location}") + fi + # Validate the config value + if [ -z "${config_value}" ] || [ "${config_value}" = null ]; then + config_value="" + fi + # Return the value + echo "${config_value}" +} + +echo "#################" +echo "# Container ENV #" +echo "#################" +# Validate the log level +set_log_level +# Print BASE_FOLDER +success "BASE_FOLDER: ${BASE_FOLDER}" +# Users should define ORS_HOME. If not, use /home/ors +if [ -z "${ORS_HOME}" ]; then + debug "ORS_HOME not explicitly set. Using default: ${BASE_FOLDER}" + ORS_HOME=${BASE_FOLDER} + success "ORS_HOME: ${ORS_HOME}" +else + success "Custom ORS_HOME: ${ORS_HOME}" +fi +# Set the jar file location +original_jar_file=/ors.jar +# Make sure BUILD_GRAPHS is safe to use +ors_build_graphs=${BUILD_GRAPHS:-"false"} +# get ors.engine.graphs_root_path=. Dot notations in bash are not allowed, so we need to use awk to parse it. +ors_engine_graphs_root_path=$(env | grep "^ors\.engine\.graphs_root_path=" | awk -F '=' '{print $2}') +# get ors.engine.elevation.cache_path +ors_engine_elevation_cache_path=$(env | grep "^ors\.engine\.elevation\.cache_path=" | awk -F '=' '{print $2}') +# get ors.engine.source_file +ors_engine_source_file=$(env | grep "^ors\.engine\.source_file=" | awk -F '=' '{print $2}') +# get ors_config_location +ors_config_location=${ORS_CONFIG_LOCATION:-""} +# Unset the ORS_CONFIG_LOCATION to not interfere with the spring-boot application +unset ORS_CONFIG_LOCATION +# Parse the ors.* properties +env | while read -r line; do + debug "${line}" +done +info "Any config file settings can be overwritten by environment variables." +info "Use 'CONTAINER_LOG_LEVEL=DEBUG' to see the full list of active environment variables for this container." +echo "###########################" +echo "# Container sanity checks #" +echo "###########################" +debug "Running container as user $(whoami) with id $(id -u) and group $(id -g)" if [[ -d /ors-core ]] || [[ -d /ors-conf ]]; then - echo "You're mounting old paths. Remove them and migrate to the new docker setup: https://giscience.github.io/openrouteservice/run-instance/installation/running-with-docker" - echo "Exit setup due to old folders /ors-core or /ors-conf being mounted" - sleep 5 - exit 1 + warning "Found remnants of old docker setup." + warning "The ors-core and ors-conf folders are not used by default with the new docker setup." + warning "Continuing with the new docker setup." fi -ors_base=${1} -catalina_base=${ors_base}/tomcat -graphs=${ors_base}/ors-core/data/graphs +mkdir -p "${ORS_HOME}" || critical "Could not create ${ORS_HOME}" + +# Make sure BASE_FOLDER and ORS_HOME exist and are writable +check_folder_writability "${BASE_FOLDER}" || critical "BASE_FOLDER: ${BASE_FOLDER} doesn't exist or is not writable." +success "BASE_FOLDER: ${BASE_FOLDER} exists and is writable." +check_folder_writability "${ORS_HOME}" || critical "ORS_HOME: ${ORS_HOME} doesn't exist or is not writable." +success "ORS_HOME: ${ORS_HOME} exists and is writable." -echo "ORS Path: ${ors_base}" -echo "Catalina Path: ${catalina_base}" +mkdir -p "${ORS_HOME}"/{files,logs,config,graphs,elevation_cache} || warning "Could not create ${ORS_HOME} and folders" +debug "Populated ORS_HOME=${ORS_HOME} with the default folders: files, logs, config, graphs, elevation_cache" + +# Check if the original jar file exists +if [ ! -f "${original_jar_file}" ]; then + critical "Original Jar file not found. This shouldn't happen. Exiting." +else + success "Update ors.jar at ${ORS_HOME}/ors.jar" + cp -f "${original_jar_file}" "${ORS_HOME}/ors.jar" || warning "Could not copy ${original_jar_file} to ${ORS_HOME}/ors.jar" + jar_file="${ORS_HOME}/ors.jar" +fi +# Fail if BASE_FOLDER env var is not set or if it is empty or set to / +if [ -z "${BASE_FOLDER}" ] || [ "${BASE_FOLDER}" = "/" ]; then + critical "BASE_FOLDER is not set or empty or set to /. This is not allowed. Exiting." +else + debug "BASE_FOLDER=${BASE_FOLDER} is set and not empty and not set to /" +fi -if [ -z "${CATALINA_OPTS}" ]; then - export CATALINA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9001 -Dcom.sun.management.jmxremote.rmi.port=9001 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost" +# Check that ors_engine_graphs_root_path is not empty and not set to / +if [ -n "${ors_engine_graphs_root_path}" ] && [ "${ors_engine_graphs_root_path}" = "/" ]; then + critical "ors.engine.graphs_root_path is set to /. This is not allowed. Exiting." +else + debug "ors.engine.graphs_root_path=${ors_engine_graphs_root_path} is set and not empty and not set to /" fi -if [ -z "${JAVA_OPTS}" ]; then - export JAVA_OPTS="-Djava.awt.headless=true -server -XX:TargetSurvivorRatio=75 -XX:SurvivorRatio=64 -XX:MaxTenuringThreshold=3 -XX:+UseG1GC -XX:+ScavengeBeforeFullGC -XX:ParallelGCThreads=4 -Xms1g -Xmx2g" +# Check that ors_engine_elevation_cache_path is not empty and not set to / +if [ -n "${ors_engine_elevation_cache_path}" ] && [ "${ors_engine_elevation_cache_path}" = "/" ]; then + critical "ors.engine.elevation.cache_path is set to /. This is not allowed. Exiting." +else + debug "ors.engine.elevation.cache_path=${ors_engine_elevation_cache_path} is set and not empty and not set to /" fi -{ - echo "CATALINA_BASE=\"${catalina_base}\"" - echo "CATALINA_HOME=\"${catalina_base}\"" - echo "CATALINA_PID=\"${catalina_base}/temp/tomcat.pid\"" - echo "CATALINA_OPTS=\"${CATALINA_OPTS}\"" - echo "JAVA_OPTS=\"${JAVA_OPTS}\"" -} >"${catalina_base}"/bin/setenv.sh +# Update the example-ors-config.env and example-ors-config.yml files if they don't exist or have changed +update_file "${ORS_HOME}/config/example-ors-config.env" "/example-ors-config.env" "true" +update_file "${ORS_HOME}/config/example-ors-config.yml" "/example-ors-config.yml" "true" + +# The config situation is difficult due to the recent ors versions. +# To ensure a smooth transition, we need to check if the user is using a .json file or a .yml file. +# If neither is set, we need to print a migration info and default to the example-ors-config.env file. +# Check if ors_config_location is a .json file +if [[ "${ors_config_location}" = *.yml ]]; then + success "Using yml config: ${ors_config_location}" +elif [[ "${ors_config_location}" = *.json ]]; then + success "Using json config: ${ors_config_location}" + # Print the above warning message in individual warning calls + warning ".json configurations are deprecated and will be removed in the future." + print_migration_info="true" +else + debug "No implicit config file provided." + success "Default to config: ${ORS_HOME}/config/example-ors-config.yml" + ors_config_location="${ORS_HOME}/config/example-ors-config.yml" +fi -if [ "${BUILD_GRAPHS}" = "True" ]; then - rm -rf "${graphs:?}"/* +# Get relevant configuration information from the .yml or .json file +if [[ -z "${ors_engine_graphs_root_path}" ]] && [[ "${config_location}" = *.yml ]]; then + ors_engine_graphs_root_path=$(extract_config_info "${ors_config_location}" '.ors.engine.graphs_root_path') fi -echo "### openrouteservice configuration ###" -# Always overwrite the example config in case another one is present -cp -f "${ors_base}/tmp/ors-config.yml" "${ors_base}/ors-conf/ors-config-example.yml" -# Check for old .json configs -JSON_FILES=$(ls -d -- "${ors_base}/ors-conf/"*.json 2>/dev/null) -if [ -n "$JSON_FILES" ]; then - echo "Old .json config found. They're deprecated and will be replaced in ORS version 8." - echo "Please migrate to the new .yml example." +if [[ -z "${ors_engine_graphs_root_path}" ]] && [[ "${config_location}" = *.json ]]; then + ors_engine_graphs_root_path=$(extract_config_info "${ors_config_location}" '.ors.services.routing.profiles.default_params.graphs_root_path') fi -# No config found. Use the base config -if [ ! -f "${ors_base}/ors-conf/ors-config.yml" ]; then - echo "Copy ors-config.yml" - cp -f "${ors_base}/tmp/ors-config.yml" "${ors_base}/ors-conf/ors-config.yml" + +if [[ -z "${ors_engine_source_file}" ]] && [[ "${ors_config_location}" = *.yml ]]; then + ors_engine_source_file=$(extract_config_info "${ors_config_location}" '.ors.engine.source_file') fi -if [ ! -f "${ors_base}/ors-core/data/osm_file.pbf" ]; then - echo "Copy osm_file.pbf" - cp -f "${ors_base}/tmp/osm_file.pbf" "${ors_base}/ors-core/data/osm_file.pbf" +if [[ -z "${ors_engine_source_file}" ]] && [[ "${ors_config_location}" = *.json ]]; then + ors_engine_source_file=$(extract_config_info "${ors_config_location}" '.ors.services.routing.sources[0]') +fi + +if [ -n "${ors_engine_graphs_root_path}" ]; then + success "Using graphs folder ${ors_engine_graphs_root_path}" +else + info "Default to graphs folder: ${ORS_HOME}/graphs" + ors_engine_graphs_root_path="${ORS_HOME}/graphs" +fi + +if [ -n "${ors_engine_source_file}" ]; then + debug "OSM source file set to ${ors_engine_source_file}" + # Check if it is the example file in root or the home folder + if [[ "${ors_engine_source_file}" = "/heidelberg.osm.gz" ]] || [[ "${ors_engine_source_file}" = "${ORS_HOME}/files/example-heidelberg.osm.gz" ]]; then + info "Default to example osm source file: \"${ors_engine_source_file}\"" + fi +fi + +info "Any ENV variables will have precedence over configuration variables from config files." +success "All checks passed. For details set CONTAINER_LOG_LEVEL=DEBUG." + +echo "#####################################" +echo "# Container file system preparation #" +echo "#####################################" +chown -R "$(whoami)" "${ORS_HOME}" || warning "Could not change ownership of ${ORS_HOME} to $(whoami)" +debug "Changed ownership of ${ORS_HOME} to $(whoami)" + +update_file "${ORS_HOME}/files/example-heidelberg.osm.gz" "/heidelberg.osm.gz" + +# Remove existing graphs if BUILD_GRAPHS is set to true +if [ "${ors_build_graphs}" = "true" ]; then + # Warn if ors.engine.graphs_root_path is not set or empty + if [ -z "${ors_engine_graphs_root_path}" ]; then + warning "graphs_root_path is not set or could not be found. Skipping cleanup." + elif [ -d "${ors_engine_graphs_root_path}" ]; then + # Check the ors.engine.graphs_root_path folder exists + rm -rf "${ors_engine_graphs_root_path:?}"/* || warning "Could not remove ${ors_engine_graphs_root_path}" + success "Removed graphs at ${ors_engine_graphs_root_path}/*." + else + debug "${ors_engine_graphs_root_path} does not exist (yet). Skipping cleanup." + fi + # Create the graphs folder again + mkdir -p "${ors_engine_graphs_root_path}" || warning "Could not populate graph folder at ${ors_engine_graphs_root_path}" +fi + +success "Container file system preparation complete. For details set CONTAINER_LOG_LEVEL=DEBUG." + +echo "#######################################" +echo "# Prepare CATALINA_OPTS and JAVA_OPTS #" +echo "#######################################" +# Let the user define every parameter via env vars if not, default to the values below +management_jmxremote_port=${MANAGEMENT_JMXREMOTE_PORT:-9001} +management_jmxremote_rmi_port=${MANAGEMENT_JMXREMOTE_RMI_PORT:-9001} +management_jmxremote_authenticate=${MANAGEMENT_JMXREMOTE_AUTHENTICATE:-false} +management_jmxremote_ssl=${MANAGEMENT_JMXREMOTE_SSL:-false} +java_rmi_server_hostname=${JAVA_RMI_SERVER_HOSTNAME:-localhost} +additional_catalina_opts=${ADDITIONAL_CATALINA_OPTS:-""} +# Let the user define every parameter via env vars if not, default to the values below +target_survivor_ratio=${TARGET_SURVIVOR_RATIO:-75} +survivor_ratio=${SURVIVOR_RATIO:-64} +max_tenuring_threshold=${MAX_TENURING_THRESHOLD:-3} +parallel_gc_threads=${PARALLEL_GC_THREADS:-4} +xms=${XMS:-1g} +xmx=${XMX:-2g} +additional_java_opts=${ADDITIONAL_JAVA_OPTS:-""} + +CATALINA_OPTS="-Dcom.sun.management.jmxremote \ +-Dcom.sun.management.jmxremote.port=${management_jmxremote_port} \ +-Dcom.sun.management.jmxremote.rmi.port=${management_jmxremote_rmi_port} \ +-Dcom.sun.management.jmxremote.authenticate=${management_jmxremote_authenticate} \ +-Dcom.sun.management.jmxremote.ssl=${management_jmxremote_ssl} \ +-Djava.rmi.server.hostname=${java_rmi_server_hostname} \ +${additional_catalina_opts}" +debug "CATALINA_OPTS: ${CATALINA_OPTS}" + +JAVA_OPTS="-Djava.awt.headless=true \ +-server -XX:TargetSurvivorRatio=${target_survivor_ratio} \ +-XX:SurvivorRatio=${survivor_ratio} \ +-XX:MaxTenuringThreshold=${max_tenuring_threshold} \ +-XX:+UseG1GC \ +-XX:+ScavengeBeforeFullGC \ +-XX:ParallelGCThreads=${parallel_gc_threads} \ +-Xms${xms} \ +-Xmx${xmx} \ +${additional_java_opts}" +debug "JAVA_OPTS: ${JAVA_OPTS}" +success "CATALINA_OPTS and JAVA_OPTS ready. For details set CONTAINER_LOG_LEVEL=DEBUG." + +# Print the migration info if print_migration_info is set to true but not if PRINT_MIGRATION_INFO is set to False +if [ "${print_migration_info}" = "true" ]; then + info "##########################################" + info "# Config migration and usage information #" + info "##########################################" + info ">>> Migration information <<<" + info "Find detailed information for migrating to ORS version 8 at: "# TODO + info ">>> Config migration <<<" + info "Configuring ors with a .json config is deprecated and will be removed in the future." + info "You've the following new methods to configure ORS:" + info "Method 1 yml config:" + info "> docker cp ors-container-name:${ORS_HOME}/config/example-ors-config.yml ./ors-config.yml" + info "> docker run --name example-ors-instance-conf-file -e ORS_CONFIG_LOCATION=${ORS_HOME}/config/ors-config.yml -v \$(pwd)/ors-config.yml:${ORS_HOME}/config/ors-config.yml heigit/openrouteservice:latest" + info "Method 2 environment variables:" + info "> docker cp ors-container-name:${ORS_HOME}/config/example-ors-config.env ./ors-config.env" + info "> docker run --name example-ors-instance-env-file --env-file ors-config.env heigit/openrouteservice:latest" + info ">>> End of migration information <<<" fi -# so docker can stop the process gracefully -exec "${catalina_base}"/bin/catalina.sh run +echo "#####################" +echo "# ORS startup phase #" +echo "#####################" +# Start the jar with the given arguments and add the ORS_HOME env var +success "🙭 Ready to start the ORS application 🙭" +debug "Startup command: java ${JAVA_OPTS} ${CATALINA_OPTS} -jar ${jar_file}" +# Export ORS_CONFIG_LOCATION to the environment of child processes +export ORS_CONFIG_LOCATION=${ors_config_location} +# shellcheck disable=SC2086 # we need word splitting here +exec java ${JAVA_OPTS} ${CATALINA_OPTS} -jar "${jar_file}" "$@" \ No newline at end of file From 548660f251b0dc8ad01b968ef2934727cc48f634 Mon Sep 17 00:00:00 2001 From: Amandus Butzer Date: Tue, 13 Feb 2024 12:43:57 +0100 Subject: [PATCH 02/42] chore: ignore generated folders --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c85f87c1fc..1e8a7b6d48 100644 --- a/.gitignore +++ b/.gitignore @@ -16,7 +16,8 @@ node_modules/ .jqwik-database # Ignore folders generated from docker -docker/ +/config/ +/files/ # Ignore all ors-config files except for the sample one, useful for development and testing ors-api/src/main/resources/ors-config* From 4af066feaf4c76e15f7865d1ebfba93196428474 Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Wed, 31 Jan 2024 19:04:00 +0100 Subject: [PATCH 03/42] chore(config-conversion): Rename the parser script --- ...fig_conversion.sh => yml_config_to_ors_config_conversion.sh} | 0 .github/workflows/config-conversion-automation.yml | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename .github/utils/{config_conversion.sh => yml_config_to_ors_config_conversion.sh} (100%) diff --git a/.github/utils/config_conversion.sh b/.github/utils/yml_config_to_ors_config_conversion.sh similarity index 100% rename from .github/utils/config_conversion.sh rename to .github/utils/yml_config_to_ors_config_conversion.sh diff --git a/.github/workflows/config-conversion-automation.yml b/.github/workflows/config-conversion-automation.yml index 9499e22611..c922aa3190 100644 --- a/.github/workflows/config-conversion-automation.yml +++ b/.github/workflows/config-conversion-automation.yml @@ -22,7 +22,7 @@ jobs: ref: ${{ github.head_ref }} - name: Convert application.yml to ors-config.yml run: | - .github/utils/config_conversion.sh ors-api/src/main/resources/application.yml ors-config.yml + .github/utils/yml_config_to_ors_config_conversion.sh ors-api/src/main/resources/application.yml ors-config.yml - uses: MichaelsJP/git-auto-commit-action@v5 with: commit_message: 'chore(config): automatic conversion of application.yml to ors-config.yml' From 2d44059d56d070ab4d3365177ffe62f23e601a65 Mon Sep 17 00:00:00 2001 From: Amandus Butzer Date: Thu, 15 Feb 2024 13:11:15 +0100 Subject: [PATCH 04/42] chore(config-conversion): rework & add properties conversion - move application.yml validation to separate file - add error exit codes - use yq to edit & validate - use sed instead of awk (for os compatibility) - move comments to echo output - add a new script to parse application.yml to a properties file The scripts are using yq to make the rewrite process more robust. The less we use sed magic, the better. --- .../yml_config_to_ors_config_conversion.sh | 41 ++++++------ .../yml_config_to_properties_conversion.sh | 62 +++++++++++++++++++ .github/utils/yml_config_validation.sh | 21 +++++++ .../config-conversion-automation.yml | 16 +++-- 4 files changed, 114 insertions(+), 26 deletions(-) create mode 100755 .github/utils/yml_config_to_properties_conversion.sh create mode 100755 .github/utils/yml_config_validation.sh diff --git a/.github/utils/yml_config_to_ors_config_conversion.sh b/.github/utils/yml_config_to_ors_config_conversion.sh index 8eac250326..2a73095832 100755 --- a/.github/utils/yml_config_to_ors_config_conversion.sh +++ b/.github/utils/yml_config_to_ors_config_conversion.sh @@ -7,37 +7,36 @@ fi input_file=$1 output_file=$2 -ors_file="ors-api/src/test/files/heidelberg.osm.gz" + +echo "" +echo "Copy $input_file to $output_file" +cp $input_file $output_file ########################### -### Validate input file ### +### Replace parameters #### ########################### -# Fail if ors: can't be found -echo "Checking for ors section" -awk '/^ors:/{print "Found ors section"}' "$input_file" || exit 1 +echo "" +echo "Replace parameters:" -# For engine and source file section, make sure they are in place -echo "Checking for engine and source_file section" -awk '/ engine:/{getline; if ($0 ~ /source_file:/) {print "Found engine and source_file section"} else { exit 1 }}' "$input_file" || exit 1 +echo "- enable ors.engine.profiles.car" +yq -i '.ors.engine.profiles.car.enabled = true' "$output_file" || exit 1 -# For profiles section for car wit enabled -echo "Checking for profiles section" -awk '/ profiles:/{getline; if ($0 ~ / car:/) {getline; if ($0 ~ / enabled:/) {print "Found profiles section"} else { exit 1 }}}' "$input_file" || exit 1 +echo "- set ors.engine.source_file to ors-api/src/test/files/heidelberg.osm.gz" +yq -i '.ors.engine.source_file = "ors-api/src/test/files/heidelberg.osm.gz"' "$output_file" || exit 1 ########################### ### Convert input file #### ########################### -# Add # to the beginning of each line that is not empty or a comment -awk '!/^[[:space:]]*#/ && !/^[[:space:]]*$/ {print "#" $0; next} {print}' "$input_file" > "$output_file" - -# Replace '#ors:' with 'ors:' -sed -i 's/#ors:/ors:/g' "$output_file" - +echo "" +echo "Converting input file:" +## Add # to the beginning of each line that is not empty or a comment +echo "- Comment everything" +sed -i '/^\s*[^#]/ s/^/#/' "$output_file" || exit 1 -# Remove the comments for the engine and source_file section -awk -i inplace "/engine:/{getline; if (\$0 ~ /source_file:/) {print \" engine:\"; print \" source_file: '$ors_file'\"; next} else { exit1 }} {print}" "$output_file" +echo "- Uncomment ors, engine and source_file" +sed -i -e '/^#ors:/s/^#//' -e '/^#.*engine:/s/^#//' -e '/^#.*source_file:/s/^#//' "$output_file" -# Remove the comments for the profiles section for car -awk -i inplace "/# profiles:/{getline; if (\$0 ~ /# car:/) {getline; if (\$0 ~ /# enabled:/) {print \" profiles:\"; print \" car:\"; print \" enabled: true\"; next}}}{print}" "$output_file" +echo "- Uncomment subsequent lines for profiles.car.enabled in ors.engine" +sed -i -e '/^# profiles:/,/^# enabled:/ s/^#//' "$output_file" echo "Parsing complete. Result saved to $output_file" diff --git a/.github/utils/yml_config_to_properties_conversion.sh b/.github/utils/yml_config_to_properties_conversion.sh new file mode 100755 index 0000000000..e93c44bb4b --- /dev/null +++ b/.github/utils/yml_config_to_properties_conversion.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +if [ "$#" -ne 2 ]; then + echo "Usage: $0 input.yaml output.properties" + exit 1 +fi + +input_file=$1 +output_file=$2 + +echo "" +echo "Copy $input_file to $output_file" +cp $input_file $output_file + +########################### +### Replace parameters #### +########################### +echo "" +echo "Replace parameters:" + +echo "- enable ors.engine.profiles.car" +yq -i '.ors.engine.profiles.car.enabled = true' "$output_file" || exit 1 + +echo "- set ors.engine.source_file to ors-api/src/test/files/heidelberg.osm.gz" +yq -i '.ors.engine.source_file = "ors-api/src/test/files/heidelberg.osm.gz"' "$output_file" || exit 1 + + +########################### +### Convert input file #### +########################### +echo "" +echo "Convert .yaml to .env/properties file:" +echo "- unwrap yaml structure to flat properties" +yq -i -o=props --unwrapScalar=false '.. | select(tag != "!!map" and tag != "!!seq") | ( (path | join(".")) + "=" + .)' "$output_file" || exit 1 + +## Add # to the beginning of each line that is not empty or a comment +echo "- Comment everything" +sed -i '/^\s*[^#]/ s/^/#/' "$output_file" || exit 1 + +echo "- Uncomment ors.engine.source_file and ors.engine.profiles.car.enabled" +sed -i -e '/^#ors.engine.source_file/s/^#//' -e '/^#ors.engine.profiles.car.enabled/s/^#//' "$output_file" || exit 1 + +############################ +### Validate output file ### +############################ +echo "" +echo "Validate output file:" +echo "- checking for ors.engine.source_file=ors-api/src/test/files/heidelberg.osm.gz" +return_value=$(sed -n '/^ors.engine.source_file=ors-api\/src\/test\/files\/heidelberg.osm.gz/p' $output_file)|| exit 1 +if [ -z "$return_value" ]; then + echo "ors.engine.source_file=ors-api/src/test/files/heidelberg.osm.gz not found" + exit 1 +fi +echo "- checking for ors.engine.profiles.car.enabled=true" +return_value=$(sed -n '/^ors.engine.profiles.car.enabled=true/p' $output_file) || exit 1 +if [ -z "$return_value" ]; then + echo "ors.engine.profiles.car.enabled=true not found" + exit 1 +fi + +echo "Parsing complete. Result saved to $output_file" + diff --git a/.github/utils/yml_config_validation.sh b/.github/utils/yml_config_validation.sh new file mode 100755 index 0000000000..fe615b1a7c --- /dev/null +++ b/.github/utils/yml_config_validation.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +if [ "$#" -ne 1 ]; then + echo "Usage: $0 input.yaml" + exit 1 +fi + +input_file=$1 + +########################### +### Validate input file ### +########################### +echo "Validate input file:" +echo "- checking if the input file is a valid yaml file" +yq 'true' $input_file /dev/null || exit 1 +# Fail if ors.engine.profiles.car.enabled='false' can't be found access with schema .result | select(.property_history != null) | .property_history | map(select(.event_name == "Sold"))[0].date' +echo "- checking if ors.engine.source_file exists and has 'source_file' property" +yq --exit-status '.ors.engine | has("source_file")' $input_file > /dev/null || exit 1 +# For profiles section for car with enabled using yq and contains +echo "- checking if ors.engine.profiles.car exists and has 'enabled' property" +yq --exit-status '.ors.engine.profiles.car | has("enabled")' $input_file > /dev/null || exit 1 \ No newline at end of file diff --git a/.github/workflows/config-conversion-automation.yml b/.github/workflows/config-conversion-automation.yml index c922aa3190..4332104191 100644 --- a/.github/workflows/config-conversion-automation.yml +++ b/.github/workflows/config-conversion-automation.yml @@ -1,4 +1,4 @@ -name: Automatic synchronization of application.yml to ors-config.yml +name: Automatic synchronization of application.yml to ors-config.yml and ors-config.env on: pull_request: branches: @@ -10,7 +10,7 @@ on: jobs: sync_config: - name: Synchronize changes in application.yml to ors-config.yml + name: Synchronize changes in application.yml to ors-config.yml and ors-config.env runs-on: ubuntu-latest permissions: contents: write @@ -20,10 +20,16 @@ jobs: uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} - - name: Convert application.yml to ors-config.yml + - name: yq - portable yaml processor + uses: mikefarah/yq@v4.40.5 + - name: validate application.yml + run: .github/utils/yml_config_validation.sh ors-api/src/main/resources/application.yml + - name: Convert application.yml to ors-config.yml and ors-config.env run: | + # Print yq version + yq --version .github/utils/yml_config_to_ors_config_conversion.sh ors-api/src/main/resources/application.yml ors-config.yml + .github/utils/yml_config_to_properties_conversion.sh ors-api/src/main/resources/application.yml ors-config.env - uses: MichaelsJP/git-auto-commit-action@v5 with: - commit_message: 'chore(config): automatic conversion of application.yml to ors-config.yml' - + commit_message: 'chore(config): automatic conversion of application.yml to ors-config.yml and ors-config.env' From d49eff8cdfb315cabef9cb546fb24c046f72ff04 Mon Sep 17 00:00:00 2001 From: Amandus Butzer Date: Thu, 15 Feb 2024 16:40:39 +0100 Subject: [PATCH 05/42] chore(config): automatic conversion of application.yml to ors-config.yml and ors-config.env --- ors-config.env | 214 +++++++++++++++++++++++++++++++++++++++++++++++++ ors-config.yml | 35 +++----- 2 files changed, 225 insertions(+), 24 deletions(-) create mode 100644 ors-config.env diff --git a/ors-config.env b/ors-config.env new file mode 100644 index 0000000000..df38d45b93 --- /dev/null +++ b/ors-config.env @@ -0,0 +1,214 @@ +#server.port=8082 +#server.error.whitelabel.enabled=false +#server.servlet.context-path=/ors +#spring.profiles.active=default +#spring.mvc.servlet.path=/ +#springdoc.swagger-ui.enabled=true +#springdoc.swagger-ui.path=/swagger-ui +#springdoc.swagger-ui.tryItOutEnabled=true +#springdoc.swagger-ui.filter=false +#springdoc.swagger-ui.syntaxHighlight.activated=true +#springdoc.swagger-ui.showExtensions=true +#springdoc.api-docs.path=/v2/api-docs +#springdoc.api-docs.version=OPENAPI_3_0 +#springdoc.packages-to-scan=org.heigit.ors +#springdoc.pathsToMatch=/v2/** +#logging.file.name=./logs/ors.log +#logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %highlight{%-7p} %style{%50t}{Cyan} %style{[ %-40.40c{1.} ]}{Bright Cyan} %m%n +#logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss} %p [%-40.40c{1.}] - %m%n +#logging.level.root=WARN +#logging.level.org.heigit=INFO +#ors.cors.allowed_origins=* +#ors.cors.allowed_headers=Content-Type, X-Requested-With, accept, Origin, Access-Control-Request-Method, Access-Control-Request-Headers, Authorization +#ors.cors.preflight_max_age=600 +#ors.messages= +#ors.endpoints.routing.enabled=true +#ors.endpoints.routing.attribution=openrouteservice.org, OpenStreetMap contributors, tmc - BASt +#ors.endpoints.routing.gpx_name=ORSRouting +#ors.endpoints.routing.gpx_description=This is a directions instructions file as GPX, generated from openrouteservice +#ors.endpoints.routing.gpx_base_url=https://openrouteservice.org/ +#ors.endpoints.routing.gpx_support_mail=support@openrouteservice.org +#ors.endpoints.routing.gpx_author=openrouteservice +#ors.endpoints.routing.gpx_content_licence=LGPL 3.0 +#ors.endpoints.routing.maximum_avoid_polygon_area=200000000 +#ors.endpoints.routing.maximum_avoid_polygon_extent=20000 +#ors.endpoints.routing.maximum_alternative_routes=3 +#ors.endpoints.matrix.enabled=true +#ors.endpoints.matrix.attribution=openrouteservice.org, OpenStreetMap contributors +#ors.endpoints.matrix.maximum_routes=2500 +#ors.endpoints.matrix.maximum_routes_flexible=25 +#ors.endpoints.matrix.maximum_visited_nodes=100000 +#ors.endpoints.matrix.maximum_search_radius=2000 +#ors.endpoints.matrix.u_turn_costs=-1 +#ors.endpoints.isochrones.enabled=true +#ors.endpoints.isochrones.attribution=openrouteservice.org, OpenStreetMap contributors +#ors.endpoints.isochrones.maximum_locations=2 +#ors.endpoints.isochrones.maximum_intervals=1 +#ors.endpoints.isochrones.allow_compute_area=true +#ors.endpoints.isochrones.maximum_range_distance_default=50000 +#ors.endpoints.isochrones.maximum_range_distance.0.profiles=driving-car, driving-hgv +#ors.endpoints.isochrones.maximum_range_distance.0.value=100000 +#ors.endpoints.isochrones.maximum_range_time_default=18000 +#ors.endpoints.isochrones.maximum_range_time.0.profiles=driving-car, driving-hgv +#ors.endpoints.isochrones.maximum_range_time.0.value=3600 +#ors.endpoints.isochrones.fastisochrones.maximum_range_distance_default=50000 +#ors.endpoints.isochrones.fastisochrones.maximum_range_distance.0.profiles=driving-car, driving-hgv +#ors.endpoints.isochrones.fastisochrones.maximum_range_distance.0.value=500000 +#ors.endpoints.isochrones.fastisochrones.maximum_range_time_default=18000 +#ors.endpoints.isochrones.fastisochrones.maximum_range_time.0.profiles=driving-car, driving-hgv +#ors.endpoints.isochrones.fastisochrones.maximum_range_time.0.value=10800 +#ors.endpoints.Snap.enabled=true +#ors.endpoints.Snap.attribution=openrouteservice.org, OpenStreetMap contributors +ors.engine.source_file=ors-api/src/test/files/heidelberg.osm.gz +#ors.engine.init_threads=1 +#ors.engine.preparation_mode=false +#ors.engine.graphs_root_path=./graphs +#ors.engine.graphs_data_access=RAM_STORE +#ors.engine.elevation.preprocessed=false +#ors.engine.elevation.data_access=MMAP +#ors.engine.elevation.cache_clear=false +#ors.engine.elevation.provider=multi +#ors.engine.elevation.cache_path=./elevation_cache +#ors.engine.profile_default.enabled=false +#ors.engine.profile_default.elevation=false +#ors.engine.profile_default.elevation_smoothing=false +#ors.engine.profile_default.encoder_flags_size=8 +#ors.engine.profile_default.instructions=true +#ors.engine.profile_default.optimize=false +#ors.engine.profile_default.traffic=false +#ors.engine.profile_default.maximum_distance=100000 +#ors.engine.profile_default.maximum_distance_dynamic_weights=100000 +#ors.engine.profile_default.maximum_distance_avoid_areas=100000 +#ors.engine.profile_default.maximum_waypoints=50 +#ors.engine.profile_default.maximum_snapping_radius=400 +#ors.engine.profile_default.maximum_distance_alternative_routes=100000 +#ors.engine.profile_default.maximum_distance_round_trip_routes=100000 +#ors.engine.profile_default.maximum_speed_lower_bound=80 +#ors.engine.profile_default.maximum_visited_nodes=1000000 +#ors.engine.profile_default.location_index_resolution=500 +#ors.engine.profile_default.location_index_search_iterations=4 +#ors.engine.profile_default.force_turn_costs=false +#ors.engine.profile_default.interpolate_bridges_and_tunnels=true +#ors.engine.profile_default.preparation.min_network_size=200 +#ors.engine.profile_default.preparation.methods.lm.enabled=true +#ors.engine.profile_default.preparation.methods.lm.threads=1 +#ors.engine.profile_default.preparation.methods.lm.weightings=recommended,shortest +#ors.engine.profile_default.preparation.methods.lm.landmarks=16 +#ors.engine.profile_default.execution.methods.lm.active_landmarks=8 +ors.engine.profiles.car.enabled=true +#ors.engine.profiles.car.profile=driving-car +#ors.engine.profiles.car.elevation=true +#ors.engine.profiles.car.encoder_options.turn_costs=true +#ors.engine.profiles.car.encoder_options.block_fords=false +#ors.engine.profiles.car.encoder_options.use_acceleration=true +#ors.engine.profiles.car.preparation.min_network_size=200 +#ors.engine.profiles.car.preparation.methods.ch.enabled=true +#ors.engine.profiles.car.preparation.methods.ch.threads=1 +#ors.engine.profiles.car.preparation.methods.ch.weightings=fastest +#ors.engine.profiles.car.preparation.methods.lm.enabled=false +#ors.engine.profiles.car.preparation.methods.lm.threads=1 +#ors.engine.profiles.car.preparation.methods.lm.weightings=fastest,shortest +#ors.engine.profiles.car.preparation.methods.lm.landmarks=16 +#ors.engine.profiles.car.preparation.methods.core.enabled=true +#ors.engine.profiles.car.preparation.methods.core.threads=1 +#ors.engine.profiles.car.preparation.methods.core.weightings=fastest,shortest +#ors.engine.profiles.car.preparation.methods.core.landmarks=64 +#ors.engine.profiles.car.preparation.methods.core.lmsets=highways;allow_all +#ors.engine.profiles.car.execution.methods.lm.active_landmarks=6 +#ors.engine.profiles.car.execution.methods.core.active_landmarks=6 +#ors.engine.profiles.car.ext_storages.WayCategory= +#ors.engine.profiles.car.ext_storages.HeavyVehicle= +#ors.engine.profiles.car.ext_storages.WaySurfaceType= +#ors.engine.profiles.car.ext_storages.RoadAccessRestrictions.use_for_warnings=true +#ors.engine.profiles.hgv.enabled=false +#ors.engine.profiles.hgv.profile=driving-hgv +#ors.engine.profiles.hgv.encoder_flags_size=8 +#ors.engine.profiles.hgv.encoder_options.turn_costs=true +#ors.engine.profiles.hgv.encoder_options.block_fords=false +#ors.engine.profiles.hgv.encoder_options.use_acceleration=true +#ors.engine.profiles.hgv.maximum_distance=100000 +#ors.engine.profiles.hgv.elevation=true +#ors.engine.profiles.hgv.preparation.min_network_size=200 +#ors.engine.profiles.hgv.preparation.methods.ch.enabled=true +#ors.engine.profiles.hgv.preparation.methods.ch.threads=1 +#ors.engine.profiles.hgv.preparation.methods.ch.weightings=recommended +#ors.engine.profiles.hgv.preparation.methods.core.enabled=true +#ors.engine.profiles.hgv.preparation.methods.core.threads=1 +#ors.engine.profiles.hgv.preparation.methods.core.weightings=recommended,shortest +#ors.engine.profiles.hgv.preparation.methods.core.landmarks=64 +#ors.engine.profiles.hgv.preparation.methods.core.lmsets=highways;allow_all +#ors.engine.profiles.hgv.execution.methods.core.active_landmarks=6 +#ors.engine.profiles.hgv.ext_storages.WayCategory= +#ors.engine.profiles.hgv.ext_storages.HeavyVehicle.restrictions=true +#ors.engine.profiles.hgv.ext_storages.WaySurfaceType= +#ors.engine.profiles.bike-regular.enabled=false +#ors.engine.profiles.bike-regular.profile=cycling-regular +#ors.engine.profiles.bike-regular.encoder_options.consider_elevation=true +#ors.engine.profiles.bike-regular.encoder_options.turn_costs=true +#ors.engine.profiles.bike-regular.encoder_options.block_fords=false +#ors.engine.profiles.bike-regular.elevation=true +#ors.engine.profiles.bike-regular.ext_storages.WayCategory= +#ors.engine.profiles.bike-regular.ext_storages.WaySurfaceType= +#ors.engine.profiles.bike-regular.ext_storages.HillIndex= +#ors.engine.profiles.bike-regular.ext_storages.TrailDifficulty= +#ors.engine.profiles.bike-mountain.enabled=false +#ors.engine.profiles.bike-mountain.profile=cycling-mountain +#ors.engine.profiles.bike-mountain.encoder_options.consider_elevation=true +#ors.engine.profiles.bike-mountain.encoder_options.turn_costs=true +#ors.engine.profiles.bike-mountain.encoder_options.block_fords=false +#ors.engine.profiles.bike-mountain.elevation=true +#ors.engine.profiles.bike-mountain.ext_storages.WayCategory= +#ors.engine.profiles.bike-mountain.ext_storages.WaySurfaceType= +#ors.engine.profiles.bike-mountain.ext_storages.HillIndex= +#ors.engine.profiles.bike-mountain.ext_storages.TrailDifficulty= +#ors.engine.profiles.bike-road.enabled=false +#ors.engine.profiles.bike-road.profile=cycling-road +#ors.engine.profiles.bike-road.encoder_options.consider_elevation=true +#ors.engine.profiles.bike-road.encoder_options.turn_costs=true +#ors.engine.profiles.bike-road.encoder_options.block_fords=false +#ors.engine.profiles.bike-road.elevation=true +#ors.engine.profiles.bike-road.ext_storages.WayCategory= +#ors.engine.profiles.bike-road.ext_storages.WaySurfaceType= +#ors.engine.profiles.bike-road.ext_storages.HillIndex= +#ors.engine.profiles.bike-road.ext_storages.TrailDifficulty= +#ors.engine.profiles.bike-electric.enabled=false +#ors.engine.profiles.bike-electric.profile=cycling-electric +#ors.engine.profiles.bike-electric.encoder_options.consider_elevation=true +#ors.engine.profiles.bike-electric.encoder_options.turn_costs=true +#ors.engine.profiles.bike-electric.encoder_options.block_fords=false +#ors.engine.profiles.bike-electric.elevation=true +#ors.engine.profiles.bike-electric.ext_storages.WayCategory= +#ors.engine.profiles.bike-electric.ext_storages.WaySurfaceType= +#ors.engine.profiles.bike-electric.ext_storages.HillIndex= +#ors.engine.profiles.bike-electric.ext_storages.TrailDifficulty= +#ors.engine.profiles.walking.enabled=false +#ors.engine.profiles.walking.profile=foot-walking +#ors.engine.profiles.walking.encoder_options.block_fords=false +#ors.engine.profiles.walking.elevation=true +#ors.engine.profiles.walking.ext_storages.WayCategory= +#ors.engine.profiles.walking.ext_storages.WaySurfaceType= +#ors.engine.profiles.walking.ext_storages.HillIndex= +#ors.engine.profiles.walking.ext_storages.TrailDifficulty= +#ors.engine.profiles.hiking.enabled=false +#ors.engine.profiles.hiking.profile=foot-hiking +#ors.engine.profiles.hiking.encoder_options.block_fords=false +#ors.engine.profiles.hiking.elevation=true +#ors.engine.profiles.hiking.ext_storages.WayCategory= +#ors.engine.profiles.hiking.ext_storages.WaySurfaceType= +#ors.engine.profiles.hiking.ext_storages.HillIndex= +#ors.engine.profiles.hiking.ext_storages.TrailDifficulty= +#ors.engine.profiles.wheelchair.enabled=false +#ors.engine.profiles.wheelchair.profile=wheelchair +#ors.engine.profiles.wheelchair.encoder_options.block_fords=true +#ors.engine.profiles.wheelchair.elevation=true +#ors.engine.profiles.wheelchair.maximum_snapping_radius=50 +#ors.engine.profiles.wheelchair.ext_storages.WayCategory= +#ors.engine.profiles.wheelchair.ext_storages.WaySurfaceType= +#ors.engine.profiles.wheelchair.ext_storages.Wheelchair.KerbsOnCrossings=true +#ors.engine.profiles.wheelchair.ext_storages.OsmId= +#ors.engine.profiles.public-transport.enabled=false +#ors.engine.profiles.public-transport.profile=public-transport +#ors.engine.profiles.public-transport.encoder_options.block_fords=false +#ors.engine.profiles.public-transport.elevation=true +#ors.engine.profiles.public-transport.maximum_visited_nodes=1000000 +#ors.engine.profiles.public-transport.gtfs_file=./src/test/files/vrn_gtfs_cut.zip diff --git a/ors-config.yml b/ors-config.yml index 996323fc12..8474bbb914 100644 --- a/ors-config.yml +++ b/ors-config.yml @@ -1,6 +1,6 @@ ##### openrouteservice settings file ##### # This file contains parameters for openrouteservice. -# For a full list of possible parameters see https://giscience.github.io/openrouteservice/ +# For a full list of possible parameters see https://giscience.github.io/openrouteservice/run-instance/configuration/ ##### General server settings ##### #server: @@ -8,17 +8,15 @@ # error: # whitelabel: # enabled: false - # Keep the context-path at / else the war file run with tomcat will have the context-path of /ors/v2 as well. +# # Keep the context-path at / else the war file run with tomcat will have the context-path of /ors/v2 as well. # servlet: # context-path: /ors - #spring: # profiles: # active: default # mvc: # servlet: # path: / - ##### Settings related to springdoc ##### #springdoc: # swagger-ui: @@ -34,23 +32,24 @@ # version: OPENAPI_3_0 # packages-to-scan: org.heigit.ors # pathsToMatch: /v2/** - ##### Logging settings ##### #logging: +# file: +# name: ./logs/ors.log +# pattern: +# console: "%d{yyyy-MM-dd HH:mm:ss} %highlight{%-7p} %style{%50t}{Cyan} %style{[ %-40.40c{1.} ]}{Bright Cyan} %m%n" +# file: "%d{yyyy-MM-dd HH:mm:ss} %p [%-40.40c{1.}] - %m%n" # level: # root: WARN # org.heigit: INFO - ##### openrouteservice specific settings ##### ors: # cors: # allowed_origins: "*" # allowed_headers: Content-Type, X-Requested-With, accept, Origin, Access-Control-Request-Method, Access-Control-Request-Headers, Authorization # preflight_max_age: 600 - # messages: - - ##### ORS endpoints settings ##### +# ##### ORS endpoints settings ##### # endpoints: # routing: # enabled: true @@ -72,7 +71,7 @@ ors: # maximum_visited_nodes: 100000 # maximum_search_radius: 2000 # u_turn_costs: -1 -# isochrone: +# isochrones: # enabled: true # attribution: openrouteservice.org, OpenStreetMap contributors # maximum_locations: 2 @@ -98,12 +97,11 @@ ors: # Snap: # enabled: true # attribution: openrouteservice.org, OpenStreetMap contributors - - ##### ORS engine settings ##### +# ##### ORS engine settings ##### engine: + source_file: ors-api/src/test/files/heidelberg.osm.gz # init_threads: 1 # preparation_mode: false - source_file: ors-api/src/test/files/heidelberg.osm.gz # graphs_root_path: ./graphs # graphs_data_access: RAM_STORE # elevation: @@ -135,7 +133,6 @@ ors: # interpolate_bridges_and_tunnels: true # preparation: # min_network_size: 200 -# min_one_way_network_size: 200 # methods: # lm: # enabled: true @@ -145,7 +142,6 @@ ors: # execution: # methods: # lm: -# disabling_allowed: true # active_landmarks: 8 profiles: car: @@ -158,7 +154,6 @@ ors: # use_acceleration: true # preparation: # min_network_size: 200 -# min_one_way_network_size: 200 # methods: # ch: # enabled: true @@ -177,13 +172,9 @@ ors: # lmsets: highways;allow_all # execution: # methods: -# ch: -# disabling_allowed: true # lm: -# disabling_allowed: true # active_landmarks: 6 # core: -# disabling_allowed: true # active_landmarks: 6 # ext_storages: # WayCategory: @@ -203,7 +194,6 @@ ors: # elevation: true # preparation: # min_network_size: 200 -# min_one_way_network_size: 200 # methods: # ch: # enabled: true @@ -217,10 +207,7 @@ ors: # lmsets: highways;allow_all # execution: # methods: -# ch: -# disabling_allowed: true # core: -# disabling_allowed: true # active_landmarks: 6 # ext_storages: # WayCategory: From 81036e896c75ebe5929290c79f3c520cb759e5fb Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Sun, 4 Feb 2024 01:52:54 +0100 Subject: [PATCH 06/42] ci(workflow): Update used actions version --- .github/workflows/docker-build-and-test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-build-and-test.yml b/.github/workflows/docker-build-and-test.yml index 3e829c98b5..bef1407c14 100644 --- a/.github/workflows/docker-build-and-test.yml +++ b/.github/workflows/docker-build-and-test.yml @@ -38,7 +38,7 @@ jobs: - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 id: buildx with: install: true @@ -95,7 +95,7 @@ jobs: with: platforms: ${{ matrix.platform }} - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v3 id: buildx with: install: true From eb9c2f4b60329f0f21b153eff2c04642a5e586bb Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Sun, 4 Feb 2024 02:01:43 +0100 Subject: [PATCH 07/42] ci(workflow): Update the docker build & test to the new setup - use ors default port in container - Add a basic docker compose check for built image --- .github/workflows/docker-build-and-test.yml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-build-and-test.yml b/.github/workflows/docker-build-and-test.yml index bef1407c14..2a3508b6ab 100644 --- a/.github/workflows/docker-build-and-test.yml +++ b/.github/workflows/docker-build-and-test.yml @@ -118,7 +118,18 @@ jobs: run: | mkdir -p $(pwd)/graphs $(pwd)/conf chown -R $UID $(pwd)/graphs $(pwd)/conf - docker run -it --user $UID -d -p 8080:8080 -v $(pwd)/graphs:/home/ors/ors-core/data/graphs -v $(pwd)/conf:/home/ors/ors-conf --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }} + # Replace image: in the docker-compose.yml with the test image. The value of image: can vary. + sed -i "s|image:.*|image: ${{ needs.prepare_environment.outputs.test_image_name }}|" docker-compose.yml + # Start the first build with the docker-compose setup + docker compose up --build -d + # Wait for all logs to come in + sleep 5 + docker compose logs ors-app + ./.github/utils/url_check.sh 127.0.0.1 8080 /ors/v2/health 200 ${{ env.HEALTH_WAIT_TIME }} + # Stop the compose setup and continue with docker run + docker compose down + # Start the container with the test image and the raw docker run command + docker run -it --user $UID -d -p 8080:8082 -v $(pwd)/graphs:/home/ors/ors-core/data/graphs -v $(pwd)/conf:/home/ors/ors-conf --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }} # Check for health to turn 200 after the graphs are build and spring-boot completely started ./.github/utils/url_check.sh 127.0.0.1 8080 /ors/v2/health 200 ${{ env.HEALTH_WAIT_TIME }} # Check for correct preflight settings to avoid CORS issues with ORIGIN wildcard from the example config @@ -136,7 +147,7 @@ jobs: docker stop ors-instance docker container prune -f chown -R $UID $(pwd)/graphs $(pwd)/conf - docker run -it --user $UID -d -p 8080:8080 -v $(pwd)/graphs:/home/ors/ors-core/data/graphs -v $(pwd)/conf:/home/ors/ors-conf --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }} + docker run -it --user $UID -d -p 8080:8082 -v $(pwd)/graphs:/home/ors/ors-core/data/graphs -v $(pwd)/conf:/home/ors/ors-conf -e ors.cors.allowed_origins=https://example.org --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }} # Request preflight with https://example.com and https://example.org to see if it gets applied correctly ./.github/utils/cors_check.sh 127.0.0.1 8080 /ors/v2/isochrones/geojson "https://example.org" 200 50 # It should fail with http code 403 for https://example.com since the Origin is not covered. From f68c21e89091b6c65bde6b3964727c3c01dc2658 Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Sun, 4 Feb 2024 19:40:44 +0100 Subject: [PATCH 08/42] feat(docker): Migrate BUILD_GRAPHS to REBUILD_GRAPHS This has been a misleading variable for some time. This introduces REBUILD_GRAPHS and keeps BUILD_GRAPHS in compatibility for now. --- Dockerfile | 1 + docker-compose.yml | 2 +- docker-entrypoint.sh | 19 ++++++++++++++++--- docs/run-instance/running-with-docker.md | 10 +++++----- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index a1c1d55634..e26fba544a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,6 +52,7 @@ RUN chmod +x /ors.jar && chown -R ors:ors /entrypoint.sh && chown -R ors:ors ${B #USER ${UID}:${GID} ENV BUILD_GRAPHS="False" +ENV REBUILD_GRAPHS="False" # Set the ARG to an ENV. Else it will be lost. ENV BASE_FOLDER=${BASE_FOLDER} diff --git a/docker-compose.yml b/docker-compose.yml index 5526982484..87d7518aa9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -19,7 +19,7 @@ services: - ./logs:/home/ors/logs - ./files:/home/ors/files environment: - BUILD_GRAPHS: False + REBUILD_GRAPHS: False # Set to True to rebuild graphs on container start. CONTAINER_LOG_LEVEL: INFO # DEBUG, INFO, WARN, ERROR # Configure your whole container with only property ENVs. # These can be set alternatively or additional to the yml configuration file. diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index f08b99391d..a5e604f7a1 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -129,10 +129,23 @@ if [ -z "${ORS_HOME}" ]; then else success "Custom ORS_HOME: ${ORS_HOME}" fi + # Set the jar file location original_jar_file=/ors.jar -# Make sure BUILD_GRAPHS is safe to use -ors_build_graphs=${BUILD_GRAPHS:-"false"} +BUILD_GRAPHS=${BUILD_GRAPHS:-"false"} +REBUILD_GRAPHS=${REBUILD_GRAPHS:-"false"} +# If BUILD_GRAPHS is set to true, we need to set ors_rebuild_graphs to true and print an info about migration to REBUILD_GRAPHS +if [ "${BUILD_GRAPHS}" = "true" ]; then + ors_rebuild_graphs="true" + warning "BUILD_GRAPHS is deprecated and will be removed in the future." + warning "Please use REBUILD_GRAPHS instead." +elif [ "${REBUILD_GRAPHS}" = "true" ]; then + ors_rebuild_graphs="true" +else + ors_rebuild_graphs="false" +fi + + # get ors.engine.graphs_root_path=. Dot notations in bash are not allowed, so we need to use awk to parse it. ors_engine_graphs_root_path=$(env | grep "^ors\.engine\.graphs_root_path=" | awk -F '=' '{print $2}') # get ors.engine.elevation.cache_path @@ -266,7 +279,7 @@ debug "Changed ownership of ${ORS_HOME} to $(whoami)" update_file "${ORS_HOME}/files/example-heidelberg.osm.gz" "/heidelberg.osm.gz" # Remove existing graphs if BUILD_GRAPHS is set to true -if [ "${ors_build_graphs}" = "true" ]; then +if [ "${ors_rebuild_graphs}" = "true" ]; then # Warn if ors.engine.graphs_root_path is not set or empty if [ -z "${ors_engine_graphs_root_path}" ]; then warning "graphs_root_path is not set or could not be found. Skipping cleanup." diff --git a/docs/run-instance/running-with-docker.md b/docs/run-instance/running-with-docker.md index 99789fb740..e03b2ad6b6 100644 --- a/docs/run-instance/running-with-docker.md +++ b/docs/run-instance/running-with-docker.md @@ -107,7 +107,7 @@ docker run -dt -u "${UID}:${GID}" \ -v $PWD/docker/logs/tomcat:/home/ors/tomcat/logs \ -v $PWD/docker/conf:/home/ors/ors-conf \ -v $PWD/docker/data:/home/ors/ors-core/data \ - #-e "BUILD_GRAPHS=True" \ + #-e "REBUILD_GRAPHS=True" \ -e "JAVA_OPTS=-Djava.awt.headless=true -server -XX:TargetSurvivorRatio=75 -XX:SurvivorRatio=64 -XX:MaxTenuringThreshold=3 -XX:+UseG1GC -XX:+ScavengeBeforeFullGC -XX:ParallelGCThreads=4 -Xms1g -Xmx2g" \ -e "CATALINA_OPTS=-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9001 -Dcom.sun.management.jmxremote.rmi.port=9001 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost" \ openrouteservice/openrouteservice:latest @@ -155,7 +155,7 @@ the use of old format JSON files placed at `./docker/conf/ors-config.json`. All will override settings in the proper YAML format. If you are making changes to anything relating to the OSM data or the settings that change how graphs are built, you -need to delete the folders in `graphs` or set the environment variable `BUILD_GRAPHS=True` (see comment in Dockerfile or +need to delete the folders in `graphs` or set the environment variable `REBUILD_GRAPHS=True` (see comment in Dockerfile or examples above). This makes it so that the graphs are built again with the new data/settings. ### Different OSM file @@ -164,7 +164,7 @@ To change the OSM data that is used, you can either overwrite the `docker/data/o mount of `/home/ors/ors-core/data` to a directory containing a file `osm_file.pbf`, or volume mount something like `/YOUR/PATH/TO/ANOTHER/OSM_FILE.pbf:/home/ors/ors-core/data/osm_file.pbf`. -Make sure to set the environment variable `BUILD_GRAPHS=True` or empty the `docker/graphs/` directory before restarting +Make sure to set the environment variable `REBUILD_GRAPHS=True` or empty the `docker/graphs/` directory before restarting the container. If you are building the Docker image locally, you can also point the build argument `OSM_FILE` to your desired OSM file @@ -212,7 +212,7 @@ examples. ### Environment variables -- `BUILD_GRAPHS`: Forces ORS to rebuild the routing graph(s) when set to `True`. Useful when another PBF is specified in +- `REBUILD_GRAPHS`: Forces ORS to rebuild the routing graph(s) when set to `True`. Useful when another PBF is specified in the Docker volume mapping to `/home/ors/ors-core/data/osm_file.pbf` - `JAVA_OPTS`: Custom Java runtime options, such as `-Xms` or `-Xmx` - `CATALINA_OPTS`: Custom Catalina options @@ -243,5 +243,5 @@ container. The new graphs will be reloaded into memory (the amount of time neede graphs and the type of hard drive) and then ready to use for routing. The downtime from reloading already built graphs is normally far less than the time needed to build the graphs. A thing to note though is that you should ensure that the config files and the amount of RAM allocated (as described earlier) is the same on both the builder and the request -server else the newly built graphs may not load. **Also, ensure that `BUILD_GRAPHS` parameter in the `docker-compose` +server else the newly built graphs may not load. **Also, ensure that `REBUILD_GRAPHS` parameter in the `docker-compose` file used by the request serving container is set to false else it will try to build the graphs for itself!** From cab31cd1492d1ac99eeb4f90212a42842657641a Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Sun, 4 Feb 2024 19:54:42 +0100 Subject: [PATCH 09/42] feat(docker): Enhance the documentation in the compose file --- docker-compose.yml | 47 ++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 87d7518aa9..6c6804bfe4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,40 +1,55 @@ # Docker Compose file for the openrouteservice (ORS) application # Documentation and examples can be found on https://giscience.github.io/openrouteservice/run-instance/installation/running-with-docker version: '3.8' + services: + # ----------------- ORS application configuration ------------------- # ors-app: # Activate the following lines to build the container from the repository #build: # context: ./ container_name: ors-app ports: - - "8080:8082" - - "9001:9001" + - "8080:8082" # Expose the ORS API on port 8080 + - "9001:9001" # Expose additional port for monitoring (optional) image: openrouteservice/openrouteservice:nightly - user: "${UID:-0}:${GID:-0}" + user: "${UID:-0}:${GID:-0}" # Set user and group IDs for the container (optional) volumes: - - ./graphs:/home/ors/graphs - - ./elevation_cache:/home/ors/elevation_cache - - ./config:/home/ors/config - - ./logs:/home/ors/logs - - ./files:/home/ors/files + - ./graphs:/home/ors/graphs # Mount graphs directory + - ./elevation_cache:/home/ors/elevation_cache # Mount elevation cache directory + - ./config:/home/ors/config # Mount configuration directory + - ./logs:/home/ors/logs # Mount logs directory + - ./files:/home/ors/files # Mount files directory environment: - REBUILD_GRAPHS: False # Set to True to rebuild graphs on container start. - CONTAINER_LOG_LEVEL: INFO # DEBUG, INFO, WARN, ERROR + REBUILD_GRAPHS: False # Set to True to rebuild graphs on container start. + CONTAINER_LOG_LEVEL: INFO # Log level for the container. Possible values: DEBUG, INFO, WARNING, ERROR, CRITICAL + ORS_CONFIG_LOCATION: /home/ors/config/example-ors-config.yml # Location of the default ORS configuration file + + # ----------------- Properties configuration ------------------- # # Configure your whole container with only property ENVs. - # These can be set alternatively or additional to the yml configuration file. + # These can be set alternatively or additionally to the yml configuration file. # See the ors-config.env file for more options. - # To have a configuration file-less container, set at least the following properties: + # To have a configuration file-less container, uncomment at least the following properties. + # The values are examples and provide the default configuration. #ors.engine.source_file: /home/ors/files/example-heidelberg.osm.gz - #ors.engine.graphs_root_path=/home/ors/graphs - #ors.engine.elevation.cache_path=/home/ors/elevation_cache + #ors.engine.graphs_root_path: /home/ors/graphs + #ors.engine.elevation.cache_path: /home/ors/elevation_cache #ors.engine.profiles.car.enabled: true - # Too much under 'environment:'? Use an env_file instead and define everything in there: + + # ----------------- ENV file configuration ------------------- # + # Too many variables for your 'environment:' section? + # Use an env_file with the ENV properties instead and define everything in there: #env_file: ors-config.env + + # ----------------- Healthcheck configuration ------------------- # + # The healthcheck is disabled by default. Uncomment the following lines to enable it. + # The healthcheck allows you to monitor the status of the ORS application. + # Be careful with long graph builds, as the healthcheck will fail and show 'unhealthy' during this time. + # This is especially useful if you run your ORS container in a production environment. #healthcheck: # test: curl --fail http://localhost:8080/ors/v2/health || exit 1 # start_period: 1m # interval: 10s # timeout: 2s # retries: 3 - # disable: false \ No newline at end of file + # disable: false From e379d5d8930f36b88868a8035c781218424d7418 Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Sun, 4 Feb 2024 21:39:04 +0100 Subject: [PATCH 10/42] fix(docker): Add more user related optimizations The setup now detects if the user runs the container with a less privileged user and prints out necessary data for that - improve container handling - add default java opts & information to docker-compose environment Co-authored-by: Amandus Butzer --- Dockerfile | 31 ++++++++++++++++--------------- docker-compose.yml | 35 ++++++++++++++++++++++++++++++----- docker-entrypoint.sh | 37 ++++++++++++++++++++++++------------- 3 files changed, 70 insertions(+), 33 deletions(-) diff --git a/Dockerfile b/Dockerfile index e26fba544a..44a498113e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,13 @@ COPY ors-report-aggregation /tmp/ors/ors-report-aggregation # Build the project RUN mvn clean package -DskipTests +# Copy the example config files to the build folder +COPY ./ors-config.yml /tmp/ors/example-ors-config.yml +COPY ./ors-config.env /tmp/ors/example-ors-config.env +# Rewrite the example config to use the right files in the container +RUN sed -i "/ors.engine.source_file=.*/s/.*/ors.engine.source_file=\/heidelberg.osm.gz/" "/tmp/ors/example-ors-config.env" && \ + sed -i "/ source_file:.*/s/.*/ source_file: \/heidelberg.osm.gz/" "/tmp/ors/example-ors-config.yml" + # build final image, just copying stuff inside FROM docker.io/amazoncorretto:21.0.2-alpine3.19 AS publish @@ -29,32 +36,26 @@ ENV LANG='en_US' LANGUAGE='en_US' LC_ALL='en_US' # Setup the target system with the right user and folders. RUN apk update && apk add --no-cache bash openssl yq jq curl && \ - addgroup ors && \ + addgroup ors -g ${GID} && \ mkdir -p ${BASE_FOLDER}/logs ${BASE_FOLDER}/files ${BASE_FOLDER}/graphs ${BASE_FOLDER}/elevation_cache && \ - adduser -D -h ${BASE_FOLDER} --system -G ors ors && \ - chown -R ors ${BASE_FOLDER} - -WORKDIR ${BASE_FOLDER} + adduser -D -h ${BASE_FOLDER} -u ${UID} --system -G ors ors && \ + chown ors:ors ${BASE_FOLDER} \ + # Give all permissions to the user + && chmod -R 777 ${BASE_FOLDER} # Copy over the needed bits and pieces from the other stages. COPY --chown=ors:ors --from=build /tmp/ors/ors-api/target/ors.jar /ors.jar -COPY --chown=ors:ors ./ors-config.yml /example-ors-config.yml -COPY --chown=ors:ors ./ors-config.env /example-ors-config.env +COPY --chown=ors:ors --from=build /tmp/ors/example-ors-config.yml /example-ors-config.yml +COPY --chown=ors:ors --from=build /tmp/ors/example-ors-config.env /example-ors-config.env COPY --chown=ors:ors ./$OSM_FILE /heidelberg.osm.gz -COPY ./docker-entrypoint.sh /entrypoint.sh +COPY --chown=ors:ors ./docker-entrypoint.sh /entrypoint.sh -# Set permissions -RUN chmod +x /ors.jar && chown -R ors:ors /entrypoint.sh && chown -R ors:ors ${BASE_FOLDER} && chown -R ors:ors /example-ors-config.yml && chown -R ors:ors /example-ors-config.env && \ - # Rewrite the example config to use the right files in the container - sed -i "/ors.engine.source_file=.*/s/.*/ors.engine.source_file=\/heidelberg.osm.gz/" "/example-ors-config.env" && \ - sed -i "/ source_file:.*/s/.*/ source_file: \/heidelberg.osm.gz/" "/example-ors-config.yml" - -#USER ${UID}:${GID} ENV BUILD_GRAPHS="False" ENV REBUILD_GRAPHS="False" # Set the ARG to an ENV. Else it will be lost. ENV BASE_FOLDER=${BASE_FOLDER} +WORKDIR ${BASE_FOLDER} # Start the container ENTRYPOINT ["/entrypoint.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index 6c6804bfe4..9894286d76 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,15 +6,16 @@ services: # ----------------- ORS application configuration ------------------- # ors-app: # Activate the following lines to build the container from the repository - #build: - # context: ./ + # You have to add --build to the docker compose command to do so + build: + context: ./ container_name: ors-app ports: - "8080:8082" # Expose the ORS API on port 8080 - "9001:9001" # Expose additional port for monitoring (optional) image: openrouteservice/openrouteservice:nightly - user: "${UID:-0}:${GID:-0}" # Set user and group IDs for the container (optional) - volumes: + #user: "0:0" # Set the user and group to 0 to avoid permission issues. Advanced option! + volumes: # Mount relative directories. ONLY for local container runtime. To switch to docker managed volumes see 'Docker Volumes configuration' section below. - ./graphs:/home/ors/graphs # Mount graphs directory - ./elevation_cache:/home/ors/elevation_cache # Mount elevation cache directory - ./config:/home/ors/config # Mount configuration directory @@ -23,11 +24,23 @@ services: environment: REBUILD_GRAPHS: False # Set to True to rebuild graphs on container start. CONTAINER_LOG_LEVEL: INFO # Log level for the container. Possible values: DEBUG, INFO, WARNING, ERROR, CRITICAL - ORS_CONFIG_LOCATION: /home/ors/config/example-ors-config.yml # Location of the default ORS configuration file + ORS_CONFIG_LOCATION: /home/ors/config/example-ors-config.yml # Location of the default ORS example configuration file in the docker container + # This config file will be reverted at each container start. If you want to use your own configuration file, create a copy in the container and rename this variable. + + # ------------------ JAVA OPTS ------------------ # + # Configure the memory settings for JAVA or pass additional opts + # Fore more available ENV properties see Prepare CATALINA_OPTS and JAVA_OPTS + # in https://github.com/GIScience/openrouteservice/blob/main/docker-entrypoint.sh + XMS: 1g # start RAM assigned to java + XMX: 2g # max RAM assigned to java. Rule of Thumb: * * 2 + # Example: 1.5 GB pbf size, two profiles (car and foot-walking) + # -> 1.5 * 2 * 2 = 6. Set xmx to be AT LEAST `-Xmx6g` + ADDITIONAL_JAVA_OPTS: "" # further options you want to pass to the java command # ----------------- Properties configuration ------------------- # # Configure your whole container with only property ENVs. # These can be set alternatively or additionally to the yml configuration file. + # Note, that any values set will override the corresponding values from the yml configuration file. # See the ors-config.env file for more options. # To have a configuration file-less container, uncomment at least the following properties. # The values are examples and provide the default configuration. @@ -39,6 +52,7 @@ services: # ----------------- ENV file configuration ------------------- # # Too many variables for your 'environment:' section? # Use an env_file with the ENV properties instead and define everything in there: + # Values will be overwritten if set in the 'environment' section. #env_file: ors-config.env # ----------------- Healthcheck configuration ------------------- # @@ -53,3 +67,14 @@ services: # timeout: 2s # retries: 3 # disable: false + +# ----------------- Docker Volumes configuration ------------------- # +# Define the Docker managed volumes for the ORS application. For more info on Docker Volumes see https://docs.docker.com/compose/compose-file/07-volumes/ +# Volumes are used to persist the data and configuration of the ORS application. +# If you want to use volumes, uncomment the following lines and remove the ./ prefix from the volume paths in 'services.ors-app.volumes'. +#volumes: +# graphs: +# elevation_cache: +# config: +# logs: +# files: diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index a5e604f7a1..f001c435cc 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -167,12 +167,26 @@ echo "###########################" echo "# Container sanity checks #" echo "###########################" debug "Running container as user $(whoami) with id $(id -u) and group $(id -g)" +if [[ $(id -u) -ne 0 ]] || [[ $(id -g) -ne 0 ]]; then + # Test if the user tampered with the user and group settings + warning "Running container as user '$(whoami)' with id $(id -u) and group $(id -g)" + warning "Changing these values is only recommended if you're an advanced docker user and can handle file permission issues yourself." + warning "Consider leaving the user and group options as root with 0:0 or 1000:1000 or avoid that setting completely." +fi + if [[ -d /ors-core ]] || [[ -d /ors-conf ]]; then warning "Found remnants of old docker setup." warning "The ors-core and ors-conf folders are not used by default with the new docker setup." warning "Continuing with the new docker setup." fi +# Fail if BASE_FOLDER env var is not set or if it is empty or set to / +if [ -z "${BASE_FOLDER}" ] || [ "${BASE_FOLDER}" = "/" ]; then + critical "BASE_FOLDER is not set or empty or set to /. This is not allowed. Exiting." +else + debug "BASE_FOLDER=${BASE_FOLDER} is set and not empty and not set to /" +fi + mkdir -p "${ORS_HOME}" || critical "Could not create ${ORS_HOME}" # Make sure BASE_FOLDER and ORS_HOME exist and are writable @@ -182,6 +196,7 @@ check_folder_writability "${ORS_HOME}" || critical "ORS_HOME: ${ORS_HOME} doesn' success "ORS_HOME: ${ORS_HOME} exists and is writable." mkdir -p "${ORS_HOME}"/{files,logs,config,graphs,elevation_cache} || warning "Could not create ${ORS_HOME} and folders" +mkdir -p "${BASE_FOLDER}"/{files,logs,config,graphs,elevation_cache} || warning "Could not create ${BASE_FOLDER} and folders" debug "Populated ORS_HOME=${ORS_HOME} with the default folders: files, logs, config, graphs, elevation_cache" # Check if the original jar file exists @@ -193,12 +208,6 @@ else jar_file="${ORS_HOME}/ors.jar" fi -# Fail if BASE_FOLDER env var is not set or if it is empty or set to / -if [ -z "${BASE_FOLDER}" ] || [ "${BASE_FOLDER}" = "/" ]; then - critical "BASE_FOLDER is not set or empty or set to /. This is not allowed. Exiting." -else - debug "BASE_FOLDER=${BASE_FOLDER} is set and not empty and not set to /" -fi # Check that ors_engine_graphs_root_path is not empty and not set to / if [ -n "${ors_engine_graphs_root_path}" ] && [ "${ors_engine_graphs_root_path}" = "/" ]; then @@ -221,10 +230,10 @@ update_file "${ORS_HOME}/config/example-ors-config.yml" "/example-ors-config.yml # The config situation is difficult due to the recent ors versions. # To ensure a smooth transition, we need to check if the user is using a .json file or a .yml file. # If neither is set, we need to print a migration info and default to the example-ors-config.env file. -# Check if ors_config_location is a .json file -if [[ "${ors_config_location}" = *.yml ]]; then +# Check if ors_config_location is a .json file and exists +if [[ "${ors_config_location}" = *.yml ]] && [[ -f "${ors_config_location}" ]]; then success "Using yml config: ${ors_config_location}" -elif [[ "${ors_config_location}" = *.json ]]; then +elif [[ "${ors_config_location}" = *.json ]] && [[ -f "${ors_config_location}" ]]; then success "Using json config: ${ors_config_location}" # Print the above warning message in individual warning calls warning ".json configurations are deprecated and will be removed in the future." @@ -273,8 +282,9 @@ success "All checks passed. For details set CONTAINER_LOG_LEVEL=DEBUG." echo "#####################################" echo "# Container file system preparation #" echo "#####################################" -chown -R "$(whoami)" "${ORS_HOME}" || warning "Could not change ownership of ${ORS_HOME} to $(whoami)" -debug "Changed ownership of ${ORS_HOME} to $(whoami)" +# Check if uid or gid is different from 1000 +chown -R "$(whoami)" "${ORS_HOME}"; debug "Changed ownership of ${ORS_HOME} to $(whoami)" || warning "Could not change ownership of ${ORS_HOME} to $(whoami)" + update_file "${ORS_HOME}/files/example-heidelberg.osm.gz" "/heidelberg.osm.gz" @@ -311,6 +321,7 @@ target_survivor_ratio=${TARGET_SURVIVOR_RATIO:-75} survivor_ratio=${SURVIVOR_RATIO:-64} max_tenuring_threshold=${MAX_TENURING_THRESHOLD:-3} parallel_gc_threads=${PARALLEL_GC_THREADS:-4} + xms=${XMS:-1g} xmx=${XMX:-2g} additional_java_opts=${ADDITIONAL_JAVA_OPTS:-""} @@ -346,7 +357,7 @@ if [ "${print_migration_info}" = "true" ]; then info "Find detailed information for migrating to ORS version 8 at: "# TODO info ">>> Config migration <<<" info "Configuring ors with a .json config is deprecated and will be removed in the future." - info "You've the following new methods to configure ORS:" + info "You have the following options to configure ORS:" info "Method 1 yml config:" info "> docker cp ors-container-name:${ORS_HOME}/config/example-ors-config.yml ./ors-config.yml" info "> docker run --name example-ors-instance-conf-file -e ORS_CONFIG_LOCATION=${ORS_HOME}/config/ors-config.yml -v \$(pwd)/ors-config.yml:${ORS_HOME}/config/ors-config.yml heigit/openrouteservice:latest" @@ -365,4 +376,4 @@ debug "Startup command: java ${JAVA_OPTS} ${CATALINA_OPTS} -jar ${jar_file}" # Export ORS_CONFIG_LOCATION to the environment of child processes export ORS_CONFIG_LOCATION=${ors_config_location} # shellcheck disable=SC2086 # we need word splitting here -exec java ${JAVA_OPTS} ${CATALINA_OPTS} -jar "${jar_file}" "$@" \ No newline at end of file +exec java ${JAVA_OPTS} ${CATALINA_OPTS} -jar "${jar_file}" "$@" From 46acc6936019b40a89892aabce12908376402459 Mon Sep 17 00:00:00 2001 From: Amandus Butzer Date: Thu, 15 Feb 2024 15:40:46 +0100 Subject: [PATCH 11/42] docs: adjust link to config parameters --- ors-api/src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ors-api/src/main/resources/application.yml b/ors-api/src/main/resources/application.yml index e1ac7a8f44..831d261efd 100644 --- a/ors-api/src/main/resources/application.yml +++ b/ors-api/src/main/resources/application.yml @@ -1,6 +1,6 @@ ##### openrouteservice settings file ##### # This file contains parameters for openrouteservice. -# For a full list of possible parameters see https://giscience.github.io/openrouteservice/ +# For a full list of possible parameters see https://giscience.github.io/openrouteservice/run-instance/configuration/ ##### General server settings ##### server: From 6a86df291869dd40b7197bad82b6b2c6d3883d36 Mon Sep 17 00:00:00 2001 From: Amandus Butzer Date: Fri, 16 Feb 2024 16:52:45 +0100 Subject: [PATCH 12/42] docs: adjust docker guide --- README.md | 4 ++-- docker-compose.yml | 2 +- docs/run-instance/running-with-docker.md | 23 +++++++++++++++-------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 53056371ee..97121a0b12 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ sed -i='' "s/openrouteservice\/openrouteservice:latest/openrouteservice\/openrou docker compose up -d ``` -For more details, check the [docker installation guide](https://giscience.github.io/openrouteservice/run-instance/installation/running-with-docker). +For more details, check the [docker installation guide](https://giscience.github.io/openrouteservice/run-instance/running-with-docker). For instructions on how to [build from source](https://giscience.github.io/openrouteservice/run-instance/installation/building-from-source) or [configure](https://giscience.github.io/openrouteservice/openrouteservice/run-instance/configuration/), visit our [Installation Instructions](https://giscience.github.io/openrouteservice/openrouteservice/run-instance/installation/). @@ -74,7 +74,7 @@ Openrouteservice offers a set of endpoints for different spatial purposes. By de - `http://localhost:8080/ors/v2/isochrones` - `http://localhost:8080/ors/v2/matrix` -You can find more information in the [Installation Instructions](https://giscience.github.io/openrouteservice/run-instance/installation/running-with-docker). +You can find more information in the [Installation Instructions](https://giscience.github.io/openrouteservice/run-instance/running-with-docker). ## API Documentation diff --git a/docker-compose.yml b/docker-compose.yml index 9894286d76..5e1ea0793d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,5 @@ # Docker Compose file for the openrouteservice (ORS) application -# Documentation and examples can be found on https://giscience.github.io/openrouteservice/run-instance/installation/running-with-docker +# Documentation and examples can be found on https://giscience.github.io/openrouteservice/run-instance/running-with-docker version: '3.8' services: diff --git a/docs/run-instance/running-with-docker.md b/docs/run-instance/running-with-docker.md index e03b2ad6b6..4df887fd82 100644 --- a/docs/run-instance/running-with-docker.md +++ b/docs/run-instance/running-with-docker.md @@ -1,19 +1,24 @@ # Running with Docker -If Docker is available on your system, openrouteservice can be run within a container using prebuilt images from [dockerhub](https://hub.docker.com/r/openrouteservice/openrouteservice) or by building your own image from our source files. +If Docker is available on your system, openrouteservice can be run within a container using prebuilt images +from [dockerhub](https://hub.docker.com/r/openrouteservice/openrouteservice) or by building your own image from the +source files. ## Prerequisites -* [Docker](https://docs.docker.com/get-docker/) should be installed on your system. +- [Docker](https://docs.docker.com/get-docker/) +- an OSM extract, e.g. from [Geofabrik](http://download.geofabrik.de) or for small areas directly export +from [osm.org](https://www.openstreetmap.org/export#map=15/49.4197/8.6893). -## Running prebuilt images +## Docker compose There are multiple ways with Docker to quickly have a running instance. +### Prebuilt image 1. Recommended: Run latest release version image using `docker compose` ```shell - # For latest release build + # For latest build wget https://raw.githubusercontent.com/GIScience/openrouteservice/main/docker-compose.yml docker compose up -d ``` @@ -31,9 +36,11 @@ There are multiple ways with Docker to quickly have a running instance. export ORS_TAG=nightly && docker compose up -d ``` -## Build image +## Build local image -To build your own image, you need to download the source code by following the instructions in chapter [Building from Source](/run-instance/building-from-source.md#download-source-code). You do not have to have Java or Maven installed on your system. +To build your own image, you need to download the source code by following the instructions in chapter +[Building from Source](/run-instance/building-from-source.md#download-source-code). +You do not have to have Java or Maven installed on your system. After downloading the source, you can build your Docker image by running the following command in the source directory: @@ -50,7 +57,7 @@ export ORS_TAG=local && docker compose up -d ::: details Alternative: modify docker compose to build image -After downloading the code, open the file `docker-compose.yml`, remove line 8 and uncomment lines 11-14. +After downloading the code, open the file `docker-compose.yml`, and apply the following changes: ```yaml version: '2.4' @@ -61,7 +68,7 @@ services: - "8080:8080" - "9001:9001" image: openrouteservice/openrouteservice:nightly // [!code --] - # For versioned images see https://giscience.github.io/openrouteservice/run-instance/installation/running-with-docker + # For versioned images see https://giscience.github.io/openrouteservice/run-instance/running-with-docker user: "${UID:-0}:${GID:-0}" # build: // [!code --] # context: ./ // [!code --] From 1421c7d698131bcd620f423e2346bfd13102e2c4 Mon Sep 17 00:00:00 2001 From: Amandus Butzer Date: Tue, 5 Mar 2024 16:07:33 +0100 Subject: [PATCH 13/42] docs: fix port in examples --- docs/run-instance/running-with-docker.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/run-instance/running-with-docker.md b/docs/run-instance/running-with-docker.md index 4df887fd82..87c70ff82d 100644 --- a/docs/run-instance/running-with-docker.md +++ b/docs/run-instance/running-with-docker.md @@ -65,7 +65,7 @@ services: ors-app: container_name: ors-app ports: - - "8080:8080" + - "8080:8082" - "9001:9001" image: openrouteservice/openrouteservice:nightly // [!code --] # For versioned images see https://giscience.github.io/openrouteservice/run-instance/running-with-docker @@ -107,7 +107,7 @@ command. To use a different version of openrouteservice, change the tag (after t mkdir -p docker/conf docker/elevation_cache docker/graphs docker/logs/ors docker/logs/tomcat docker run -dt -u "${UID}:${GID}" \ --name ors-app \ - -p 8080:8080 \ + -p 8080:8082 \ -v $PWD/docker/graphs:/home/ors/ors-core/data/graphs \ -v $PWD/docker/elevation_cache:/home/ors/ors-core/data/elevation_cache \ -v $PWD/docker/logs/ors:/home/ors/ors-core/logs/ors \ From fceeaa710c44fffb9d6265dc8c2920f34872e840 Mon Sep 17 00:00:00 2001 From: Amandus Butzer Date: Tue, 5 Mar 2024 16:08:17 +0100 Subject: [PATCH 14/42] ci: adjust folder paths in docker-build-and-test.yml --- .github/workflows/docker-build-and-test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-build-and-test.yml b/.github/workflows/docker-build-and-test.yml index 2a3508b6ab..6de46968e4 100644 --- a/.github/workflows/docker-build-and-test.yml +++ b/.github/workflows/docker-build-and-test.yml @@ -129,14 +129,14 @@ jobs: # Stop the compose setup and continue with docker run docker compose down # Start the container with the test image and the raw docker run command - docker run -it --user $UID -d -p 8080:8082 -v $(pwd)/graphs:/home/ors/ors-core/data/graphs -v $(pwd)/conf:/home/ors/ors-conf --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }} + docker run -it --user $UID -d -p 8080:8082 -v $(pwd)/graphs:/home/ors/graphs -v $(pwd)/conf:/home/ors/config --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }} # Check for health to turn 200 after the graphs are build and spring-boot completely started ./.github/utils/url_check.sh 127.0.0.1 8080 /ors/v2/health 200 ${{ env.HEALTH_WAIT_TIME }} # Check for correct preflight settings to avoid CORS issues with ORIGIN wildcard from the example config ./.github/utils/cors_check.sh 127.0.0.1 8080 /ors/v2/isochrones/geojson "https://example.org" 200 10 ./.github/utils/cors_check.sh 127.0.0.1 8080 /ors/v2/isochrones/geojson "https://example.com" 200 10 echo "Adjust the config file and set ORIGIN to https://example.org" - sudo yq '.ors.cors.allowed_origins = "https://example.org, https://test.com, http://localhost:8080"' -i ./conf/ors-config.yml + sudo yq '.ors.cors.allowed_origins = "https://example.org, https://test.com, http://localhost:8080"' -i $(pwd)/conf/ors-config.yml # Restart the container to apply the config changes docker restart ors-instance # Request preflight with https://example.com and https://example.org to see if it gets applied correctly @@ -147,7 +147,7 @@ jobs: docker stop ors-instance docker container prune -f chown -R $UID $(pwd)/graphs $(pwd)/conf - docker run -it --user $UID -d -p 8080:8082 -v $(pwd)/graphs:/home/ors/ors-core/data/graphs -v $(pwd)/conf:/home/ors/ors-conf -e ors.cors.allowed_origins=https://example.org --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }} + docker run -it --user $UID -d -p 8080:8082 -v $(pwd)/graphs:/home/ors/graphs -v $(pwd)/conf:/home/ors/config -e ors.cors.allowed_origins=https://example.org --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }} # Request preflight with https://example.com and https://example.org to see if it gets applied correctly ./.github/utils/cors_check.sh 127.0.0.1 8080 /ors/v2/isochrones/geojson "https://example.org" 200 50 # It should fail with http code 403 for https://example.com since the Origin is not covered. From fa5b8221d6faebc37dbb62c687cbed29dcb9ecc9 Mon Sep 17 00:00:00 2001 From: Amandus Butzer Date: Wed, 6 Mar 2024 16:27:11 +0100 Subject: [PATCH 15/42] refactor: change config path in docker as ors is reading the config path from $HOME, this did not work when running ors in a container as root. We moved the config ors is using in the container to the default lookup location '/etc/openrouteservice'. introduces: - copying example config to ors-config.yml if it doesn't exist - not using example-config.yml by default - adjust docker-compose.yml to changes Co-authored-by: Jochen Haeussler --- .github/workflows/docker-build-and-test.yml | 12 ++++---- docker-compose.yml | 7 +++-- docker-entrypoint.sh | 32 +++++++++++++-------- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/.github/workflows/docker-build-and-test.yml b/.github/workflows/docker-build-and-test.yml index 6de46968e4..4f78fec684 100644 --- a/.github/workflows/docker-build-and-test.yml +++ b/.github/workflows/docker-build-and-test.yml @@ -116,8 +116,8 @@ jobs: cache-from: type=gha - name: Start container from previously build image and wait for successful checks run: | - mkdir -p $(pwd)/graphs $(pwd)/conf - chown -R $UID $(pwd)/graphs $(pwd)/conf + mkdir -p $(pwd)/graphs $(pwd)/config + chown -R $UID $(pwd)/graphs $(pwd)/config # Replace image: in the docker-compose.yml with the test image. The value of image: can vary. sed -i "s|image:.*|image: ${{ needs.prepare_environment.outputs.test_image_name }}|" docker-compose.yml # Start the first build with the docker-compose setup @@ -129,14 +129,14 @@ jobs: # Stop the compose setup and continue with docker run docker compose down # Start the container with the test image and the raw docker run command - docker run -it --user $UID -d -p 8080:8082 -v $(pwd)/graphs:/home/ors/graphs -v $(pwd)/conf:/home/ors/config --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }} + docker run -it --user $UID -d -p 8080:8082 -v $(pwd)/graphs:/home/ors/graphs -v $(pwd)/config:/etc/openrouteservice --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }} # Check for health to turn 200 after the graphs are build and spring-boot completely started ./.github/utils/url_check.sh 127.0.0.1 8080 /ors/v2/health 200 ${{ env.HEALTH_WAIT_TIME }} # Check for correct preflight settings to avoid CORS issues with ORIGIN wildcard from the example config ./.github/utils/cors_check.sh 127.0.0.1 8080 /ors/v2/isochrones/geojson "https://example.org" 200 10 ./.github/utils/cors_check.sh 127.0.0.1 8080 /ors/v2/isochrones/geojson "https://example.com" 200 10 echo "Adjust the config file and set ORIGIN to https://example.org" - sudo yq '.ors.cors.allowed_origins = "https://example.org, https://test.com, http://localhost:8080"' -i $(pwd)/conf/ors-config.yml + sudo yq '.ors.cors.allowed_origins = "https://example.org, https://test.com, http://localhost:8080"' -i $(pwd)/config/ors-config.yml # Restart the container to apply the config changes docker restart ors-instance # Request preflight with https://example.com and https://example.org to see if it gets applied correctly @@ -146,8 +146,8 @@ jobs: echo "Recreate the container to test if the graph can be properly read again" docker stop ors-instance docker container prune -f - chown -R $UID $(pwd)/graphs $(pwd)/conf - docker run -it --user $UID -d -p 8080:8082 -v $(pwd)/graphs:/home/ors/graphs -v $(pwd)/conf:/home/ors/config -e ors.cors.allowed_origins=https://example.org --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }} + chown -R $UID $(pwd)/graphs $(pwd)/config + docker run -it --user $UID -d -p 8080:8082 -v $(pwd)/graphs:/home/ors/graphs -v $(pwd)/config:/etc/openrouteservice -e ors.cors.allowed_origins=https://example.org --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }} # Request preflight with https://example.com and https://example.org to see if it gets applied correctly ./.github/utils/cors_check.sh 127.0.0.1 8080 /ors/v2/isochrones/geojson "https://example.org" 200 50 # It should fail with http code 403 for https://example.com since the Origin is not covered. diff --git a/docker-compose.yml b/docker-compose.yml index 5e1ea0793d..6dcdbae844 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,14 +18,15 @@ services: volumes: # Mount relative directories. ONLY for local container runtime. To switch to docker managed volumes see 'Docker Volumes configuration' section below. - ./graphs:/home/ors/graphs # Mount graphs directory - ./elevation_cache:/home/ors/elevation_cache # Mount elevation cache directory - - ./config:/home/ors/config # Mount configuration directory + - ./config:/etc/openrouteservice # Mount configuration directory - ./logs:/home/ors/logs # Mount logs directory - ./files:/home/ors/files # Mount files directory environment: REBUILD_GRAPHS: False # Set to True to rebuild graphs on container start. CONTAINER_LOG_LEVEL: INFO # Log level for the container. Possible values: DEBUG, INFO, WARNING, ERROR, CRITICAL - ORS_CONFIG_LOCATION: /home/ors/config/example-ors-config.yml # Location of the default ORS example configuration file in the docker container - # This config file will be reverted at each container start. If you want to use your own configuration file, create a copy in the container and rename this variable. + # If you don't want the default ors-config.yml you can specify a custom file name, that should match the file in + # your 'config' volume mount. + #ORS_CONFIG_LOCATION: /etc/openrouteservice/my-ors-config.yml # Location of your ORS configuration file in the docker container # ------------------ JAVA OPTS ------------------ # # Configure the memory settings for JAVA or pass additional opts diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index f001c435cc..73bb7fef8f 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -195,9 +195,12 @@ success "BASE_FOLDER: ${BASE_FOLDER} exists and is writable." check_folder_writability "${ORS_HOME}" || critical "ORS_HOME: ${ORS_HOME} doesn't exist or is not writable." success "ORS_HOME: ${ORS_HOME} exists and is writable." -mkdir -p "${ORS_HOME}"/{files,logs,config,graphs,elevation_cache} || warning "Could not create ${ORS_HOME} and folders" -mkdir -p "${BASE_FOLDER}"/{files,logs,config,graphs,elevation_cache} || warning "Could not create ${BASE_FOLDER} and folders" -debug "Populated ORS_HOME=${ORS_HOME} with the default folders: files, logs, config, graphs, elevation_cache" +mkdir -p "${ORS_HOME}"/{files,logs,graphs,elevation_cache} || warning "Could not create ${ORS_HOME} and folders" +mkdir -p "${BASE_FOLDER}"/{files,logs,graphs,elevation_cache} || warning "Could not create ${BASE_FOLDER} and folders" +debug "Populated ORS_HOME=${ORS_HOME} with the default folders: files, logs, graphs, elevation_cache" + +mkdir -p "/etc/openrouteservice" || warning "Could not create /etc/openrouteservice folder" +debug "Created /etc/openrouteservice" # Check if the original jar file exists if [ ! -f "${original_jar_file}" ]; then @@ -224,8 +227,8 @@ else fi # Update the example-ors-config.env and example-ors-config.yml files if they don't exist or have changed -update_file "${ORS_HOME}/config/example-ors-config.env" "/example-ors-config.env" "true" -update_file "${ORS_HOME}/config/example-ors-config.yml" "/example-ors-config.yml" "true" +update_file "/etc/openrouteservice/example-ors-config.env" "/example-ors-config.env" "true" +update_file "/etc/openrouteservice/example-ors-config.yml" "/example-ors-config.yml" "true" # The config situation is difficult due to the recent ors versions. # To ensure a smooth transition, we need to check if the user is using a .json file or a .yml file. @@ -238,10 +241,15 @@ elif [[ "${ors_config_location}" = *.json ]] && [[ -f "${ors_config_location}" ] # Print the above warning message in individual warning calls warning ".json configurations are deprecated and will be removed in the future." print_migration_info="true" +elif [[ -f /etc/openrouteservice/ors-config.yml ]]; then + success "Using existing /etc/openrouteservice/ors-config.yml" + ors_config_location="/etc/openrouteservice/ors-config.yml" else - debug "No implicit config file provided." - success "Default to config: ${ORS_HOME}/config/example-ors-config.yml" - ors_config_location="${ORS_HOME}/config/example-ors-config.yml" + warning "No config file found. Copying /etc/openrouteservice/example-ors-config.yml to /etc/openrouteservice/ors-config.yml" + warning "To adjust your config edit ors-config.yml in your 'config' docker volume or use environment variable configuration." + cp /etc/openrouteservice/example-ors-config.yml /etc/openrouteservice/ors-config.yml +# success "Default to config: /etc/openrouteservice/example-ors-config.yml" + ors_config_location="/etc/openrouteservice/ors-config.yml" fi # Get relevant configuration information from the .yml or .json file @@ -359,11 +367,11 @@ if [ "${print_migration_info}" = "true" ]; then info "Configuring ors with a .json config is deprecated and will be removed in the future." info "You have the following options to configure ORS:" info "Method 1 yml config:" - info "> docker cp ors-container-name:${ORS_HOME}/config/example-ors-config.yml ./ors-config.yml" - info "> docker run --name example-ors-instance-conf-file -e ORS_CONFIG_LOCATION=${ORS_HOME}/config/ors-config.yml -v \$(pwd)/ors-config.yml:${ORS_HOME}/config/ors-config.yml heigit/openrouteservice:latest" + info "> docker cp ors-container-name:/etc/openrouteservice/example-ors-config.yml ./ors-config.yml" + info "> docker run --name example-ors-instance-conf-file -e ORS_CONFIG_LOCATION=/etc/openrouteservice/ors-config.yml -v \$(pwd)/ors-config.yml:/etc/openrouteservice/ors-config.yml openrouteservice/openrouteservice:latest" info "Method 2 environment variables:" - info "> docker cp ors-container-name:${ORS_HOME}/config/example-ors-config.env ./ors-config.env" - info "> docker run --name example-ors-instance-env-file --env-file ors-config.env heigit/openrouteservice:latest" + info "> docker cp ors-container-name:/etc/openrouteservice/example-ors-config.env ./ors-config.env" + info "> docker run --name example-ors-instance-env-file --env-file ors-config.env openrouteservice/openrouteservice:latest" info ">>> End of migration information <<<" fi From 60b4677a2a52eef3220578993d4e06eef544e477 Mon Sep 17 00:00:00 2001 From: Amandus Butzer Date: Wed, 6 Mar 2024 17:19:18 +0100 Subject: [PATCH 16/42] refactor: use example-heidelberg.osm.gz switch to usage of copied file in /home/ors/files instead of root folder Co-authored-by: Julian Psotta Co-authored-by: Jochen Haeussler --- Dockerfile | 4 ++-- docker-entrypoint.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 44a498113e..9165a39428 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,8 +19,8 @@ RUN mvn clean package -DskipTests COPY ./ors-config.yml /tmp/ors/example-ors-config.yml COPY ./ors-config.env /tmp/ors/example-ors-config.env # Rewrite the example config to use the right files in the container -RUN sed -i "/ors.engine.source_file=.*/s/.*/ors.engine.source_file=\/heidelberg.osm.gz/" "/tmp/ors/example-ors-config.env" && \ - sed -i "/ source_file:.*/s/.*/ source_file: \/heidelberg.osm.gz/" "/tmp/ors/example-ors-config.yml" +RUN sed -i "/ors.engine.source_file=.*/s/.*/ors.engine.source_file=\/home\/ors\/files\/example-heidelberg.osm.gz/" "/tmp/ors/example-ors-config.env" && \ + sed -i "/ source_file:.*/s/.*/ source_file: \/home\/ors\/files\/example-heidelberg.osm.gz/" "/tmp/ors/example-ors-config.yml" # build final image, just copying stuff inside FROM docker.io/amazoncorretto:21.0.2-alpine3.19 AS publish diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 73bb7fef8f..a451523c39 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -279,7 +279,7 @@ fi if [ -n "${ors_engine_source_file}" ]; then debug "OSM source file set to ${ors_engine_source_file}" # Check if it is the example file in root or the home folder - if [[ "${ors_engine_source_file}" = "/heidelberg.osm.gz" ]] || [[ "${ors_engine_source_file}" = "${ORS_HOME}/files/example-heidelberg.osm.gz" ]]; then + if [[ "${ors_engine_source_file}" = "${ORS_HOME}/files/example-heidelberg.osm.gz" ]]; then info "Default to example osm source file: \"${ors_engine_source_file}\"" fi fi From 7b67c717fa7502a520eae24c875d7f762548f72b Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Thu, 7 Mar 2024 15:39:25 +0100 Subject: [PATCH 17/42] feat(docker): Change the user example to 1000:1000 The user needs to be 1000:1000 if anything else than 0:0 wants to be chosen. Else the image needs to be rebuild with the correct gid and uid. --- docker-compose.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 6dcdbae844..08c9065739 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,9 @@ services: - "8080:8082" # Expose the ORS API on port 8080 - "9001:9001" # Expose additional port for monitoring (optional) image: openrouteservice/openrouteservice:nightly - #user: "0:0" # Set the user and group to 0 to avoid permission issues. Advanced option! + # The user command useful if you want easier bind mount access or better security. + # Run the following command to create the directory before docker starts with the correct permissions: mkdir -p ors && sudo chown -R 1000:1000 ors + #user: "1000:1000" # Advanced option! volumes: # Mount relative directories. ONLY for local container runtime. To switch to docker managed volumes see 'Docker Volumes configuration' section below. - ./graphs:/home/ors/graphs # Mount graphs directory - ./elevation_cache:/home/ors/elevation_cache # Mount elevation cache directory From dd91ebf78a97e47dd6954ef8e2761f58dc9f0b0b Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Thu, 7 Mar 2024 15:41:28 +0100 Subject: [PATCH 18/42] feat(docker): Adjust the container config path The path will now default to /home/ors/config allowing for easier mounts and a more streamlined way to configure the container. --- docker-compose.yml | 13 +++++++------ docker-entrypoint.sh | 30 +++++++++++++----------------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 08c9065739..d9a56125b8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,17 +18,18 @@ services: # Run the following command to create the directory before docker starts with the correct permissions: mkdir -p ors && sudo chown -R 1000:1000 ors #user: "1000:1000" # Advanced option! volumes: # Mount relative directories. ONLY for local container runtime. To switch to docker managed volumes see 'Docker Volumes configuration' section below. - - ./graphs:/home/ors/graphs # Mount graphs directory - - ./elevation_cache:/home/ors/elevation_cache # Mount elevation cache directory - - ./config:/etc/openrouteservice # Mount configuration directory - - ./logs:/home/ors/logs # Mount logs directory - - ./files:/home/ors/files # Mount files directory + - ./ors:/home/ors # Mount the ORS application directory (for logs, graphs, elevation_cache, etc.) into its own directory + # - ./graphs:/home/ors/graphs # Mount graphs directory + # - ./elevation_cache:/home/ors/elevation_cache # Mount elevation cache directory + # - ./config:/home/ors/config # Mount configuration directory + # - ./logs:/home/ors/logs # Mount logs directory + # - ./files:/home/ors/files # Mount files directory environment: REBUILD_GRAPHS: False # Set to True to rebuild graphs on container start. CONTAINER_LOG_LEVEL: INFO # Log level for the container. Possible values: DEBUG, INFO, WARNING, ERROR, CRITICAL # If you don't want the default ors-config.yml you can specify a custom file name, that should match the file in # your 'config' volume mount. - #ORS_CONFIG_LOCATION: /etc/openrouteservice/my-ors-config.yml # Location of your ORS configuration file in the docker container + #ORS_CONFIG_LOCATION: /home/ors/config/my-ors-config.yml # Location of your ORS configuration file in the docker container # ------------------ JAVA OPTS ------------------ # # Configure the memory settings for JAVA or pass additional opts diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index a451523c39..397f06700b 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -195,13 +195,10 @@ success "BASE_FOLDER: ${BASE_FOLDER} exists and is writable." check_folder_writability "${ORS_HOME}" || critical "ORS_HOME: ${ORS_HOME} doesn't exist or is not writable." success "ORS_HOME: ${ORS_HOME} exists and is writable." -mkdir -p "${ORS_HOME}"/{files,logs,graphs,elevation_cache} || warning "Could not create ${ORS_HOME} and folders" -mkdir -p "${BASE_FOLDER}"/{files,logs,graphs,elevation_cache} || warning "Could not create ${BASE_FOLDER} and folders" +mkdir -p "${ORS_HOME}"/{files,logs,graphs,elevation_cache,config} || warning "Could not create ${ORS_HOME} and folders" +mkdir -p "${BASE_FOLDER}"/{files,logs,graphs,elevation_cache,config} || warning "Could not create ${BASE_FOLDER} and folders" debug "Populated ORS_HOME=${ORS_HOME} with the default folders: files, logs, graphs, elevation_cache" -mkdir -p "/etc/openrouteservice" || warning "Could not create /etc/openrouteservice folder" -debug "Created /etc/openrouteservice" - # Check if the original jar file exists if [ ! -f "${original_jar_file}" ]; then critical "Original Jar file not found. This shouldn't happen. Exiting." @@ -227,8 +224,8 @@ else fi # Update the example-ors-config.env and example-ors-config.yml files if they don't exist or have changed -update_file "/etc/openrouteservice/example-ors-config.env" "/example-ors-config.env" "true" -update_file "/etc/openrouteservice/example-ors-config.yml" "/example-ors-config.yml" "true" +update_file "/home/ors/config/example-ors-config.env" "/example-ors-config.env" "true" +update_file "/home/ors/config/example-ors-config.yml" "/example-ors-config.yml" "true" # The config situation is difficult due to the recent ors versions. # To ensure a smooth transition, we need to check if the user is using a .json file or a .yml file. @@ -241,15 +238,14 @@ elif [[ "${ors_config_location}" = *.json ]] && [[ -f "${ors_config_location}" ] # Print the above warning message in individual warning calls warning ".json configurations are deprecated and will be removed in the future." print_migration_info="true" -elif [[ -f /etc/openrouteservice/ors-config.yml ]]; then - success "Using existing /etc/openrouteservice/ors-config.yml" - ors_config_location="/etc/openrouteservice/ors-config.yml" +elif [[ -f /home/ors/config/ors-config.yml ]]; then + success "Using existing /home/ors/config/ors-config.yml" + ors_config_location="/home/ors/config/ors-config.yml" else - warning "No config file found. Copying /etc/openrouteservice/example-ors-config.yml to /etc/openrouteservice/ors-config.yml" + warning "No config file found. Copying /example-ors-config.yml to /home/ors/config/ors-config.yml" warning "To adjust your config edit ors-config.yml in your 'config' docker volume or use environment variable configuration." - cp /etc/openrouteservice/example-ors-config.yml /etc/openrouteservice/ors-config.yml -# success "Default to config: /etc/openrouteservice/example-ors-config.yml" - ors_config_location="/etc/openrouteservice/ors-config.yml" + update_file "/home/ors/config/ors-config.yml" "/example-ors-config.yml" + ors_config_location="/home/ors/config/ors-config.yml" fi # Get relevant configuration information from the .yml or .json file @@ -367,10 +363,10 @@ if [ "${print_migration_info}" = "true" ]; then info "Configuring ors with a .json config is deprecated and will be removed in the future." info "You have the following options to configure ORS:" info "Method 1 yml config:" - info "> docker cp ors-container-name:/etc/openrouteservice/example-ors-config.yml ./ors-config.yml" - info "> docker run --name example-ors-instance-conf-file -e ORS_CONFIG_LOCATION=/etc/openrouteservice/ors-config.yml -v \$(pwd)/ors-config.yml:/etc/openrouteservice/ors-config.yml openrouteservice/openrouteservice:latest" + info "> docker cp ors-container-name:/home/ors/config/example-ors-config.yml ./ors-config.yml" + info "> docker run --name example-ors-instance-conf-file -e ORS_CONFIG_LOCATION=/home/ors/config/ors-config.yml -v \$(pwd)/ors-config.yml:/home/ors/config/ors-config.yml openrouteservice/openrouteservice:latest" info "Method 2 environment variables:" - info "> docker cp ors-container-name:/etc/openrouteservice/example-ors-config.env ./ors-config.env" + info "> docker cp ors-container-name:/home/ors/config/example-ors-config.env ./ors-config.env" info "> docker run --name example-ors-instance-env-file --env-file ors-config.env openrouteservice/openrouteservice:latest" info ">>> End of migration information <<<" fi From 2967aa5d2552ae917204a3e183d3a2f0c477ca7c Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Thu, 7 Mar 2024 16:10:08 +0100 Subject: [PATCH 19/42] fix(docker): Migrate BASE_FOLDER to ORS_HOME This removes the redundant BASE_FOLDER and replaces a couple of more hard coded paths to ORS_HOME. --- Dockerfile | 14 ++++++------- docker-entrypoint.sh | 48 +++++++++++++++++--------------------------- 2 files changed, 25 insertions(+), 37 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9165a39428..17a03463bd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,7 +29,7 @@ FROM docker.io/amazoncorretto:21.0.2-alpine3.19 AS publish ARG UID=1000 ARG GID=1000 ARG OSM_FILE=./ors-api/src/test/files/heidelberg.osm.gz -ARG BASE_FOLDER=/home/ors +ARG ORS_HOME=/home/ors # Set the default language ENV LANG='en_US' LANGUAGE='en_US' LC_ALL='en_US' @@ -37,11 +37,11 @@ ENV LANG='en_US' LANGUAGE='en_US' LC_ALL='en_US' # Setup the target system with the right user and folders. RUN apk update && apk add --no-cache bash openssl yq jq curl && \ addgroup ors -g ${GID} && \ - mkdir -p ${BASE_FOLDER}/logs ${BASE_FOLDER}/files ${BASE_FOLDER}/graphs ${BASE_FOLDER}/elevation_cache && \ - adduser -D -h ${BASE_FOLDER} -u ${UID} --system -G ors ors && \ - chown ors:ors ${BASE_FOLDER} \ + mkdir -p ${ORS_HOME}/logs ${ORS_HOME}/files ${ORS_HOME}/graphs ${ORS_HOME}/elevation_cache && \ + adduser -D -h ${ORS_HOME} -u ${UID} --system -G ors ors && \ + chown ors:ors ${ORS_HOME} \ # Give all permissions to the user - && chmod -R 777 ${BASE_FOLDER} + && chmod -R 777 ${ORS_HOME} # Copy over the needed bits and pieces from the other stages. COPY --chown=ors:ors --from=build /tmp/ors/ors-api/target/ors.jar /ors.jar @@ -54,8 +54,8 @@ COPY --chown=ors:ors ./docker-entrypoint.sh /entrypoint.sh ENV BUILD_GRAPHS="False" ENV REBUILD_GRAPHS="False" # Set the ARG to an ENV. Else it will be lost. -ENV BASE_FOLDER=${BASE_FOLDER} +ENV ORS_HOME=${ORS_HOME} -WORKDIR ${BASE_FOLDER} +WORKDIR ${ORS_HOME} # Start the container ENTRYPOINT ["/entrypoint.sh"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 397f06700b..a4a6659ce2 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -119,16 +119,6 @@ echo "# Container ENV #" echo "#################" # Validate the log level set_log_level -# Print BASE_FOLDER -success "BASE_FOLDER: ${BASE_FOLDER}" -# Users should define ORS_HOME. If not, use /home/ors -if [ -z "${ORS_HOME}" ]; then - debug "ORS_HOME not explicitly set. Using default: ${BASE_FOLDER}" - ORS_HOME=${BASE_FOLDER} - success "ORS_HOME: ${ORS_HOME}" -else - success "Custom ORS_HOME: ${ORS_HOME}" -fi # Set the jar file location original_jar_file=/ors.jar @@ -180,23 +170,21 @@ if [[ -d /ors-core ]] || [[ -d /ors-conf ]]; then warning "Continuing with the new docker setup." fi -# Fail if BASE_FOLDER env var is not set or if it is empty or set to / -if [ -z "${BASE_FOLDER}" ] || [ "${BASE_FOLDER}" = "/" ]; then - critical "BASE_FOLDER is not set or empty or set to /. This is not allowed. Exiting." -else - debug "BASE_FOLDER=${BASE_FOLDER} is set and not empty and not set to /" +# Fail if ORS_HOME env var is not set or if it is empty or set to / +if [ -z "${ORS_HOME}" ] || [ "${ORS_HOME}" = "/" ]; then + critical "ORS_HOME is not set or empty or set to /. This is not allowed. Exiting." fi mkdir -p "${ORS_HOME}" || critical "Could not create ${ORS_HOME}" -# Make sure BASE_FOLDER and ORS_HOME exist and are writable -check_folder_writability "${BASE_FOLDER}" || critical "BASE_FOLDER: ${BASE_FOLDER} doesn't exist or is not writable." -success "BASE_FOLDER: ${BASE_FOLDER} exists and is writable." +# Make sure ORS_HOME and ORS_HOME exist and are writable +check_folder_writability "${ORS_HOME}" || critical "ORS_HOME: ${ORS_HOME} doesn't exist or is not writable." +success "ORS_HOME: ${ORS_HOME} exists and is writable." check_folder_writability "${ORS_HOME}" || critical "ORS_HOME: ${ORS_HOME} doesn't exist or is not writable." success "ORS_HOME: ${ORS_HOME} exists and is writable." mkdir -p "${ORS_HOME}"/{files,logs,graphs,elevation_cache,config} || warning "Could not create ${ORS_HOME} and folders" -mkdir -p "${BASE_FOLDER}"/{files,logs,graphs,elevation_cache,config} || warning "Could not create ${BASE_FOLDER} and folders" +mkdir -p "${ORS_HOME}"/{files,logs,graphs,elevation_cache,config} || warning "Could not create ${ORS_HOME} and folders" debug "Populated ORS_HOME=${ORS_HOME} with the default folders: files, logs, graphs, elevation_cache" # Check if the original jar file exists @@ -224,8 +212,8 @@ else fi # Update the example-ors-config.env and example-ors-config.yml files if they don't exist or have changed -update_file "/home/ors/config/example-ors-config.env" "/example-ors-config.env" "true" -update_file "/home/ors/config/example-ors-config.yml" "/example-ors-config.yml" "true" +update_file "${ORS_HOME}/config/example-ors-config.env" "/example-ors-config.env" "true" +update_file "${ORS_HOME}/config/example-ors-config.yml" "/example-ors-config.yml" "true" # The config situation is difficult due to the recent ors versions. # To ensure a smooth transition, we need to check if the user is using a .json file or a .yml file. @@ -238,14 +226,14 @@ elif [[ "${ors_config_location}" = *.json ]] && [[ -f "${ors_config_location}" ] # Print the above warning message in individual warning calls warning ".json configurations are deprecated and will be removed in the future." print_migration_info="true" -elif [[ -f /home/ors/config/ors-config.yml ]]; then - success "Using existing /home/ors/config/ors-config.yml" - ors_config_location="/home/ors/config/ors-config.yml" +elif [[ -f ${ORS_HOME}/config/ors-config.yml ]]; then + success "Using existing ${ORS_HOME}/config/ors-config.yml" + ors_config_location="${ORS_HOME}/config/ors-config.yml" else - warning "No config file found. Copying /example-ors-config.yml to /home/ors/config/ors-config.yml" + warning "No config file found. Copying /example-ors-config.yml to ${ORS_HOME}/config/ors-config.yml" warning "To adjust your config edit ors-config.yml in your 'config' docker volume or use environment variable configuration." - update_file "/home/ors/config/ors-config.yml" "/example-ors-config.yml" - ors_config_location="/home/ors/config/ors-config.yml" + update_file "${ORS_HOME}/config/ors-config.yml" "/example-ors-config.yml" + ors_config_location="${ORS_HOME}/config/ors-config.yml" fi # Get relevant configuration information from the .yml or .json file @@ -363,10 +351,10 @@ if [ "${print_migration_info}" = "true" ]; then info "Configuring ors with a .json config is deprecated and will be removed in the future." info "You have the following options to configure ORS:" info "Method 1 yml config:" - info "> docker cp ors-container-name:/home/ors/config/example-ors-config.yml ./ors-config.yml" - info "> docker run --name example-ors-instance-conf-file -e ORS_CONFIG_LOCATION=/home/ors/config/ors-config.yml -v \$(pwd)/ors-config.yml:/home/ors/config/ors-config.yml openrouteservice/openrouteservice:latest" + info "> docker cp ors-container-name:${ORS_HOME}/config/example-ors-config.yml ./ors-config.yml" + info "> docker run --name example-ors-instance-conf-file -e ORS_CONFIG_LOCATION=${ORS_HOME}/config/ors-config.yml -v \$(pwd)/ors-config.yml:${ORS_HOME}/config/ors-config.yml openrouteservice/openrouteservice:latest" info "Method 2 environment variables:" - info "> docker cp ors-container-name:/home/ors/config/example-ors-config.env ./ors-config.env" + info "> docker cp ors-container-name:${ORS_HOME}/config/example-ors-config.env ./ors-config.env" info "> docker run --name example-ors-instance-env-file --env-file ors-config.env openrouteservice/openrouteservice:latest" info ">>> End of migration information <<<" fi From 4c29fc2db9a4d1c18ce7db2d60a1d84d6a042f62 Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Thu, 7 Mar 2024 16:16:05 +0100 Subject: [PATCH 20/42] fix(docker): Remove redundant sanity check --- docker-entrypoint.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index a4a6659ce2..64e4b1dce2 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -180,8 +180,6 @@ mkdir -p "${ORS_HOME}" || critical "Could not create ${ORS_HOME}" # Make sure ORS_HOME and ORS_HOME exist and are writable check_folder_writability "${ORS_HOME}" || critical "ORS_HOME: ${ORS_HOME} doesn't exist or is not writable." success "ORS_HOME: ${ORS_HOME} exists and is writable." -check_folder_writability "${ORS_HOME}" || critical "ORS_HOME: ${ORS_HOME} doesn't exist or is not writable." -success "ORS_HOME: ${ORS_HOME} exists and is writable." mkdir -p "${ORS_HOME}"/{files,logs,graphs,elevation_cache,config} || warning "Could not create ${ORS_HOME} and folders" mkdir -p "${ORS_HOME}"/{files,logs,graphs,elevation_cache,config} || warning "Could not create ${ORS_HOME} and folders" From 701f7ac01c3d7daba75e00406e8b6695f556d758 Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Thu, 7 Mar 2024 16:17:14 +0100 Subject: [PATCH 21/42] fix(docker): Set user id and gid to info --- docker-entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 64e4b1dce2..9d078d2fcb 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -156,7 +156,7 @@ info "Use 'CONTAINER_LOG_LEVEL=DEBUG' to see the full list of active environment echo "###########################" echo "# Container sanity checks #" echo "###########################" -debug "Running container as user $(whoami) with id $(id -u) and group $(id -g)" +info "Running container as user $(whoami) with id $(id -u) and group $(id -g)" if [[ $(id -u) -ne 0 ]] || [[ $(id -g) -ne 0 ]]; then # Test if the user tampered with the user and group settings warning "Running container as user '$(whoami)' with id $(id -u) and group $(id -g)" From fd9fd13815cb4ff9ba9b4dd88c4d11e080411b04 Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Thu, 7 Mar 2024 16:43:18 +0100 Subject: [PATCH 22/42] fix(docker): Make the writeability and existens check explicit It is good to have a more in depth feedback on what goes wrong. --- docker-entrypoint.sh | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 9d078d2fcb..7462e12579 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -68,18 +68,6 @@ function set_log_level() { success "CONTAINER_LOG_LEVEL: ${CONTAINER_LOG_LEVEL}. Set CONTAINER_LOG_LEVEL=DEBUG for more details." } -check_folder_writability() { - local folder="$1" - - if ! touch "${folder}"/.test 2>/dev/null; then - # Echo error with a red x instead of a check - return 1 - else - rm -rf "${folder:?}"/.test - return 0 - fi -} - update_file() { local target_file_path="$1" local original_file_path="$2" @@ -177,8 +165,16 @@ fi mkdir -p "${ORS_HOME}" || critical "Could not create ${ORS_HOME}" -# Make sure ORS_HOME and ORS_HOME exist and are writable -check_folder_writability "${ORS_HOME}" || critical "ORS_HOME: ${ORS_HOME} doesn't exist or is not writable." +# Make sure ORS_HOME is a directory +if [ ! -d "${ORS_HOME}" ]; then + critical "ORS_HOME: ${ORS_HOME} doesn't exist. Exiting." +elif [ ! -w "${ORS_HOME}" ]; then + error "ORS_HOME: ${ORS_HOME} is not writable." + error "Make sure the file permission of ${ORS_HOME} in your volume mount are set to $(id -u):$(id -g)." + error "Under linux the command for a volume would be: sudo chown -R $(id -u):$(id -g) /path/to/ors/volume" + critical "Exiting." +fi + success "ORS_HOME: ${ORS_HOME} exists and is writable." mkdir -p "${ORS_HOME}"/{files,logs,graphs,elevation_cache,config} || warning "Could not create ${ORS_HOME} and folders" From d6d910f97ae39c9207d10e639954371fed4386e5 Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Thu, 7 Mar 2024 16:44:47 +0100 Subject: [PATCH 23/42] fix(docker): Explain the user option a bit clearer and add 1000:1000 to the checks --- docker-compose.yml | 5 +++-- docker-entrypoint.sh | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index d9a56125b8..88ce93b925 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,9 +14,10 @@ services: - "8080:8082" # Expose the ORS API on port 8080 - "9001:9001" # Expose additional port for monitoring (optional) image: openrouteservice/openrouteservice:nightly - # The user command useful if you want easier bind mount access or better security. + # Advanced option! If you different ids to 0:0 and 1000:1000, you have to rebuild the container with the build args UID,GID. # Run the following command to create the directory before docker starts with the correct permissions: mkdir -p ors && sudo chown -R 1000:1000 ors - #user: "1000:1000" # Advanced option! + # The user command is useful if you want easier bind mount access or better security. + #user: "1000:1000" volumes: # Mount relative directories. ONLY for local container runtime. To switch to docker managed volumes see 'Docker Volumes configuration' section below. - ./ors:/home/ors # Mount the ORS application directory (for logs, graphs, elevation_cache, etc.) into its own directory # - ./graphs:/home/ors/graphs # Mount graphs directory diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 7462e12579..52ddfa962f 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -145,11 +145,16 @@ echo "###########################" echo "# Container sanity checks #" echo "###########################" info "Running container as user $(whoami) with id $(id -u) and group $(id -g)" -if [[ $(id -u) -ne 0 ]] || [[ $(id -g) -ne 0 ]]; then +if [[ $(id -u) -eq 0 ]] || [[ $(id -g) -eq 0 ]] ; then + debug "User and group are set to root with id 0 and group 0." +elif [[ $(id -u) -eq 1000 ]] || [[ $(id -g) -eq 1000 ]] ; then + debug "User and group are set to 1000 and group 1000." +else # Test if the user tampered with the user and group settings warning "Running container as user '$(whoami)' with id $(id -u) and group $(id -g)" warning "Changing these values is only recommended if you're an advanced docker user and can handle file permission issues yourself." warning "Consider leaving the user and group options as root with 0:0 or 1000:1000 or avoid that setting completely." + warning "If you need to change the user and group, make sure to rebuild the docker image with the appropriate UID,GID build args." fi if [[ -d /ors-core ]] || [[ -d /ors-conf ]]; then From c94294c8b134453b0120febb33f813a9b297b82b Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Thu, 7 Mar 2024 16:45:25 +0100 Subject: [PATCH 24/42] fix(docker): Fix the indentation and add the individually explanation --- docker-compose.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 88ce93b925..f1b2e4c68e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,11 +20,11 @@ services: #user: "1000:1000" volumes: # Mount relative directories. ONLY for local container runtime. To switch to docker managed volumes see 'Docker Volumes configuration' section below. - ./ors:/home/ors # Mount the ORS application directory (for logs, graphs, elevation_cache, etc.) into its own directory - # - ./graphs:/home/ors/graphs # Mount graphs directory - # - ./elevation_cache:/home/ors/elevation_cache # Mount elevation cache directory - # - ./config:/home/ors/config # Mount configuration directory - # - ./logs:/home/ors/logs # Mount logs directory - # - ./files:/home/ors/files # Mount files directory + #- ./graphs:/home/ors/graphs # Mount graphs directory individually + #- ./elevation_cache:/home/ors/elevation_cache # Mount elevation cache directory individually + #- ./config:/home/ors/config # Mount configuration directory individually + #- ./logs:/home/ors/logs # Mount logs directory individually + #- ./files:/home/ors/files # Mount files directory individually environment: REBUILD_GRAPHS: False # Set to True to rebuild graphs on container start. CONTAINER_LOG_LEVEL: INFO # Log level for the container. Possible values: DEBUG, INFO, WARNING, ERROR, CRITICAL From 4376c1243885007fc7015ab6c9bfc8a8470dff37 Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Thu, 7 Mar 2024 16:53:43 +0100 Subject: [PATCH 25/42] fix(docker): Migrate to the default jar location This avoids users mounting and accidentally fiddling with the jar file. --- docker-entrypoint.sh | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 52ddfa962f..5e6ed1b686 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -109,7 +109,7 @@ echo "#################" set_log_level # Set the jar file location -original_jar_file=/ors.jar +jar_file=/ors.jar BUILD_GRAPHS=${BUILD_GRAPHS:-"false"} REBUILD_GRAPHS=${REBUILD_GRAPHS:-"false"} # If BUILD_GRAPHS is set to true, we need to set ors_rebuild_graphs to true and print an info about migration to REBUILD_GRAPHS @@ -187,12 +187,8 @@ mkdir -p "${ORS_HOME}"/{files,logs,graphs,elevation_cache,config} || warning "Co debug "Populated ORS_HOME=${ORS_HOME} with the default folders: files, logs, graphs, elevation_cache" # Check if the original jar file exists -if [ ! -f "${original_jar_file}" ]; then - critical "Original Jar file not found. This shouldn't happen. Exiting." -else - success "Update ors.jar at ${ORS_HOME}/ors.jar" - cp -f "${original_jar_file}" "${ORS_HOME}/ors.jar" || warning "Could not copy ${original_jar_file} to ${ORS_HOME}/ors.jar" - jar_file="${ORS_HOME}/ors.jar" +if [ ! -f "${jar_file}" ]; then + critical "Jar file not found. This shouldn't happen. Exiting." fi From d80dc6df713be2bb6a7db1b103f1a8ad35ecc74b Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Thu, 7 Mar 2024 16:54:01 +0100 Subject: [PATCH 26/42] fix(docker): Add another even clearer explanation --- docker-compose.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index f1b2e4c68e..2ae88fbba5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,9 +15,8 @@ services: - "9001:9001" # Expose additional port for monitoring (optional) image: openrouteservice/openrouteservice:nightly # Advanced option! If you different ids to 0:0 and 1000:1000, you have to rebuild the container with the build args UID,GID. - # Run the following command to create the directory before docker starts with the correct permissions: mkdir -p ors && sudo chown -R 1000:1000 ors # The user command is useful if you want easier bind mount access or better security. - #user: "1000:1000" + #user: "1000:1000" # Run "mkdir -p ors && sudo chown -R 1000:1000 ors" before starting the container! volumes: # Mount relative directories. ONLY for local container runtime. To switch to docker managed volumes see 'Docker Volumes configuration' section below. - ./ors:/home/ors # Mount the ORS application directory (for logs, graphs, elevation_cache, etc.) into its own directory #- ./graphs:/home/ors/graphs # Mount graphs directory individually From dd84f38fbd11705b1613106b09608890d6b933f0 Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Thu, 7 Mar 2024 16:59:30 +0100 Subject: [PATCH 27/42] fix(docker): Fix port for healthcheck --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 2ae88fbba5..b9bec420d3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -65,7 +65,7 @@ services: # Be careful with long graph builds, as the healthcheck will fail and show 'unhealthy' during this time. # This is especially useful if you run your ORS container in a production environment. #healthcheck: - # test: curl --fail http://localhost:8080/ors/v2/health || exit 1 + # test: curl --fail http://localhost:8082/ors/v2/health || exit 1 # start_period: 1m # interval: 10s # timeout: 2s From e0b7c036adabb387ee884efa44197fa9706828f6 Mon Sep 17 00:00:00 2001 From: Jochen Haeussler Date: Thu, 7 Mar 2024 17:00:09 +0100 Subject: [PATCH 28/42] chore: added new docker directory to ignore files --- .dockerignore | 1 + .gitignore | 1 + 2 files changed, 2 insertions(+) diff --git a/.dockerignore b/.dockerignore index 7bc9742d68..d928e85bfa 100644 --- a/.dockerignore +++ b/.dockerignore @@ -25,6 +25,7 @@ ors-api/logs ors-api/target/ ors-engine/target/ +ors-docker/** cgiar_provider/ cgiar_cache/ diff --git a/.gitignore b/.gitignore index 1e8a7b6d48..5867765681 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ node_modules/ # Ignore all ors-config files except for the sample one, useful for development and testing ors-api/src/main/resources/ors-config* ors-config* +ors-docker/** envs/ ors-config-repo/ From 324e7098b38ea734743b050e41248ac8c96a099e Mon Sep 17 00:00:00 2001 From: Jochen Haeussler Date: Thu, 7 Mar 2024 17:02:24 +0100 Subject: [PATCH 29/42] feat: changed volume name --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index b9bec420d3..09b569a258 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,7 +18,7 @@ services: # The user command is useful if you want easier bind mount access or better security. #user: "1000:1000" # Run "mkdir -p ors && sudo chown -R 1000:1000 ors" before starting the container! volumes: # Mount relative directories. ONLY for local container runtime. To switch to docker managed volumes see 'Docker Volumes configuration' section below. - - ./ors:/home/ors # Mount the ORS application directory (for logs, graphs, elevation_cache, etc.) into its own directory + - ./ors-docker:/home/ors # Mount the ORS application directory (for logs, graphs, elevation_cache, etc.) into its own directory #- ./graphs:/home/ors/graphs # Mount graphs directory individually #- ./elevation_cache:/home/ors/elevation_cache # Mount elevation cache directory individually #- ./config:/home/ors/config # Mount configuration directory individually From 7230d0fbce1cf1c98ff53e5f9b1699e3319304d0 Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Thu, 7 Mar 2024 18:16:56 +0100 Subject: [PATCH 30/42] fix(workflow): Fix the wrong config volume mapping for the test workflow --- .github/workflows/docker-build-and-test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-build-and-test.yml b/.github/workflows/docker-build-and-test.yml index 4f78fec684..34f41ada60 100644 --- a/.github/workflows/docker-build-and-test.yml +++ b/.github/workflows/docker-build-and-test.yml @@ -129,7 +129,7 @@ jobs: # Stop the compose setup and continue with docker run docker compose down # Start the container with the test image and the raw docker run command - docker run -it --user $UID -d -p 8080:8082 -v $(pwd)/graphs:/home/ors/graphs -v $(pwd)/config:/etc/openrouteservice --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }} + docker run -it --user $UID -d -p 8080:8082 -v $(pwd)/graphs:/home/ors/graphs -v $(pwd)/config:/home/ors/config --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }} # Check for health to turn 200 after the graphs are build and spring-boot completely started ./.github/utils/url_check.sh 127.0.0.1 8080 /ors/v2/health 200 ${{ env.HEALTH_WAIT_TIME }} # Check for correct preflight settings to avoid CORS issues with ORIGIN wildcard from the example config @@ -147,7 +147,7 @@ jobs: docker stop ors-instance docker container prune -f chown -R $UID $(pwd)/graphs $(pwd)/config - docker run -it --user $UID -d -p 8080:8082 -v $(pwd)/graphs:/home/ors/graphs -v $(pwd)/config:/etc/openrouteservice -e ors.cors.allowed_origins=https://example.org --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }} + docker run -it --user $UID -d -p 8080:8082 -v $(pwd)/graphs:/home/ors/graphs -v $(pwd)/config:/home/ors/config -e ors.cors.allowed_origins=https://example.org --name ors-instance ${{ needs.prepare_environment.outputs.test_image_name }} # Request preflight with https://example.com and https://example.org to see if it gets applied correctly ./.github/utils/cors_check.sh 127.0.0.1 8080 /ors/v2/isochrones/geojson "https://example.org" 200 50 # It should fail with http code 403 for https://example.com since the Origin is not covered. From 73531c408994e489ca7ef416b3248c74cc0c5e2b Mon Sep 17 00:00:00 2001 From: Jochen Haeussler Date: Fri, 8 Mar 2024 13:11:25 +0100 Subject: [PATCH 31/42] feat: evaluating ORS_TAG in docker compose --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 09b569a258..cc29696ebe 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,7 +13,7 @@ services: ports: - "8080:8082" # Expose the ORS API on port 8080 - "9001:9001" # Expose additional port for monitoring (optional) - image: openrouteservice/openrouteservice:nightly + image: openrouteservice/openrouteservice:${ORS_TAG:-v8} # Advanced option! If you different ids to 0:0 and 1000:1000, you have to rebuild the container with the build args UID,GID. # The user command is useful if you want easier bind mount access or better security. #user: "1000:1000" # Run "mkdir -p ors && sudo chown -R 1000:1000 ors" before starting the container! From 40f992e22449ac87d055ac8011977226808c1d8e Mon Sep 17 00:00:00 2001 From: Jochen Haeussler Date: Fri, 8 Mar 2024 13:18:19 +0100 Subject: [PATCH 32/42] feat: add docker compose file to release artifacts --- .github/workflows/release-artifacts.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release-artifacts.yml b/.github/workflows/release-artifacts.yml index 860f0e52c0..18fa228dc8 100644 --- a/.github/workflows/release-artifacts.yml +++ b/.github/workflows/release-artifacts.yml @@ -41,4 +41,5 @@ jobs: ./ors.jar ./ors.war ./ors-config.yml - ./ors-config.env \ No newline at end of file + ./ors-config.env + ./docker-compose.yml \ No newline at end of file From 04bbc6aa313212b28a3fd88dd8aa828c0c81fdc5 Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Fri, 8 Mar 2024 14:39:02 +0100 Subject: [PATCH 33/42] fix(docker-compose): Adjust the image tag to local/openrouteservice:latest This ensures that users that checkout the compose from main will either fail or if it was cloned with the repo will have the latest repo stage build as their docker image. The image line is adjusted in the release action so that the release artifacts compose files will always point to their subsequent image version on docker hub. --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index cc29696ebe..ea2315ae2b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,7 +13,7 @@ services: ports: - "8080:8082" # Expose the ORS API on port 8080 - "9001:9001" # Expose additional port for monitoring (optional) - image: openrouteservice/openrouteservice:${ORS_TAG:-v8} + image: local/openrouteservice:latest # Advanced option! If you different ids to 0:0 and 1000:1000, you have to rebuild the container with the build args UID,GID. # The user command is useful if you want easier bind mount access or better security. #user: "1000:1000" # Run "mkdir -p ors && sudo chown -R 1000:1000 ors" before starting the container! From 5ae46519766c757dce2393fb64e105dbb41e3e3b Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Fri, 8 Mar 2024 14:54:44 +0100 Subject: [PATCH 34/42] ci(release): Merge the new artifact release with the docker image artifact release --- .github/workflows/publish-tagged-release.yml | 63 ++++++++++++++++---- .github/workflows/release-artifacts.yml | 45 -------------- 2 files changed, 50 insertions(+), 58 deletions(-) delete mode 100644 .github/workflows/release-artifacts.yml diff --git a/.github/workflows/publish-tagged-release.yml b/.github/workflows/publish-tagged-release.yml index 594f37e740..db73fe1d05 100644 --- a/.github/workflows/publish-tagged-release.yml +++ b/.github/workflows/publish-tagged-release.yml @@ -20,14 +20,9 @@ jobs: id: buildx with: install: true - - name: 'Get Previous tag' - id: previoustag - uses: "WyriHaximus/github-action-get-previous-tag@v1" - - name: 'Get next minor version' - id: semvers - uses: "WyriHaximus/github-action-next-semvers@v1" - with: - version: ${{ steps.previoustag.outputs.tag }} + - name: Get the release tag + id: get_tag + run: echo ::set-output name=tag::${{ github.event.release.tag_name }} - name: Prepare id: prepare run: | @@ -42,13 +37,11 @@ jobs: DOCKER_IMAGE=openrouteservice/openrouteservice CURRENT_VERSIONS=$(test_version) - LATEST_IMAGE_VERSION=${{ steps.previoustag.outputs.tag }} - HIGHEST_IMAGE_VERSION=${{ steps.semvers.outputs.v_mayor }} + LATEST_IMAGE_VERSION=${{ steps.get_tag.outputs.tag }} DOCKER_PLATFORMS=linux/amd64,linux/arm64 BUILD_VERSION=true TAGS_LATEST_VERSION="${DOCKER_IMAGE}:${LATEST_IMAGE_VERSION}" - TAGS_HIGHEST_VERSION="${DOCKER_IMAGE}:${HIGHEST_IMAGE_VERSION}" echo "HIGHEST MAYOR VERSION: $TAGS_HIGHEST_VERSION" TAGS_LATEST="${DOCKER_IMAGE}:latest" @@ -60,7 +53,7 @@ jobs: echo ::set-output name=build_version::${BUILD_VERSION} echo ::set-output name=build_platforms::${DOCKER_PLATFORMS} - echo ::set-output name=buildx_tags_version::${TAGS_LATEST_VERSION} + echo ::set-output name=buildx_tags_version::${TAGS_LATEST_VERSION} echo ::set-output name=buildx_tags_latest::${TAGS_LATEST} - name: Login to DockerHub if: ${{ steps.prepare.outputs.build_version == 'true' }} @@ -72,7 +65,7 @@ jobs: if: ${{ steps.prepare.outputs.build_version == 'true' }} uses: actions/checkout@v4 with: - ref: ${{ steps.previoustag.outputs.tag }} + ref: ${{ steps.get_tag.outputs.tag }} - name: Build and publish version if needed if: ${{ steps.prepare.outputs.build_version == 'true' }} uses: docker/build-push-action@v4 @@ -83,3 +76,47 @@ jobs: platforms: ${{ steps.prepare.outputs.build_platforms }} cache-from: type=gha cache-to: type=gha,mode=max + build_and_publish_release_artifacts: + runs-on: ubuntu-latest + needs: build_and_publish_docker + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '17' + cache: 'maven' + cache-dependency-path: ./pom.xml + - name: Build JAR + run: | + mvn clean package -DskipTests + # Copy the JAR to the root directory + cp ors-api/target/ors.jar ors.jar + - name: Build WAR + run: | + mvn clean package -DskipTests -PbuildWar + # Copy the WAR to the root directory + cp ors-api/target/ors.war ors.war + - name: Get the release tag + id: get_tag + run: echo ::set-output name=tag::${{ github.event.release.tag_name }} + - name: Rewrite the docker-compose.yml image tag to the release tag + if: startsWith(github.ref, 'refs/tags/') + run: | + # Replace the image part + sed -i "s/local\/openrouteservice:latest/openrouteservice\/openrouteservice:${{ steps.get_tag.outputs.tag }}/g" docker-compose.yml + - name: Attach the files to the release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + token: ${{ secrets.GITHUB_TOKEN }} + files: | + ./ors.jar + ./ors.war + ./ors-config.yml + ./ors-config.env + ./docker-compose.yml \ No newline at end of file diff --git a/.github/workflows/release-artifacts.yml b/.github/workflows/release-artifacts.yml deleted file mode 100644 index 18fa228dc8..0000000000 --- a/.github/workflows/release-artifacts.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Build the release artifacts and attach them to the release - -on: - release: - types: [ created ] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: '17' - cache: 'maven' - cache-dependency-path: ./pom.xml - - name: Build JAR - run: | - mvn clean package -DskipTests - # Copy the JAR to the root directory - cp ors-api/target/ors.jar ors.jar - - - name: Build WAR - run: | - mvn clean package -DskipTests -PbuildWar - # Copy the WAR to the root directory - cp ors-api/target/ors.war ors.war - - - name: Attach the files to the release - uses: softprops/action-gh-release@v1 - if: startsWith(github.ref, 'refs/tags/') - with: - token: ${{ secrets.GITHUB_TOKEN }} - files: | - ./ors.jar - ./ors.war - ./ors-config.yml - ./ors-config.env - ./docker-compose.yml \ No newline at end of file From 92a58edcea4c2c4d747ca3bf66e3786a5c8e2615 Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Fri, 8 Mar 2024 15:10:24 +0100 Subject: [PATCH 35/42] fix(mvn): Add -q at some places to reduce verbosity of maven --- .github/workflows/publish-tagged-release.yml | 4 ++-- Dockerfile | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish-tagged-release.yml b/.github/workflows/publish-tagged-release.yml index db73fe1d05..ef5255abb3 100644 --- a/.github/workflows/publish-tagged-release.yml +++ b/.github/workflows/publish-tagged-release.yml @@ -93,12 +93,12 @@ jobs: cache-dependency-path: ./pom.xml - name: Build JAR run: | - mvn clean package -DskipTests + mvn -q clean package -DskipTests # Copy the JAR to the root directory cp ors-api/target/ors.jar ors.jar - name: Build WAR run: | - mvn clean package -DskipTests -PbuildWar + mvn -q clean package -DskipTests -PbuildWar # Copy the WAR to the root directory cp ors-api/target/ors.war ors.war - name: Get the release tag diff --git a/Dockerfile b/Dockerfile index 17a03463bd..6b79fc51e6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ COPY pom.xml /tmp/ors/pom.xml COPY ors-report-aggregation /tmp/ors/ors-report-aggregation # Build the project -RUN mvn clean package -DskipTests +RUN mvn -q clean package -DskipTests # Copy the example config files to the build folder COPY ./ors-config.yml /tmp/ors/example-ors-config.yml From f607efffe27cdf6c685a5e577446b41d05256902 Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Wed, 13 Mar 2024 15:07:52 +0100 Subject: [PATCH 36/42] chore: Remove dev dependencies Curl and openssl are not needed for the final image. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6b79fc51e6..e86603730c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,7 +35,7 @@ ARG ORS_HOME=/home/ors ENV LANG='en_US' LANGUAGE='en_US' LC_ALL='en_US' # Setup the target system with the right user and folders. -RUN apk update && apk add --no-cache bash openssl yq jq curl && \ +RUN apk update && apk add --no-cache bash yq jq && \ addgroup ors -g ${GID} && \ mkdir -p ${ORS_HOME}/logs ${ORS_HOME}/files ${ORS_HOME}/graphs ${ORS_HOME}/elevation_cache && \ adduser -D -h ${ORS_HOME} -u ${UID} --system -G ors ors && \ From 7d6c76363b1879225ed3157c586bb1a4106d40fb Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Wed, 13 Mar 2024 15:11:36 +0100 Subject: [PATCH 37/42] fix: Remove redundant mkdir and adjust the log messages --- docker-entrypoint.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 5e6ed1b686..220c68cbde 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -182,9 +182,8 @@ fi success "ORS_HOME: ${ORS_HOME} exists and is writable." -mkdir -p "${ORS_HOME}"/{files,logs,graphs,elevation_cache,config} || warning "Could not create ${ORS_HOME} and folders" -mkdir -p "${ORS_HOME}"/{files,logs,graphs,elevation_cache,config} || warning "Could not create ${ORS_HOME} and folders" -debug "Populated ORS_HOME=${ORS_HOME} with the default folders: files, logs, graphs, elevation_cache" +mkdir -p "${ORS_HOME}"/{files,logs,graphs,elevation_cache,config} || warning "Could not create the default folders in ${ORS_HOME}: files, logs, graphs, elevation_cache, config" +debug "Populated ORS_HOME=${ORS_HOME} with the default folders: files, logs, graphs, elevation_cache, config" # Check if the original jar file exists if [ ! -f "${jar_file}" ]; then From f762dffecfc8f7717ee0db03199529d1db572217 Mon Sep 17 00:00:00 2001 From: Jochen Haeussler Date: Wed, 13 Mar 2024 17:12:21 +0100 Subject: [PATCH 38/42] refactor: review finding: change to nested if blocks --- docker-entrypoint.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 220c68cbde..2a25bf5b1b 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -231,20 +231,20 @@ else fi # Get relevant configuration information from the .yml or .json file -if [[ -z "${ors_engine_graphs_root_path}" ]] && [[ "${config_location}" = *.yml ]]; then - ors_engine_graphs_root_path=$(extract_config_info "${ors_config_location}" '.ors.engine.graphs_root_path') -fi - -if [[ -z "${ors_engine_graphs_root_path}" ]] && [[ "${config_location}" = *.json ]]; then - ors_engine_graphs_root_path=$(extract_config_info "${ors_config_location}" '.ors.services.routing.profiles.default_params.graphs_root_path') -fi - -if [[ -z "${ors_engine_source_file}" ]] && [[ "${ors_config_location}" = *.yml ]]; then - ors_engine_source_file=$(extract_config_info "${ors_config_location}" '.ors.engine.source_file') +if [[ -z "${ors_engine_graphs_root_path}" ]]; then + if [[ "${config_location}" = *.yml ]]; then + ors_engine_graphs_root_path=$(extract_config_info "${ors_config_location}" '.ors.engine.graphs_root_path') + elif [[ "${config_location}" = *.json ]]; then + ors_engine_graphs_root_path=$(extract_config_info "${ors_config_location}" '.ors.services.routing.profiles.default_params.graphs_root_path') + fi fi -if [[ -z "${ors_engine_source_file}" ]] && [[ "${ors_config_location}" = *.json ]]; then - ors_engine_source_file=$(extract_config_info "${ors_config_location}" '.ors.services.routing.sources[0]') +if [[ -z "${ors_engine_source_file}" ]]; then + if [[ "${ors_config_location}" = *.yml ]]; then + ors_engine_source_file=$(extract_config_info "${ors_config_location}" '.ors.engine.source_file') + elif [[ "${ors_config_location}" = *.json ]]; then + ors_engine_source_file=$(extract_config_info "${ors_config_location}" '.ors.services.routing.sources[0]') + fi fi if [ -n "${ors_engine_graphs_root_path}" ]; then From 72885d670d60bcf2065ac90351cb289a2e6ba21d Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Wed, 13 Mar 2024 18:30:38 +0100 Subject: [PATCH 39/42] fix(dockerfile): Move the config env setting further down and adjust the config loading messages The enhanced messages ensure that the user knows that a config is either read by ENV or as a fallback when existing in the config folder. --- docker-entrypoint.sh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 2a25bf5b1b..41fddb3d67 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -130,10 +130,7 @@ ors_engine_graphs_root_path=$(env | grep "^ors\.engine\.graphs_root_path=" | awk ors_engine_elevation_cache_path=$(env | grep "^ors\.engine\.elevation\.cache_path=" | awk -F '=' '{print $2}') # get ors.engine.source_file ors_engine_source_file=$(env | grep "^ors\.engine\.source_file=" | awk -F '=' '{print $2}') -# get ors_config_location -ors_config_location=${ORS_CONFIG_LOCATION:-""} -# Unset the ORS_CONFIG_LOCATION to not interfere with the spring-boot application -unset ORS_CONFIG_LOCATION + # Parse the ors.* properties env | while read -r line; do debug "${line}" @@ -212,20 +209,24 @@ update_file "${ORS_HOME}/config/example-ors-config.yml" "/example-ors-config.yml # The config situation is difficult due to the recent ors versions. # To ensure a smooth transition, we need to check if the user is using a .json file or a .yml file. # If neither is set, we need to print a migration info and default to the example-ors-config.env file. +# get ors_config_location +ors_config_location=${ORS_CONFIG_LOCATION:-""} +# Unset the ORS_CONFIG_LOCATION to not interfere with the spring-boot application +unset ORS_CONFIG_LOCATION # Check if ors_config_location is a .json file and exists if [[ "${ors_config_location}" = *.yml ]] && [[ -f "${ors_config_location}" ]]; then - success "Using yml config: ${ors_config_location}" + success "Using yml config from ENV: ${ors_config_location}" elif [[ "${ors_config_location}" = *.json ]] && [[ -f "${ors_config_location}" ]]; then - success "Using json config: ${ors_config_location}" + success "Using json config from ENV: ${ors_config_location}" # Print the above warning message in individual warning calls warning ".json configurations are deprecated and will be removed in the future." print_migration_info="true" elif [[ -f ${ORS_HOME}/config/ors-config.yml ]]; then - success "Using existing ${ORS_HOME}/config/ors-config.yml" + success "Using the existing ors-config.yml from: ${ORS_HOME}/config/ors-config.yml" ors_config_location="${ORS_HOME}/config/ors-config.yml" else warning "No config file found. Copying /example-ors-config.yml to ${ORS_HOME}/config/ors-config.yml" - warning "To adjust your config edit ors-config.yml in your 'config' docker volume or use environment variable configuration." + warning "To adjust your config edit ors-config.yml in your 'config' docker volume or use the environment variable configuration." update_file "${ORS_HOME}/config/ors-config.yml" "/example-ors-config.yml" ors_config_location="${ORS_HOME}/config/ors-config.yml" fi From 648f9bbf67dda9d3c7e459c02e59ae92def54297 Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Wed, 13 Mar 2024 18:31:06 +0100 Subject: [PATCH 40/42] fix(dockerfile): Add curl again Curl is necessary for the health check in the docker-compose.yml --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e86603730c..19c26fa3f0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,7 +35,7 @@ ARG ORS_HOME=/home/ors ENV LANG='en_US' LANGUAGE='en_US' LC_ALL='en_US' # Setup the target system with the right user and folders. -RUN apk update && apk add --no-cache bash yq jq && \ +RUN apk update && apk add --no-cache bash yq jq curl && \ addgroup ors -g ${GID} && \ mkdir -p ${ORS_HOME}/logs ${ORS_HOME}/files ${ORS_HOME}/graphs ${ORS_HOME}/elevation_cache && \ adduser -D -h ${ORS_HOME} -u ${UID} --system -G ors ors && \ From f64384677138f6c6f70e3f1447e3ab179e8179df Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Wed, 13 Mar 2024 18:35:33 +0100 Subject: [PATCH 41/42] fix(dockerfile): Replace curl with wget Wget is provided by default and can also be used for the health check. One dependency less :). --- Dockerfile | 2 +- docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 19c26fa3f0..e86603730c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,7 +35,7 @@ ARG ORS_HOME=/home/ors ENV LANG='en_US' LANGUAGE='en_US' LC_ALL='en_US' # Setup the target system with the right user and folders. -RUN apk update && apk add --no-cache bash yq jq curl && \ +RUN apk update && apk add --no-cache bash yq jq && \ addgroup ors -g ${GID} && \ mkdir -p ${ORS_HOME}/logs ${ORS_HOME}/files ${ORS_HOME}/graphs ${ORS_HOME}/elevation_cache && \ adduser -D -h ${ORS_HOME} -u ${UID} --system -G ors ors && \ diff --git a/docker-compose.yml b/docker-compose.yml index ea2315ae2b..c2c3936b5e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -65,7 +65,7 @@ services: # Be careful with long graph builds, as the healthcheck will fail and show 'unhealthy' during this time. # This is especially useful if you run your ORS container in a production environment. #healthcheck: - # test: curl --fail http://localhost:8082/ors/v2/health || exit 1 + # test: wget --no-verbose --tries=1 --spider http://localhost:8082/ors/v2/health || exit 1 # start_period: 1m # interval: 10s # timeout: 2s From c5a92e972b311f9e493d0f8a9c1c232fb46e24d7 Mon Sep 17 00:00:00 2001 From: Julian Psotta Date: Thu, 14 Mar 2024 11:39:20 +0100 Subject: [PATCH 42/42] fix(dockerfile): Move the config parsing closer to its first usage --- docker-entrypoint.sh | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 41fddb3d67..f74fb5397b 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -123,14 +123,6 @@ else ors_rebuild_graphs="false" fi - -# get ors.engine.graphs_root_path=. Dot notations in bash are not allowed, so we need to use awk to parse it. -ors_engine_graphs_root_path=$(env | grep "^ors\.engine\.graphs_root_path=" | awk -F '=' '{print $2}') -# get ors.engine.elevation.cache_path -ors_engine_elevation_cache_path=$(env | grep "^ors\.engine\.elevation\.cache_path=" | awk -F '=' '{print $2}') -# get ors.engine.source_file -ors_engine_source_file=$(env | grep "^ors\.engine\.source_file=" | awk -F '=' '{print $2}') - # Parse the ors.* properties env | while read -r line; do debug "${line}" @@ -187,6 +179,12 @@ if [ ! -f "${jar_file}" ]; then critical "Jar file not found. This shouldn't happen. Exiting." fi +# get ors.engine.graphs_root_path=. Dot notations in bash are not allowed, so we need to use awk to parse it. +ors_engine_graphs_root_path=$(env | grep "^ors\.engine\.graphs_root_path=" | awk -F '=' '{print $2}') +# get ors.engine.elevation.cache_path +ors_engine_elevation_cache_path=$(env | grep "^ors\.engine\.elevation\.cache_path=" | awk -F '=' '{print $2}') +# get ors.engine.source_file +ors_engine_source_file=$(env | grep "^ors\.engine\.source_file=" | awk -F '=' '{print $2}') # Check that ors_engine_graphs_root_path is not empty and not set to / if [ -n "${ors_engine_graphs_root_path}" ] && [ "${ors_engine_graphs_root_path}" = "/" ]; then