- 
                Notifications
    You must be signed in to change notification settings 
- Fork 7
Simple deployment script #392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
c4ccf96
              d5c2aa5
              16a777f
              e920ce6
              13ca3a4
              3a3d34c
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #!/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 | ||
| } | ||
|  | ||
| # 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; } | ||
|  | ||
| # 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" | ||
|         
                  Tristan-WorkGH marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
|  | ||
| 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" | ||
|  | ||
| # 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 | ||
| cd docker-compose/explicit-profiles || { echo "Failed to change directory. Check if the path is correct. Exiting."; exit 1; } | ||
| docker compose --profile suite up -d || { echo "Docker Compose failed to start. Check Docker setup. Exiting."; exit 1; } | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We prefer to pass the profile name in a parameter to start and stop | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We at first decided to not do scripts like this because there is in day-to-day too much cases to support and we don't want to have to maintain these scripts. I will ask our TL. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
 | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +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 suite stop || { echo "Docker Compose failed to stop. Exiting."; exit 1; } | 
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't support a "DATABASES" env var, we define directly "GRIDSUITE_DATABASES" in our env (
.bashrcfor example).It's up to users to decide how they manage it in their environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here it creates default folder DATABASES, it is not an ENV variable, the ENV variable is still "GRIDSUITE_DATABASES". One could add check, if it is already defined, then it will not be set again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we prefer to create GRIDSUITE_DATABASES env only if it does not exist