Skip to content

Commit

Permalink
Pull docker-stack-config.bash from github.com/ITISFoundation/osparc-s…
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiser committed Apr 2, 2024
1 parent 12fad4e commit 91a0794
Show file tree
Hide file tree
Showing 21 changed files with 155 additions and 167 deletions.
2 changes: 1 addition & 1 deletion scripts/deployments/compose_stack_yml.bash
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ cp .env ..
cp ../../docker-compose.yml ./docker-compose.simcore.yml

unset EC2_INSTANCES_ALLOWED_TYPES
"$repo_basedir"/scripts/docker-compose-config.bash -e .env docker-compose.simcore.yml docker-compose.deploy.yml > ../../stack.yml
"$repo_basedir"/scripts/docker-stack-config.bash -e .env docker-compose.simcore.yml docker-compose.deploy.yml > ../../stack.yml
#
#
### Cleanup
Expand Down
2 changes: 1 addition & 1 deletion scripts/deployments/start_simcore_locally.bash
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ else

$_yq "del(.services.traefik)" "$osparcsimcoredeveldir"/services/docker-compose.local.yml > "$repo_basedir"/"$tempdirname"/docker-compose.local.mutated.yml
#
"$repo_basedir"/scripts/docker-compose-config.bash \
"$repo_basedir"/scripts/docker-stack-config.bash \
-e "$repo_basedir"/services/simcore/.env \
"$osparcsimcoredeveldir"/services/docker-compose.yml \
"$repo_basedir"/"$tempdirname"/docker-compose.local.mutated.yml \
Expand Down
86 changes: 0 additions & 86 deletions scripts/docker-compose-config.bash

This file was deleted.

74 changes: 74 additions & 0 deletions scripts/docker-stack-config.bash
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}"
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ if [[ -z $(grep '[^[:space:]]' "$repo_basedir"/stack.yml) ]] ; then
error_exit "stack.yml is empty"
exit 1
fi
"$repo_basedir"/scripts/docker-compose-config.bash -e "$repo_basedir"/services/.env "$repo_basedir"/stack.yml 2>&1 | cat
"$repo_basedir"/scripts/docker-stack-config.bash -e "$repo_basedir"/services/.env "$repo_basedir"/stack.yml 2>&1 | cat
rm "$repo_basedir"/stack.yml 2>/dev/null || true
rm "$repo_basedir"/docker-compose.yml 2>/dev/null || true
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ source .venv/bin/activate
python -m pip install -r requirements.txt >/dev/null 2>&1
for i in "$@"; do
# assert file not empty via https://www.cyberciti.biz/faq/linux-unix-script-check-if-file-empty-or-not/
[ -s ../../../"$i" ] && bash -c "! ../../../scripts/docker-compose-config.bash -e .env ../../../$i 2>&1 | cat | grep \"must be unique\""
[ -s ../../../"$i" ] && bash -c "! ../../../scripts/docker-stack-config.bash -e .env ../../../$i 2>&1 | cat | grep \"must be unique\""
done
14 changes: 7 additions & 7 deletions services/admin-panels/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ endef
.PHONY: docker-compose.yml
docker-compose.yml: docker-compose.yml.j2 .venv .data.json
$(call jinja, $<, .data.json, tmp.yml)
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash tmp.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash tmp.yml > $@
@rm tmp.yml

.PHONY: up
Expand Down Expand Up @@ -68,28 +68,28 @@ up-public: up-dalco

.PHONY: ${TEMP_COMPOSE}-letsencrypt-http
${TEMP_COMPOSE}-letsencrypt-http: docker-compose.yml docker-compose.letsencrypt.http.yml .env
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< docker-compose.letsencrypt.http.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.letsencrypt.http.yml > $@

.PHONY: ${TEMP_COMPOSE}-letsencrypt-dns
${TEMP_COMPOSE}-letsencrypt-dns: docker-compose.yml docker-compose.letsencrypt.dns.yml .env
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< docker-compose.letsencrypt.dns.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.letsencrypt.dns.yml > $@

.PHONY: ${TEMP_COMPOSE}-dalco
${TEMP_COMPOSE}-dalco: docker-compose.yml .env
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< > $@

