Skip to content

Commit

Permalink
[FIX] Enable graph setup to run on stack restart (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
surchs authored May 16, 2024
1 parent f7715a2 commit 089f3cd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
8 changes: 5 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ services:
- "local_node_query"
- "full_stack"
volumes:
- "${NB_GRAPH_ROOT_HOST:-~/graphdb-home}:${NB_GRAPH_ROOT_CONT:-/opt/graphdb/home}"
- "graphdb_home:/opt/graphdb/home"
- "./scripts:/usr/src/neurobagel/scripts"
- ".env:/usr/src/neurobagel/.env"
- "./vocab:/usr/src/neurobagel/vocab"
- "${LOCAL_GRAPH_DATA:-./data}:/data"
ports:
- "${NB_GRAPH_PORT_HOST:-7200}:${NB_GRAPH_PORT:-7200}"
environment:
NB_GRAPH_ROOT_CONT: ${NB_GRAPH_ROOT_CONT:-/opt/graphdb/home}
NB_GRAPH_USERNAME: ${NB_GRAPH_USERNAME}
NB_GRAPH_ADDRESS: ${NB_GRAPH_ADDRESS:-graph}
NB_GRAPH_PORT: ${NB_GRAPH_PORT:-7200}
Expand Down Expand Up @@ -89,4 +88,7 @@ secrets:
db_admin_password:
environment: "NB_GRAPH_ADMIN_PASSWORD"
db_user_password:
environment: "NB_GRAPH_PASSWORD"
environment: "NB_GRAPH_PASSWORD"

volumes:
graphdb_home:
2 changes: 0 additions & 2 deletions docs/neurobagel_environment_variables.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ Environment variable Set manually in .env? Description Default value if not set
`NB_FAPI_PORT` No Port number on which to run the Neurobagel federation API _in the API container_ `8000` Docker
`NB_GRAPH_IMG` No Graph server Docker image `ontotext/graphdb:10.3.1` Docker
`NB_GRAPH_ADDRESS` No IP address for the graph database (or container name, if graph is hosted locally) `206.12.99.17 (graph)` ** Docker, Python
`NB_GRAPH_ROOT_HOST` No Path to directory on the _host machine_ to store graph database files and data (directory does not have to exist beforehand). `~/graphdb-home` Docker
`NB_GRAPH_ROOT_CONT` No Path to directory for graph databases in the _graph server container_ `/opt/graphdb/home` * Docker
`NB_GRAPH_PORT_HOST` No Port number on the _host machine_ to map the graph server container port to `7200` Docker
`NB_GRAPH_PORT` No Port number used by the _graph server container_ `7200` * Docker, Python
`NB_QUERY_TAG` No Docker image tag for the query tool `latest` Docker
Expand Down
33 changes: 24 additions & 9 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
#!/bin/bash

/opt/graphdb/dist/bin/graphdb -Dgraphdb.home=${NB_GRAPH_ROOT_CONT} &
/opt/graphdb/dist/bin/graphdb -Dgraphdb.home=/opt/graphdb/home &
GRAPHDB_PID=$!

# TODO revisit/test this also once we document how users can change (in addition to the data files being uploaded) the variables to set up a non-tester database after a first-time deployment
export NB_GRAPH_ADMIN_PASSWORD=$(cat /run/secrets/db_admin_password)
export NB_GRAPH_PASSWORD=$(cat /run/secrets/db_user_password)

# Waiting for GraphDB to start
while ! curl --silent "localhost:${NB_GRAPH_PORT}/rest/repositories" | grep '\[\]'; do
while ! curl --silent "localhost:${NB_GRAPH_PORT}/rest/repositories" -u "${NB_GRAPH_USERNAME}:${NB_GRAPH_PASSWORD}" | grep '\['; do
:
done

# We need to figure out if this is the first time the setup has been run
repo_response=$(curl --silent "localhost:${NB_GRAPH_PORT}/rest/repositories" -u "${NB_GRAPH_USERNAME}:${NB_GRAPH_PASSWORD}")
if [ "${repo_response}" = "[]" ]; then
export FIRST_TIME_SETUP="on"
else
export FIRST_TIME_SETUP="off"
fi

echo "First time setup: ${FIRST_TIME_SETUP}"

# TODO: Do we also want to use this elsewhere in the script or stick to ./<some_path>?
SCRIPT_DIR=$(dirname "$0")
mkdir -p ${SCRIPT_DIR}/logs

export NB_GRAPH_ADMIN_PASSWORD=$(cat /run/secrets/db_admin_password)
export NB_GRAPH_PASSWORD=$(cat /run/secrets/db_user_password)

# Logic for main setup
main() {
echo "Setting up a Neurobagel graph backend..."
echo -e "(The GraphDB server is being accessed inside the GraphDB container at http://localhost:${NB_GRAPH_PORT}.)\n"

echo "Setting up GraphDB server..."
./graphdb_setup.sh --env-file-path /usr/src/neurobagel/.env "${NB_GRAPH_ADMIN_PASSWORD}"
echo "Finished server setup."
if [ "${FIRST_TIME_SETUP}" = "on" ]; then
echo "Setting up GraphDB server..."
./graphdb_setup.sh --env-file-path /usr/src/neurobagel/.env "${NB_GRAPH_ADMIN_PASSWORD}"
echo "Finished server setup."export FIRST_TIME_SETUP="on"
else
echo "GraphDB server already set up, skipping setup."
fi

echo "Adding datasets to the database..."
./add_data_to_graph.sh /data localhost:${NB_GRAPH_PORT} ${NB_GRAPH_DB} "${NB_GRAPH_USERNAME}" "${NB_GRAPH_PASSWORD}"
./add_data_to_graph.sh /data localhost:${NB_GRAPH_PORT} ${NB_GRAPH_DB} "${NB_GRAPH_USERNAME}" "${NB_GRAPH_PASSWORD}" --clear-data
echo "Finished adding datasets to databases."

echo "Adding Neurobagel vocabulary to the database"
Expand Down

0 comments on commit 089f3cd

Please sign in to comment.