diff --git a/.env b/.env index 27e03ceb4c6e4dc59dd8dd297bc915fd6abb97e6..2294ac345cfc8861a76654354b57cd7b1e1e4ce3 100644 --- a/.env +++ b/.env @@ -3,7 +3,7 @@ NEO4J_PORT=7687 NEO4J_PROTOCOL=bolt NEO4J_HOST=neo NEO4J_USER=neo4j -NEO4J_PW=neo4j +NEO4J_PW=W7uFSy$y=wR3M3ck DB_PW=FooBar DB_HOST=db DB_NAME=discussion diff --git a/docker-compose.yml b/docker-compose.yml index 239166099b752302ebe063d0055a5500fbcb0d09..595e1d0ef12c65f4e8e1f4aa5ed9f079e8760f6f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,19 +2,17 @@ version: "3.2" services: neo: - image: neo4j + build: neo4j ports: - "7474:7474" - "7687:7687" volumes: - - ./neo4j/plugins:/plugins - - ./neo4j/entrypoint:/var/lib/neo4j/data/graph.db - - # Todo: Add command to seed the database while the container is starting - # Important: The Files of the Volume are stored in /data/graph.db - + - ./neo4j/plugins:/var/lib/neo4j/plugins + - ./neo4j/entrypoint:/var/lib/neo4j/entrypoint environment: - NEO4J_AUTH: none + NEO4J_USERNAME: $NEO4J_USER + NEO4J_PASSWORD: $NEO4J_PW + NEO4J_AUTH: $NEO4J_USER/$NEO4J_PW NEO4J_dbms_security_procedures_unrestricted: algo.* api: diff --git a/neo4j/Dockerfile b/neo4j/Dockerfile old mode 100644 new mode 100755 index 37bff43483d8b591916bef3be142e2bc7dd5cdf4..5fa07a672599f5b728a3b1b7224d03293826ed38 --- a/neo4j/Dockerfile +++ b/neo4j/Dockerfile @@ -1,3 +1,9 @@ FROM neo4j:3.5.0 +MAINTAINER marc.feger@uni-duesseldorf.de + +RUN apk add --no-cache curl jq + COPY . . + +CMD /var/lib/neo4j/entrypoint/entrypoint.sh \ No newline at end of file diff --git a/neo4j/entrypoint/entrypoint.sh b/neo4j/entrypoint/entrypoint.sh index dc7fa141c67ffa7d0b2b545082548a27330511b6..b2f5b676f092eb6a0659e2c999e256be602a0837 100755 --- a/neo4j/entrypoint/entrypoint.sh +++ b/neo4j/entrypoint/entrypoint.sh @@ -1,11 +1,56 @@ #!/usr/bin/env bash +: ' + This script changes the default password of the default user. Then the database is loaded and initialized. +' -echo "Start waiting for Database to be ready ..." +set -e -end="$((SECONDS+60))" -while true; do - nc -w 2 localhost 7687 && break - [[ "${SECONDS}" -ge "${end}" ]] && exit 1 - sleep 1 -done -cypher-shell --fail-fast --debug --format verbose < /data/graph.db/neo4j-entrypoint.cql +function wait_for_port() { + : ' + This function waits 60 seconds to determine whether a port on a host has been opened and activated on a host. + The function receives as parameters the host and the port to be checked. + ' + echo "$(date "+%Y-%m-%d %T") INFO": "Start waiting for container to open port $2 at $1..." + end="$((SECONDS+60))" + while true; do + nc -w 2 $1 $2 && break + [[ "${SECONDS}" -ge "${end}" ]] && exit 1 + sleep 1 + done + echo "$(date "+%Y-%m-%d %T") INFO": "Port $2 is up and running after ${SECONDS} seconds at $1..." +} + +function wait_for_neo { + : ' + This function waits for the Neo4J server to start on port 7687 and the Neo4J browser to start on port 7474. + Then the default password of the user "neo4j" will be changed. + This password is then the new and valid password. The password is changed via the HTTP REST API provided by Neo4J. + Then the database is initialized. + ' + + wait_for_port localhost 7687 + wait_for_port localhost 7474 + + echo "$(date "+%Y-%m-%d %T") INFO": "Change the default authentication of ${NEO4J_USERNAME}..." + : ' + Attention. Since this script only overwrites the password of the default user when loading the Neo4j container, + the name of the default user for the default password is used as the second argument. + Therefore, the default user name should still be used. + ' + bash /var/lib/neo4j/entrypoint/hide_default_password.sh ${NEO4J_USERNAME} ${NEO4J_USERNAME} ${NEO4J_PASSWORD} 2>/dev/null + + echo "$(date "+%Y-%m-%d %T") INFO": "Inject data to database..." + : ' + This section loads the basic discussion graphs. + ' + bin/cypher-shell --fail-fast --debug --format verbose -u ${NEO4J_USERNAME} -p ${NEO4J_PASSWORD} < /var/lib/neo4j/entrypoint/neo4j-entrypoint.cql + echo "$(date "+%Y-%m-%d %T") INFO": "-> Everything is up and running ..." + +} + +# Start to wait +wait_for_neo & + +# Start the entrypoint for neo4j +# Todo: Solve -> WARN Unknown config option +/sbin/tini -g -s -- /docker-entrypoint.sh neo4j diff --git a/neo4j/entrypoint/hide_default_password.sh b/neo4j/entrypoint/hide_default_password.sh new file mode 100755 index 0000000000000000000000000000000000000000..0f567a715e4ab8a642b2ebf9572a72e02db901f6 --- /dev/null +++ b/neo4j/entrypoint/hide_default_password.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash + +: ' + USER: + This variable contains the name of the user whose initial password is to be changed. + Attention: At the beginning the user and the password are set to "neo4j" by default. + If the default user is still used, a new password should be created for this user. +' +USER=$1 +if [[ -z ${USER} ]]; +then + echo "$(date "+%Y-%m-%d %T") ERROR": "-> The variable USER is not set!" 1>&2 + exit 1 +fi + +: ' + OLD_PASSWORD: + This variable contains initial password which is to be changed. + Attention: At the beginning the user and the password are set to "neo4j" by default. + If the default user is still used, a new password should be created for this user. +' + +OLD_PASSWORD=$2 +if [[ -z ${OLD_PASSWORD} ]]; +then + echo "$(date "+%Y-%m-%d %T") ERROR": "-> The variable OLD_PASSWORD is not set!" 1>&2 + exit 1 +fi + +: ' + NEW_PASSWORD: + This variable contains the new password. +' +NEW_PASSWORD=$3 +if [[ -z ${NEW_PASSWORD} ]]; +then + echo "$(date "+%Y-%m-%d %T") ERROR": "-> The variable NEW_PASSWORD is not set!" 1>&2 + exit 1 +fi + +: ' + This variable contains the response of the Neo4J server to a specific user. +' +USER_STATUS=$(curl -u ${USER}:${OLD_PASSWORD} http://localhost:7474/user/${USER} 2>/dev/null) + +: ' + This variable stores the status of whether the password needs to be changed. + Since only the default password has to be changed at the beginning, the field "password_change_required" + is set and true or false. If a non-existent user or password is requested, + the field "password_change_required" is null. + Then jq does not enter the variable PASSWORD_CHANGE_IS_REQUIRED. + The value of PASSWORD_CHANGE_IS_REQUIRED is then empty. +' +PASSWORD_CHANGE_IS_REQUIRED=$(echo ${USER_STATUS} | jq -r '.password_change_required // empty') #Todo: Explain empty + +if [[ ${PASSWORD_CHANGE_IS_REQUIRED} = true ]]; +then + echo "$(date "+%Y-%m-%d %T") INFO": "-> Call HTTP REST API with ${USER}:${OLD_PASSWORD} ..." + # The new password is set here + curl -H "Content-Type: application/json" \ + -d '{"password":"'"${NEW_PASSWORD}"'"}' \ + -u ${USER}:${OLD_PASSWORD} \ + http://localhost:7474/user/${USER}/password + echo "$(date "+%Y-%m-%d %T") INFO": "--> Done." +else + echo "$(date "+%Y-%m-%d %T") INFO": "-> Password for ${USER} is already set ..." +fi \ No newline at end of file diff --git a/neo4j/plugins/apoc-3.5.0.1-all.jar b/neo4j/plugins/apoc-3.5.0.1-all.jar old mode 100644 new mode 100755 diff --git a/neo4j/plugins/graph-algorithms-algo-3.5.3.0.jar b/neo4j/plugins/graph-algorithms-algo-3.5.3.0.jar old mode 100644 new mode 100755 diff --git a/neo4j/plugins/postgresql-42.2.5.jar b/neo4j/plugins/postgresql-42.2.5.jar old mode 100644 new mode 100755