.PHONY: ${TEMP_COMPOSE}-master
${TEMP_COMPOSE}-master: docker-compose.yml .env
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< > $@


.PHONY: ${TEMP_COMPOSE}-aws
${TEMP_COMPOSE}-aws: docker-compose.yml docker-compose.aws.yml .env
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< docker-compose.aws.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.aws.yml > $@

.PHONY: ${TEMP_COMPOSE}
${TEMP_COMPOSE}: docker-compose.yml .env
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< > $@


.PHONY: jupyter_server_config.py
Expand Down
12 changes: 6 additions & 6 deletions services/adminer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,25 @@ up-public: up-dalco

.PHONY: ${TEMP_COMPOSE}
${TEMP_COMPOSE}: docker-compose.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< > $@

.PHONY: ${TEMP_COMPOSE}-letsencrypt-http
${TEMP_COMPOSE}-letsencrypt-http: docker-compose.yml docker-compose.letsencrypt.http.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< docker-compose.letsencrypt-http.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.letsencrypt-http.yml > $@

.PHONY: ${TEMP_COMPOSE}-letsencrypt-dns
${TEMP_COMPOSE}-letsencrypt-dns: docker-compose.yml docker-compose.letsencrypt.dns.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< docker-compose.letsencrypt.dns.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.letsencrypt.dns.yml > $@

.PHONY: ${TEMP_COMPOSE}-dalco
${TEMP_COMPOSE}-dalco: docker-compose.yml docker-compose.dalco.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< docker-compose.dalco.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.dalco.yml > $@

.PHONY: ${TEMP_COMPOSE}-master
${TEMP_COMPOSE}-master: docker-compose.yml docker-compose.master.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< docker-compose.master.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.master.yml > $@


.PHONY: ${TEMP_COMPOSE}-aws
${TEMP_COMPOSE}-aws: docker-compose.yml docker-compose.aws.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< docker-compose.aws.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.aws.yml > $@
6 changes: 3 additions & 3 deletions services/appmotion_gateway/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ up-local: .init .env ${TEMP_COMPOSE}-local .api_env.secret

.PHONY: ${TEMP_COMPOSE}-aws
${TEMP_COMPOSE}-aws: docker-compose.yml docker-compose.aws.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< docker-compose.aws.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.aws.yml > $@

.PHONY: ${TEMP_COMPOSE}-master
${TEMP_COMPOSE}-master: docker-compose.yml docker-compose.master.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< docker-compose.master.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.master.yml > $@

.PHONY: ${TEMP_COMPOSE}-local
${TEMP_COMPOSE}-local: docker-compose.yml docker-compose.local.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< docker-compose.local.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.local.yml > $@


.api_env.secret: .env template.api_env ## resolves '.api_env.secret' using '.env'
Expand Down
12 changes: 6 additions & 6 deletions services/filestash/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,27 @@ up-local: up

.PHONY: ${TEMP_COMPOSE}
${TEMP_COMPOSE}: docker-compose.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< > $@

.PHONY: ${TEMP_COMPOSE}-letsencrypt-http
${TEMP_COMPOSE}-letsencrypt-http: docker-compose.yml docker-compose.letsencrypt.http.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< docker-compose.letsencrypt.http.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.letsencrypt.http.yml > $@

.PHONY: ${TEMP_COMPOSE}-letsencrypt-dns
${TEMP_COMPOSE}-letsencrypt-dns: docker-compose.yml docker-compose.letsencrypt.dns.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< docker-compose.letsencrypt.dns.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.letsencrypt.dns.yml > $@

.PHONY: ${TEMP_COMPOSE}-dalco
${TEMP_COMPOSE}-dalco: docker-compose.yml docker-compose.dalco.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< docker-compose.dalco.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.dalco.yml > $@

.PHONY: ${TEMP_COMPOSE}-master
${TEMP_COMPOSE}-master: docker-compose.yml docker-compose.master.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< docker-compose.master.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.master.yml > $@

.PHONY: ${TEMP_COMPOSE}-aws
${TEMP_COMPOSE}-aws: docker-compose.yml docker-compose.aws.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< docker-compose.aws.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.aws.yml > $@


