forked from ITISFoundation/osparc-ops-environments
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull docker-stack-config.bash from github.com/ITISFoundation/osparc-s…
- Loading branch information
kaiser
committed
Apr 2, 2024
1 parent
12fad4e
commit 91a0794
Showing
21 changed files
with
155 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/bin/bash | ||
# generated using chatgpt | ||
show_info() { | ||
local message="$1" | ||
echo -e "\e[37mInfo:\e[0m $message" >&2 | ||
} | ||
|
||
show_warning() { | ||
local message="$1" | ||
echo -e "\e[31mWarning:\e[0m $message" >&2 | ||
} | ||
|
||
show_error() { | ||
local message="$1" | ||
echo -e "\e[31mError:\e[0m $message" >&2 | ||
} | ||
|
||
env_file=".env" | ||
# Parse command line arguments | ||
while getopts ":e:" opt; do | ||
case $opt in | ||
e) | ||
env_file="$OPTARG" | ||
;; | ||
\?) | ||
show_error "Invalid option: -$OPTARG" | ||
exit 1 | ||
;; | ||
:) | ||
show_error "Option -$OPTARG requires an argument." | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
shift $((OPTIND - 1)) | ||
|
||
if [[ "$#" -eq 0 ]]; then | ||
show_error "No compose files specified!" | ||
exit 1 | ||
fi | ||
|
||
# Check if Docker version is greater than or equal to 25.0.3 | ||
version_check=$(docker --version | grep --extended-regexp --only-matching '[0-9]+\.[0-9]+\.[0-9]+') | ||
IFS='.' read -r -a version_parts <<<"$version_check" | ||
|
||
if [[ "${version_parts[0]}" -gt 25 ]] || | ||
{ [[ "${version_parts[0]}" -eq 25 ]] && [[ "${version_parts[1]}" -gt 0 ]]; } || | ||
{ [[ "${version_parts[0]}" -eq 25 ]] && [[ "${version_parts[1]}" -eq 0 ]] && [[ "${version_parts[2]}" -ge 3 ]]; }; then | ||
show_info "Running Docker version $version_check" | ||
else | ||
show_error "Docker version 25.0.3 or higher is required." | ||
exit 1 | ||
fi | ||
|
||
# shellcheck disable=SC2002 | ||
docker_command="\ | ||
set -o allexport && \ | ||
. ${env_file} && set +o allexport && \ | ||
docker stack config" | ||
|
||
for compose_file_path in "$@"; do | ||
docker_command+=" --compose-file ${compose_file_path}" | ||
done | ||
|
||
# mitigates https://stackoverflow.com/questions/40619582/how-can-i-escape-a-dollar-sign-in-a-docker-compose-file | ||
docker_command+="| sed 's/\\\$/\\\$\\\$/g'" | ||
|
||
# WE CANNOT DO THIS: | ||
# docker_command+=" --skip-interpolation" | ||
# because docker stack compose will *validate* that e.g. `replicas: ${SIMCORE_SERVICES_POSTGRES_REPLICAS}` is a valid number, which it is not if it is read as a literal string. | ||
|
||
# Execute the command | ||
show_info "Executing Docker command: ${docker_command}" | ||
eval "${docker_command}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.