From c4ccf964edb4e88d60dbebc68948dedf131147a4 Mon Sep 17 00:00:00 2001 From: Haigutus Date: Tue, 20 Feb 2024 10:14:53 +0200 Subject: [PATCH 1/6] Create setup.sh 1. Creates database folder and its structure 2. Download sample conf files 3. Run docker compose --- setup.sh | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 setup.sh diff --git a/setup.sh b/setup.sh new file mode 100644 index 00000000..5eefe9ee --- /dev/null +++ b/setup.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# Function to download a file if it does not exist +download_file() { + local url=$1 + local target_path=$2 + + # Check if the file already exists to avoid re-downloading + if [ ! -f "$target_path" ]; then + echo "Downloading $(basename "$target_path")..." + curl -s -L "$url" -o "$target_path" || { echo "Failed to download $(basename "$target_path"). Exiting."; exit 1; } + else + echo "$(basename "$target_path") already exists. Skipping download." + fi +} + +# Check if ENV exists or if new given in commandline parameter, if not, ask user for a path (relative or absolute) +if [ -z "$1" ] && [ -n "$GRIDSUITE_DATABASES" ]; then + echo "Using GRIDSUITE_DATABASES from environment: $GRIDSUITE_DATABASES" +else + if [ -n "$1" ]; then + # Convert to absolute path and create path structure + GRIDSUITE_DATABASES=$(realpath "$1") + export GRIDSUITE_DATABASES + else + if [ -z "$GRIDSUITE_DATABASES" ]; then + echo "Enter the root directory location for GRIDSUITE_DATABASES:" + read USER_INPUT + GRIDSUITE_DATABASES=$(realpath "$USER_INPUT") + export GRIDSUITE_DATABASES + fi + fi +fi + +if [ -z "$GRIDSUITE_DATABASES" ]; then + echo "GRIDSUITE_DATABASES is not set. Exiting." + exit 1 +fi + +# Create the subdirectories with the required file mode +mkdir -p "$GRIDSUITE_DATABASES/cases" "$GRIDSUITE_DATABASES/postgres" "$GRIDSUITE_DATABASES/elasticsearch" "$GRIDSUITE_DATABASES/init" || { echo "Failed to create directories. Exiting."; exit 1; } + +# Change the file mode to 777 for all subdirectories +chmod 777 "$GRIDSUITE_DATABASES/cases" "$GRIDSUITE_DATABASES/postgres" "$GRIDSUITE_DATABASES/elasticsearch" "$GRIDSUITE_DATABASES/init" || { echo "Failed to set permissions. Exiting."; exit 1; } + +echo "Folder structure created under $GRIDSUITE_DATABASES with required permissions." + +# Populate init folder +download_file "https://raw.githubusercontent.com/gridsuite/geo-data/main/src/test/resources/geo_data_substations.json" "$GRIDSUITE_DATABASES/init/geo_data_substations.json" +download_file "https://raw.githubusercontent.com/gridsuite/geo-data/main/src/test/resources/geo_data_lines.json" "$GRIDSUITE_DATABASES/init/geo_data_lines.json" +download_file "https://raw.githubusercontent.com/gridsuite/cgmes-boundary-server/main/src/test/resources/business_processes.json" "$GRIDSUITE_DATABASES/init/business_processes.json" +download_file "https://raw.githubusercontent.com/gridsuite/cgmes-boundary-server/main/src/test/resources/tsos.json" "$GRIDSUITE_DATABASES/init/tsos.json" + +echo "Configuration files downloaded." + +# Assuming the Docker Compose file is relative to the script's execution path +cd docker-compose/explicit-profiles || { echo "Failed to change directory. Check if the path is correct. Exiting."; exit 1; } +docker compose --profile study up -d || { echo "Docker Compose failed to start. Check Docker setup. Exiting."; exit 1; } From d5c2aa5b372f8ef88ca392793c83c0530061f6b3 Mon Sep 17 00:00:00 2001 From: Haigutus Date: Tue, 20 Feb 2024 11:39:10 +0200 Subject: [PATCH 2/6] - Removed dynamic database path setting. - Added IP replacement. --- setup.sh | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/setup.sh b/setup.sh index 5eefe9ee..f4f21d98 100644 --- a/setup.sh +++ b/setup.sh @@ -14,28 +14,9 @@ download_file() { fi } -# Check if ENV exists or if new given in commandline parameter, if not, ask user for a path (relative or absolute) -if [ -z "$1" ] && [ -n "$GRIDSUITE_DATABASES" ]; then - echo "Using GRIDSUITE_DATABASES from environment: $GRIDSUITE_DATABASES" -else - if [ -n "$1" ]; then - # Convert to absolute path and create path structure - GRIDSUITE_DATABASES=$(realpath "$1") - export GRIDSUITE_DATABASES - else - if [ -z "$GRIDSUITE_DATABASES" ]; then - echo "Enter the root directory location for GRIDSUITE_DATABASES:" - read USER_INPUT - GRIDSUITE_DATABASES=$(realpath "$USER_INPUT") - export GRIDSUITE_DATABASES - fi - fi -fi - -if [ -z "$GRIDSUITE_DATABASES" ]; then - echo "GRIDSUITE_DATABASES is not set. Exiting." - exit 1 -fi +# Set databases path +GRIDSUITE_DATABASES=$(realpath "DATABASES") +export GRIDSUITE_DATABASES # Create the subdirectories with the required file mode mkdir -p "$GRIDSUITE_DATABASES/cases" "$GRIDSUITE_DATABASES/postgres" "$GRIDSUITE_DATABASES/elasticsearch" "$GRIDSUITE_DATABASES/init" || { echo "Failed to create directories. Exiting."; exit 1; } @@ -53,6 +34,23 @@ download_file "https://raw.githubusercontent.com/gridsuite/cgmes-boundary-server echo "Configuration files downloaded." +# Update IP +# Capture the first IP address into a variable +target_ip=$(hostname -I | awk '{print $1}') + +# Use the variable as needed +echo "The target IP address is: $target_ip" + +# Loop through all files in the directory +for file in "docker-compose/explicit-profiles"/*; do + # Check if file exists to avoid errors with sed command when no files match + if [ -f "$file" ]; then + # Use sed to replace 'localhost' and '172.17.0.1' with 'target_ip' in-place + sed -i "s/localhost/$target_ip/g" "$file" + sed -i "s/172.17.0.1/$target_ip/g" "$file" + fi +done + # Assuming the Docker Compose file is relative to the script's execution path cd docker-compose/explicit-profiles || { echo "Failed to change directory. Check if the path is correct. Exiting."; exit 1; } docker compose --profile study up -d || { echo "Docker Compose failed to start. Check Docker setup. Exiting."; exit 1; } From 16a777f2587c76c8c862729896774b4de4eebfa9 Mon Sep 17 00:00:00 2001 From: Haigutus Date: Tue, 20 Feb 2024 11:47:37 +0200 Subject: [PATCH 3/6] fixed path for ip update --- setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index f4f21d98..4cffefcf 100644 --- a/setup.sh +++ b/setup.sh @@ -42,7 +42,7 @@ target_ip=$(hostname -I | awk '{print $1}') echo "The target IP address is: $target_ip" # Loop through all files in the directory -for file in "docker-compose/explicit-profiles"/*; do +for file in "docker-compose"/*; do # Check if file exists to avoid errors with sed command when no files match if [ -f "$file" ]; then # Use sed to replace 'localhost' and '172.17.0.1' with 'target_ip' in-place From e920ce63075714d385fc8238e0b2a7cf884582f5 Mon Sep 17 00:00:00 2001 From: Haigutus Date: Tue, 20 Feb 2024 11:58:56 +0200 Subject: [PATCH 4/6] Replace IP in folders. Added stop.sh --- setup.sh | 13 +++++-------- stop.sh | 3 +++ 2 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 stop.sh diff --git a/setup.sh b/setup.sh index 4cffefcf..627260b9 100644 --- a/setup.sh +++ b/setup.sh @@ -41,14 +41,11 @@ target_ip=$(hostname -I | awk '{print $1}') # Use the variable as needed echo "The target IP address is: $target_ip" -# Loop through all files in the directory -for file in "docker-compose"/*; do - # Check if file exists to avoid errors with sed command when no files match - if [ -f "$file" ]; then - # Use sed to replace 'localhost' and '172.17.0.1' with 'target_ip' in-place - sed -i "s/localhost/$target_ip/g" "$file" - sed -i "s/172.17.0.1/$target_ip/g" "$file" - fi +# Find all files in the directory and its subdirectories +find "docker-compose" -type f | while read -r file; do + # Use sed to replace 'localhost' and '172.17.0.1' with 'target_ip' in-place + sed -i "s/localhost/$target_ip/g" "$file" + sed -i "s/172.17.0.1/$target_ip/g" "$file" done # Assuming the Docker Compose file is relative to the script's execution path diff --git a/stop.sh b/stop.sh new file mode 100644 index 00000000..84efe3fc --- /dev/null +++ b/stop.sh @@ -0,0 +1,3 @@ +# Assuming the Docker Compose file is relative to the script's execution path +cd docker-compose/explicit-profiles || { echo "Failed to change directory. Check if the path is correct. Exiting."; exit 1; } +docker compose --profile study stop || { echo "Docker Compose failed to stop. Exiting."; exit 1; } \ No newline at end of file From 13ca3a4bceea9de084d4a02e2aca016fa61546ce Mon Sep 17 00:00:00 2001 From: Haigutus Date: Tue, 20 Feb 2024 12:49:40 +0200 Subject: [PATCH 5/6] switched to suite --- setup.sh | 2 +- stop.sh | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/setup.sh b/setup.sh index 627260b9..94838f20 100644 --- a/setup.sh +++ b/setup.sh @@ -50,4 +50,4 @@ done # Assuming the Docker Compose file is relative to the script's execution path cd docker-compose/explicit-profiles || { echo "Failed to change directory. Check if the path is correct. Exiting."; exit 1; } -docker compose --profile study up -d || { echo "Docker Compose failed to start. Check Docker setup. Exiting."; exit 1; } +docker compose --profile suite up -d || { echo "Docker Compose failed to start. Check Docker setup. Exiting."; exit 1; } diff --git a/stop.sh b/stop.sh index 84efe3fc..4543e3f8 100644 --- a/stop.sh +++ b/stop.sh @@ -1,3 +1,9 @@ +#!/bin/bash + +# Set databases path +GRIDSUITE_DATABASES=$(realpath "DATABASES") +export GRIDSUITE_DATABASES + # Assuming the Docker Compose file is relative to the script's execution path cd docker-compose/explicit-profiles || { echo "Failed to change directory. Check if the path is correct. Exiting."; exit 1; } -docker compose --profile study stop || { echo "Docker Compose failed to stop. Exiting."; exit 1; } \ No newline at end of file +docker compose --profile suite stop || { echo "Docker Compose failed to stop. Exiting."; exit 1; } \ No newline at end of file From 3a3d34cf343fc65568e4e4d458d312ac9d7fb42b Mon Sep 17 00:00:00 2001 From: Haigutus Date: Wed, 20 Mar 2024 08:37:44 +0200 Subject: [PATCH 6/6] Update docker-compose.technical.yml Kibana and Grafana to listen external traffic --- docker-compose/technical/docker-compose.technical.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docker-compose/technical/docker-compose.technical.yml b/docker-compose/technical/docker-compose.technical.yml index fb13455f..002d03e4 100644 --- a/docker-compose/technical/docker-compose.technical.yml +++ b/docker-compose/technical/docker-compose.technical.yml @@ -68,6 +68,8 @@ services: - 5601:5601 environment: - LOGSPOUT=ignore + - SERVER_HOST=0.0.0.0 + - SERVER_PORT=5601 depends_on: - elasticsearch restart: unless-stopped @@ -138,5 +140,7 @@ services: - GF_AUTH_DISABLE_LOGIN_FORM=true - GF_ANALYTICS_REPORTING_ENABLED=false - GF_ANALYTICS_CHECK_FOR_UPDATES=false + - HTTP_PORT=3000 + - HTTP_ADDR=0.0.0.0 ports: - "7000:3000"