filestash_config.json: .env
Expand Down
14 changes: 7 additions & 7 deletions services/graylog/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,33 @@ up-local: .init .env ${TEMP_COMPOSE}-local ## Deploys graylog stack for local c
.PHONY: ${TEMP_COMPOSE}
${TEMP_COMPOSE}: docker-compose.yml ## Deploys stack
# Hacky workaround introduced by DK2021 via https://github.com/docker/compose/issues/7771
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< > $@

.PHONY: ${TEMP_COMPOSE}-letsencrypt-http ## Deploys stack using let's encrypt http challenge
${TEMP_COMPOSE}-letsencrypt-http: docker-compose.yml docker-compose.letsencrypt.http.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< docker-compose.letsencrypt.http.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.letsencrypt.http.yml > $@

.PHONY: ${TEMP_COMPOSE}-letsencrypt-dns ## Deploys stack using let's encrypt dns challenge
${TEMP_COMPOSE}-letsencrypt-dns: docker-compose.yml docker-compose.letsencrypt.dns.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< docker-compose.letsencrypt.dns.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.letsencrypt.dns.yml > $@

.PHONY: ${TEMP_COMPOSE}-dalco
${TEMP_COMPOSE}-dalco: docker-compose.yml docker-compose.dalco.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< docker-compose.dalco.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.dalco.yml > $@

.PHONY: ${TEMP_COMPOSE}-master .env ## Deploys stack on master deployment
# Hacky workaround introduced by DK2021 via https://github.com/docker/compose/issues/7771
${TEMP_COMPOSE}-master: docker-compose.yml docker-compose.master.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< docker-compose.master.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.master.yml > $@

.PHONY: ${TEMP_COMPOSE}-local ## Deploys stack on local deployment
# Hacky workaround introduced by DK2021 via https://github.com/docker/compose/issues/7771
${TEMP_COMPOSE}-local: docker-compose.yml docker-compose.local.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< docker-compose.local.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.local.yml > $@

.PHONY: ${TEMP_COMPOSE}-aws ## Deploys stack on aws
${TEMP_COMPOSE}-aws: docker-compose.yml docker-compose.aws.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash -e .env $< docker-compose.aws.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash -e .env $< docker-compose.aws.yml > $@

.PHONY: .env
.env: template.env $(REPO_CONFIG_LOCATION)
Expand Down
12 changes: 6 additions & 6 deletions services/jaeger/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,24 @@ up-local: up

.PHONY: ${TEMP_COMPOSE}
${TEMP_COMPOSE}: docker-compose.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash $< > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash $< > $@

.PHONY: ${TEMP_COMPOSE}-letsencrypt-http
${TEMP_COMPOSE}-letsencrypt-http: docker-compose.yml docker-compose.letsencrypt.http.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash $< docker-compose.letsencrypt.http.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash $< docker-compose.letsencrypt.http.yml > $@

.PHONY: ${TEMP_COMPOSE}-letsencrypt-dns
${TEMP_COMPOSE}-letsencrypt-dns: docker-compose.yml docker-compose.letsencrypt.dns.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash $< docker-compose.letsencrypt.dns.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash $< docker-compose.letsencrypt.dns.yml > $@

.PHONY: ${TEMP_COMPOSE}-dalco
${TEMP_COMPOSE}-dalco: docker-compose.yml docker-compose.dalco.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash $< docker-compose.dalco.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash $< docker-compose.dalco.yml > $@

.PHONY: ${TEMP_COMPOSE}-master
${TEMP_COMPOSE}-master: docker-compose.yml docker-compose.master.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash $< docker-compose.master.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash $< docker-compose.master.yml > $@

.PHONY: ${TEMP_COMPOSE}-aws
${TEMP_COMPOSE}-aws: docker-compose.yml docker-compose.aws.yml
@${REPO_BASE_DIR}/scripts/docker-compose-config.bash $< docker-compose.aws.yml > $@
@${REPO_BASE_DIR}/scripts/docker-stack-config.bash $< docker-compose.aws.yml > $@
Loading

0 comments on commit 91a0794

Please sign in to comment.