From fa6701aace2ef4bbebc4deac01529070b0df8427 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Tue, 17 Dec 2024 10:43:12 +0100 Subject: [PATCH 1/7] new: [mongo] add support for 6.0.* version --- mongo/actions/upgrade | 48 +++++++++++++++++++-------- mongo/hooks/init | 5 +-- mongo/lib/common | 6 +++- mongo/upgrade/build/6.0.19/Dockerfile | 3 +- mongo/upgrade/build/7.0.15/Dockerfile | 3 +- 5 files changed, 46 insertions(+), 19 deletions(-) diff --git a/mongo/actions/upgrade b/mongo/actions/upgrade index 5c10ae9..1b370c2 100755 --- a/mongo/actions/upgrade +++ b/mongo/actions/upgrade @@ -79,31 +79,45 @@ mongo:image:version() { } mongo:container:version() { - local container="$1" - if ! out=$(docker exec -i "$container" mongo --version); then + local container="$1" version + if ! out=$(docker exec "$container" mongod --version); then err "Couldn't infer container's '$container' mongod's version." - exit 1 + return 1 fi out=${out%%$'\n'*} out=${out%%$'\r'*} - image_version=${out#db version v} - echo "$image_version" + version=${out#db version v} + echo "$version" } mongo:container:mongo () { local container="$1" + docker exec -i "$container" mongo 2>&1 } mongo:container:fix_compat() { - local container="$1" image_version="$2" - out=$(echo "db.adminCommand( { setFeatureCompatibilityVersion: \"${image_version%.*}\" } )" | - mongo:container:mongo "$container" 2>&1) - if [[ "$out" == *"\"ok\" : 1"* ]]; then + local container="$1" image_version="$2" version + + if ! version=$(mongo:container:version "$container"); then + err "Couldn't get container's mongod version" + return 1 + fi + + + ## No need of confirmation for version < 7.0.0 + if version_gt 7.0.0 "$version"; then + mongo_cmd="db.adminCommand( { setFeatureCompatibilityVersion: \"${image_version%.*}\" } )" + else + mongo_cmd="db.adminCommand( { setFeatureCompatibilityVersion: \"${image_version%.*}\", confirm: true } )" + fi + + out=$(echo "$mongo_cmd" | mongo:container:mongo "$container" 2>&1) + if [[ "$out" == *"\"ok\" : 1"* ]] || [[ "$out" == *"ok: 1"* ]]; then debug "Feature Compatibility set to ${WHITE}${image_version%.*}${NORMAL}" else err "Failed to set feature compatibility version to ${WHITE}${image_version%.*}${NORMAL}:" - echo "$out" | prefix " | " >&2 + printf "%s" "$out" | prefix " | " >&2 return 1 fi } @@ -202,13 +216,18 @@ if [ -n "$containers" ]; then #err "Running container(s) for $DARKYELLOW$SERVICE_NAME$NORMAL are still running:" for container in $containers; do debug "Stopping container $container" - docker stop "$container" >/dev/null || { + docker:container:stop "$container" >/dev/null || { err "Failed to stop container '$container'." exit 1 } - docker rm "$container" > /dev/null || { - err "Couldn't delete container '$container'." - } + docker rm "$container" > /dev/null + + ## Check that the container is actually removed + if [ -n "$(docker ps -q -f name="$container")" ]; then + err "Failed to remove container '$container'." + exit 1 + fi + container_stopped+=("$container") done fi @@ -339,6 +358,7 @@ if [ -z "$unexpected_stop" -a -z "$expected_stop" ]; then docker stop "$migration_container" fi + if [ -n "$failed" ]; then echo "${WHITE}Failing migration logs:${NORMAL}" >&2 cat "$MIGRATION_TMPDIR/migration.log" | prefix " ${GRAY}|${NORMAL} " >&2 diff --git a/mongo/hooks/init b/mongo/hooks/init index e140d0b..00081e1 100755 --- a/mongo/hooks/init +++ b/mongo/hooks/init @@ -93,9 +93,10 @@ ensure_db_docker_running cmd="rs.initiate({ _id: 'rs01', members: [ { _id: 0, host: '$SERVICE_NAME:27017' } ]})" debug "${WHITE}running:$NORMAL $cmd" -out=$(ddb <<<"$cmd") +out=$(ddb 2>&1 <<<"$cmd") || true -if [[ "$out" == *"\"codeName\" : \"AlreadyInitialized\""* ]]; then +if [[ "$out" == *"\"codeName\" : \"AlreadyInitialized\""* ]] || + [[ "$out" == *"MongoServerError: already initialized"* ]]; then info "ReplicaSet already initialized." elif [[ "$out" == *"\"ok\" : 1"* ]]; then info "ReplicaSet initialized. " diff --git a/mongo/lib/common b/mongo/lib/common index 8d3754f..68766e2 100644 --- a/mongo/lib/common +++ b/mongo/lib/common @@ -46,7 +46,11 @@ _set_db_params() { } -ddb() { dcmd mongo --quiet "$@"; } +ddb() { + local eval_code + eval_code="$(cat - )" + dcmd mongo --quiet "$@" --eval "$eval_code" Date: Tue, 21 Jan 2025 14:33:45 +0100 Subject: [PATCH 2/7] new: [odoo-tecnativa] set correct executable permission for entrypoint script --- .../resources/opt/odoo/common/entrypoint.d/20-postgres-wait | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 odoo-tecnativa/resources/opt/odoo/common/entrypoint.d/20-postgres-wait diff --git a/odoo-tecnativa/resources/opt/odoo/common/entrypoint.d/20-postgres-wait b/odoo-tecnativa/resources/opt/odoo/common/entrypoint.d/20-postgres-wait old mode 100644 new mode 100755 -- 2.30.2 From 1f06bd1d3490ca4fb0ea6994e439b7bcc0c73c35 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Mon, 27 Jan 2025 17:42:01 +0100 Subject: [PATCH 3/7] fix: dev: [odoo-tecnativa] prefer ``relation:get`` --- odoo-tecnativa/actions/load | 23 +++-------------------- odoo-tecnativa/actions/save | 23 +++-------------------- 2 files changed, 6 insertions(+), 40 deletions(-) diff --git a/odoo-tecnativa/actions/load b/odoo-tecnativa/actions/load index 54d36e4..6b24bca 100755 --- a/odoo-tecnativa/actions/load +++ b/odoo-tecnativa/actions/load @@ -64,26 +64,9 @@ version:lt() { ! version:ge "$@"; } if [ -z "$dbname" ]; then - - ## - ## Fetch default dbname in relation to postgres-database - ## - - ## XXXvlab: can't get real config here - if ! read-0 ts _ _ < <(get_service_relation "$SERVICE_NAME" "postgres-database"); then - err "Couldn't find relation ${DARKCYAN}postgres-database${NORMAL}." - exit 1 - fi - - relation_file=$(get_relation_data_dir "$SERVICE_NAME" "$ts" "postgres-database") || { - err "Failed to find relation file" - exit 1 - } - - postgres_config=$(cat "$relation_file"/data) || exit 2 - - dbname="$(e "$postgres_config" | shyaml get-value dbname)" || { - err "Couldn't retrieve information of ${DARKCYAN}postgres-database${NORMAL}'s relation." + dbname=$(relation:get "$SERVICE_NAME:postgres-database" dbname) || { + err "Couldn't retrieve information of" \ + "${DARKYELLOW}$SERVICE_NAME${NORMAL}-->${DARKCYAN}postgres-database${NORMAL}." exit 1 } fi diff --git a/odoo-tecnativa/actions/save b/odoo-tecnativa/actions/save index b9d067d..d79ebef 100755 --- a/odoo-tecnativa/actions/save +++ b/odoo-tecnativa/actions/save @@ -56,26 +56,9 @@ done if [ -z "$dbname" ]; then - - ## - ## Fetch default dbname in relation to postgres-database - ## - - ## XXXvlab: can't get real config here - if ! read-0 ts _ _ < <(get_service_relation "$SERVICE_NAME" "postgres-database"); then - err "Couldn't find relation ${DARKCYAN}postgres-database${NORMAL}." - exit 1 - fi - - relation_file=$(get_relation_data_dir "$SERVICE_NAME" "$ts" "postgres-database") || { - err "Failed to find relation file" - exit 1 - } - - postgres_config=$(cat "$relation_file"/data) || exit 2 - - dbname="$(e "$postgres_config" | shyaml get-value dbname)" || { - err "Couldn't retrieve information of ${DARKCYAN}mysql-database${NORMAL}'s relation." + dbname=$(relation:get "$SERVICE_NAME:postgres-database" dbname) || { + err "Couldn't retrieve information of" \ + "${DARKYELLOW}$SERVICE_NAME${NORMAL}-->${DARKCYAN}postgres-database${NORMAL}." exit 1 } fi -- 2.30.2 From bc84fecf3e7b537c802ab9fdcfc6273c39c4ae1c Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Mon, 27 Jan 2025 18:25:20 +0100 Subject: [PATCH 4/7] fix: dev: [odoo-tecnativa] factorize code to ``lib/common`` --- odoo-tecnativa/actions/load | 32 ++++++++------------------------ odoo-tecnativa/actions/save | 18 +++++------------- odoo-tecnativa/lib/common | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 37 deletions(-) diff --git a/odoo-tecnativa/actions/load b/odoo-tecnativa/actions/load index 6b24bca..85b2ca5 100755 --- a/odoo-tecnativa/actions/load +++ b/odoo-tecnativa/actions/load @@ -71,38 +71,22 @@ if [ -z "$dbname" ]; then } fi +. "$CHARM_PATH/lib/common" + set -e curl_opts=() -## Ensure odoo is launched -service_def=$(get_compose_service_def "$SERVICE_NAME") - -## XXXvlab: should be moved to lib -CONFIG=$SERVICE_CONFIGSTORE/etc/odoo-server.conf -ADMIN_PASSWORD=$(echo "$service_def" | shyaml -q get-value options.admin-password) || { - if [ -e "$CONFIG" ]; then - ADMIN_PASSWORD=$(grep ^admin_passwd "$CONFIG" | sed -r 's/^admin_passwd\s+=\s+(.+)$/\1/g') - fi - if [ -z "$ADMIN_PASSWORD" ]; then - err "Could not find 'admin-password' in $SERVICE_NAME service definition nor in config file." - exit 1 - fi -} - -containers="$(get_running_containers_for_service "$SERVICE_NAME")" -if [ -z "$containers" ]; then - err "No containers running for service $DARKYELLOW$SERVICE_NAME$NORMAL." +ADMIN_PASSWORD=$(odoo:get-admin-password) || { + err "Couldn't retrieve admin password for ${DARKYELLOW}$SERVICE_NAME${NORMAL}." exit 1 -fi +} -if [ "$(echo "$containers" | wc -l)" -gt 1 ]; then - err "More than 1 container running for service $DARKYELLOW$SERVICE_NAME$NORMAL." - echo " Please contact administrator to fix this issue." >&2 +container="$(get_running_container_for_service "$SERVICE_NAME")" || { + err "Couldn't find running container for service ${DARKYELLOW}$SERVICE_NAME${NORMAL}." exit 1 -fi +} -container="$(echo "$containers" | head -n 1)" odoo_version=$(docker exec "$container" python -c 'import odoo.release; print(odoo.release.version)') || { err "Failed to get odoo version." exit 1 diff --git a/odoo-tecnativa/actions/save b/odoo-tecnativa/actions/save index d79ebef..5de18fe 100755 --- a/odoo-tecnativa/actions/save +++ b/odoo-tecnativa/actions/save @@ -63,21 +63,13 @@ if [ -z "$dbname" ]; then } fi -set -e +. $CHARM_PATH/lib/common -## Ensure odoo is launched -service_def=$(get_compose_service_def "$SERVICE_NAME") +set -e -## XXXvlab: should be moved to lib -CONFIG=$SERVICE_CONFIGSTORE/etc/odoo-server.conf -ADMIN_PASSWORD=$(echo "$service_def" | shyaml -q get-value options.admin-password) || { - if [ -e "$CONFIG" ]; then - ADMIN_PASSWORD=$(grep ^admin_passwd "$CONFIG" | sed -r 's/^admin_passwd\s+=\s+(.+)$/\1/g') - fi - if [ -z "$ADMIN_PASSWORD" ]; then - err "Could not find 'admin-password' in $SERVICE_NAME service definition nor in config file." - exit 1 - fi +ADMIN_PASSWORD=$(odoo:get-admin-password) || { + err "Couldn't retrieve admin password for $SERVICE_NAME." + exit 1 } container_network_ip=$(get_healthy_container_ip_for_service "$SERVICE_NAME" 8069 4) || { diff --git a/odoo-tecnativa/lib/common b/odoo-tecnativa/lib/common index 8babbde..c3a4ebb 100644 --- a/odoo-tecnativa/lib/common +++ b/odoo-tecnativa/lib/common @@ -38,3 +38,40 @@ sql() { ddb "${dbname:-$DBNAME}" ) } + + +odoo:get-admin-password() { + local service_def config admin_password + service_def=$(get_compose_service_def "$SERVICE_NAME") + + config=$SERVICE_CONFIGSTORE/etc/odoo-server.conf + admin_password=$(echo "$service_def" | shyaml -q get-value options.admin-password) || { + if [ -e "$config" ]; then + admin_password=$(grep ^admin_passwd "$config" | sed -r 's/^admin_passwd\s+=\s+(.+)$/\1/g') + fi + if [ -z "$admin_password" ]; then + err "Could not find 'admin-password' in $SERVICE_NAME service definition nor in config file." + return 1 + fi + + } + echo "$admin_password" +} + +## XXXvlab: to include in `compose-core` +get_running_container_for_service() { + local containers service="$1" + containers=($(get_running_containers_for_service "$service")) + if [ "${#containers[@]}" == 0 ]; then + err "No containers running for service $DARKYELLOW$service$NORMAL." + return 1 + fi + + if [ "${#containers[@]}" -gt 1 ]; then + err "More than 1 container running for service $DARKYELLOW$service$NORMAL." + echo " Please contact administrator to fix this issue." >&2 + return 1 + fi + + echo "${containers[0]}" +} -- 2.30.2 From 5122c6e67e6a6f8bd60684fefe14312499396f98 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Mon, 27 Jan 2025 19:53:30 +0100 Subject: [PATCH 5/7] fix: dev: [odoo-tecnativa] move code for save and load to ``lib/common`` --- odoo-tecnativa/actions/load | 101 +-------------------- odoo-tecnativa/actions/save | 56 +----------- odoo-tecnativa/lib/common | 176 ++++++++++++++++++++++++++++++++++++ 3 files changed, 178 insertions(+), 155 deletions(-) diff --git a/odoo-tecnativa/actions/load b/odoo-tecnativa/actions/load index 85b2ca5..d240c83 100755 --- a/odoo-tecnativa/actions/load +++ b/odoo-tecnativa/actions/load @@ -75,103 +75,4 @@ fi set -e -curl_opts=() - -ADMIN_PASSWORD=$(odoo:get-admin-password) || { - err "Couldn't retrieve admin password for ${DARKYELLOW}$SERVICE_NAME${NORMAL}." - exit 1 -} - -container="$(get_running_container_for_service "$SERVICE_NAME")" || { - err "Couldn't find running container for service ${DARKYELLOW}$SERVICE_NAME${NORMAL}." - exit 1 -} - -odoo_version=$(docker exec "$container" python -c 'import odoo.release; print(odoo.release.version)') || { - err "Failed to get odoo version." - exit 1 -} -if version:lt "$odoo_version" "16.0" && [ -n "$neutralize" ]; then - err "Option \`\`--neutralize\`\` (or \`\`-n\`\`)" \ - "is only available for odoo ${WHITE}16.0${NORMAL}+." - echo " Service ${DARKYELLOW}$SERVICE_NAME${NORMAL} is running odoo ${WHITE}$odoo_version${NORMAL}" >&2 - exit 1 -fi - -if [ -n "$neutralize" ]; then - curl_opts+=(-F "neutralize_database=true") -fi - -container_network_ip=$(get_healthy_container_ip_for_service "$SERVICE_NAME" 8069 4) || { - err "Please ensure that $DARKYELLOW$service$NORMAL is running before using '$exname'." - exit 1 -} - -container_ip=${container_network_ip##*:} -container_network=${container_network_ip%%:*} - - -DEFAULT_CURL_IMAGE=${DEFAULT_CURL_IMAGE:-docker.0k.io/curl} - -check_input() { - local chars - read -n 2 -r chars - if [ "$chars" != "PK" ]; then - err "Unexpected input not matching ZIP signature. Invalid dump." - echo " First chars: '$chars'" - exit 1 - fi - { - printf "%s" "$chars" - cat - } -} - -## Beware that we are not on the host, so we need to create the -## fifo in a place we can share with the curl container. -export TMPDIR=/var/cache/compose -settmpdir RESTORE_TMPDIR - -mkfifo "$RESTORE_TMPDIR/fifo" - -## Using fifo because if using ``@-`` curl will load all the database -## in memory before sending it, which is NOT desirable as the size of -## the database can be greater than available memory. Using fifo, we -## force the data to be streamed. -cmd=( - docker run -i --rm --network "$container_network" - -v "$RESTORE_TMPDIR/fifo:/tmp/restore/fifo" - "$DEFAULT_CURL_IMAGE" - -sS - -X POST - -F "master_pwd=${ADMIN_PASSWORD}" - -F "name=${dbname}" - "${curl_opts[@]}" - -F "backup_file=@/tmp/restore/fifo" - http://${container_ip}:8069/web/database/restore - ) - -## XXXvlab: contains password, left only for advanced debug -#echo "COMMAND: ${cmd[@]}" >&2 - -"${cmd[@]}" > "$RESTORE_TMPDIR/out" & -pid=$! -check_input > "$RESTORE_TMPDIR/fifo" -wait "$pid" || { - die "Posting to odoo restore API through curl was unsuccessfull." -} - -out=$(cat "$RESTORE_TMPDIR/out") - -if [[ "$out" == *""* ]]; then - errmsg=$(echo "$out" | grep "alert-danger") - errmsg=${errmsg#*>} - errmsg=${errmsg%%<*} - if [ "$errmsg" ]; then - errmsg=$(echo "$errmsg" | recode html..utf8) - die "$errmsg" - fi - die "Unexpected output. Restore probably failed." -fi >&2 - -info "Restored stdin dump to odoo '$dbname'." \ No newline at end of file +odoo:load "$dbname" "$neutralize" diff --git a/odoo-tecnativa/actions/save b/odoo-tecnativa/actions/save index 5de18fe..4b4db49 100755 --- a/odoo-tecnativa/actions/save +++ b/odoo-tecnativa/actions/save @@ -67,58 +67,4 @@ fi set -e -ADMIN_PASSWORD=$(odoo:get-admin-password) || { - err "Couldn't retrieve admin password for $SERVICE_NAME." - exit 1 -} - -container_network_ip=$(get_healthy_container_ip_for_service "$SERVICE_NAME" 8069 4) || { - err "Please ensure that $DARKYELLOW$SERVICE_NAME$NORMAL is running before using '$exname'." - exit 1 -} - -container_ip=${container_network_ip##*:} -container_network=${container_network_ip%%:*} - -DEFAULT_CURL_IMAGE=${DEFAULT_CURL_IMAGE:-docker.0k.io/curl} - - -check_output() { - local chars - read -n 2 -r chars - if [ "$chars" != "PK" ]; then - out=$(cat) - errmsg=$(echo "$out" | grep "alert-danger") - errmsg=${errmsg#*>} - errmsg=${errmsg%%<*} - if [ -n "$errmsg" ]; then - errmsg=$(echo "$errmsg" | recode html..utf8) - die "$errmsg" - fi - err "Unexpected output not matching ZIP signature. Dump probably failed." - exit 1 - fi - { - echo -n "$chars" - cat - } -} - - -cmd=( - docker run --rm --network "$container_network" - "$DEFAULT_CURL_IMAGE" - -sS - -X POST - -F "master_pwd=${ADMIN_PASSWORD}" - -F "name=${dbname}" - -F "backup_format=zip" - http://${container_ip}:8069/web/database/backup -) - -## XXXvlab: contains password, left only for advanced debug -#debug "${cmd[@]}" - -set -o pipefail -"${cmd[@]}" | check_output && - info "Requested odoo '$dbname' dump and outputted result to stdout." +odoo:save "$dbname" diff --git a/odoo-tecnativa/lib/common b/odoo-tecnativa/lib/common index c3a4ebb..c9ed38c 100644 --- a/odoo-tecnativa/lib/common +++ b/odoo-tecnativa/lib/common @@ -75,3 +75,179 @@ get_running_container_for_service() { echo "${containers[0]}" } + + +odoo:save() { + local ADMIN_PASSWORD container_ip container_network_ip container_network cmd dbname="$1" + + ADMIN_PASSWORD=$(odoo:get-admin-password) || { + err "Couldn't retrieve admin password for $SERVICE_NAME." + return 1 + } + + container_network_ip=$(get_healthy_container_ip_for_service "$SERVICE_NAME" 8069 4) || { + err "Please ensure that $DARKYELLOW$SERVICE_NAME$NORMAL is running before using '$exname'." + return 1 + } + + container_ip=${container_network_ip##*:} + container_network=${container_network_ip%%:*} + + DEFAULT_CURL_IMAGE=${DEFAULT_CURL_IMAGE:-docker.0k.io/curl} + + + check_output() { + local chars + read -n 2 -r chars + if [ "$chars" != "PK" ]; then + out=$(cat) + errmsg=$(echo "$out" | grep "alert-danger") + errmsg=${errmsg#*>} + errmsg=${errmsg%%<*} + if [ -n "$errmsg" ]; then + errmsg=$(echo "$errmsg" | recode html..utf8) + die "$errmsg" + fi + err "Unexpected output not matching ZIP signature. Dump probably failed." + return 1 + fi + { + echo -n "$chars" + cat + } + } + + + cmd=( + docker run --rm --network "$container_network" + "$DEFAULT_CURL_IMAGE" + -sS + -X POST + -F "master_pwd=${ADMIN_PASSWORD}" + -F "name=${dbname}" + -F "backup_format=zip" + http://${container_ip}:8069/web/database/backup + ) + + ## XXXvlab: contains password, left only for advanced debug + #debug "${cmd[@]}" + + set -o pipefail + "${cmd[@]}" | check_output && + info "Requested odoo '$dbname' dump and outputted result to stdout." + +} + +odoo:version() { + local odoo_version container + container="$(get_running_container_for_service "$SERVICE_NAME")" || { + err "Couldn't find running container for service ${DARKYELLOW}$SERVICE_NAME${NORMAL}." + return 1 + } + + odoo_version=$(docker exec "$container" python -c 'import odoo.release; print(odoo.release.version)') || { + err "Failed to get odoo version from ${DARKYELLOW}$SERVICE_NAME${NORMAL}." + return 1 + } + echo "$odoo_version" +} + + +odoo:load() { + local ADMIN_PASSWORD container_ip container_network_ip container_network cmd \ + dbname="$1" neutralize="$2" DEFAULT_CURL_IMAGE RESTORE_TMPDIR + + curl_opts=() + + ADMIN_PASSWORD=$(odoo:get-admin-password) || { + err "Couldn't retrieve admin password for ${DARKYELLOW}$SERVICE_NAME${NORMAL}." + return 1 + } + + odoo_version=$(odoo:version) || return 1 + if version:lt "$odoo_version" "16.0" && [ -n "$neutralize" ]; then + err "Option \`\`--neutralize\`\` (or \`\`-n\`\`)" \ + "is only available for odoo ${WHITE}16.0${NORMAL}+." + echo " Service ${DARKYELLOW}$SERVICE_NAME${NORMAL} is running odoo ${WHITE}$odoo_version${NORMAL}" >&2 + return 1 + fi + + if [ -n "$neutralize" ]; then + curl_opts+=(-F "neutralize_database=true") + fi + + container_network_ip=$(get_healthy_container_ip_for_service "$SERVICE_NAME" 8069 4) || { + err "Please ensure that $DARKYELLOW$service$NORMAL is running before using '$exname'." + return 1 + } + + container_ip=${container_network_ip##*:} + container_network=${container_network_ip%%:*} + + + DEFAULT_CURL_IMAGE=${DEFAULT_CURL_IMAGE:-docker.0k.io/curl} + + check_input() { + local chars + read -n 2 -r chars + if [ "$chars" != "PK" ]; then + err "Unexpected input not matching ZIP signature. Invalid dump." + echo " First chars: '$chars'" + return 1 + fi + { + printf "%s" "$chars" + cat + } + } + + ## Beware that we are not on the host, so we need to create the + ## fifo in a place we can share with the curl container. + export TMPDIR=/var/cache/compose + settmpdir RESTORE_TMPDIR + + mkfifo "$RESTORE_TMPDIR/fifo" + + ## Using fifo because if using ``@-`` curl will load all the database + ## in memory before sending it, which is NOT desirable as the size of + ## the database can be greater than available memory. Using fifo, we + ## force the data to be streamed. + cmd=( + docker run -i --rm --network "$container_network" + -v "$RESTORE_TMPDIR/fifo:/tmp/restore/fifo" + "$DEFAULT_CURL_IMAGE" + -sS + -X POST + -F "master_pwd=${ADMIN_PASSWORD}" + -F "name=${dbname}" + "${curl_opts[@]}" + -F "backup_file=@/tmp/restore/fifo" + http://${container_ip}:8069/web/database/restore + ) + + ## XXXvlab: contains password, left only for advanced debug + #echo "COMMAND: ${cmd[@]}" >&2 + + "${cmd[@]}" > "$RESTORE_TMPDIR/out" & + pid=$! + check_input > "$RESTORE_TMPDIR/fifo" + wait "$pid" || { + die "Posting to odoo restore API through curl was unsuccessfull." + } + + out=$(cat "$RESTORE_TMPDIR/out") + + if [[ "$out" == *""* ]]; then + errmsg=$(echo "$out" | grep "alert-danger") + errmsg=${errmsg#*>} + errmsg=${errmsg%%<*} + if [ "$errmsg" ]; then + errmsg=$(echo "$errmsg" | recode html..utf8) + die "$errmsg" + fi + die "Unexpected output. Restore probably failed." + fi >&2 + + info "Restored stdin dump to odoo '$dbname'." + +} -- 2.30.2 From 0ee4f0ea443eeac4fb22266e18090416bcea0e48 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Wed, 29 Jan 2025 10:39:58 +0100 Subject: [PATCH 6/7] new: [apache] add ``check-external-https`` indirect action --- .../publish-dir/check-external-https | 30 +++++++++++++++++++ .../relations/web-proxy/check-external-https | 1 + 2 files changed, 31 insertions(+) create mode 100755 apache/actions/relations/publish-dir/check-external-https create mode 120000 apache/actions/relations/web-proxy/check-external-https diff --git a/apache/actions/relations/publish-dir/check-external-https b/apache/actions/relations/publish-dir/check-external-https new file mode 100755 index 0000000..9e78860 --- /dev/null +++ b/apache/actions/relations/publish-dir/check-external-https @@ -0,0 +1,30 @@ +#!/bin/bash +# compose: no-hooks + +## Load action gets a first argument a FILE/DIRECTORY/URL holding the necessary files. +## +## + +if [ -z "$SERVICE_DATASTORE" ]; then + echo "This script is meant to be run through 'compose' to work properly." >&2 + exit 1 +fi + +usage="$exname [-h|--help]" + +while [ "$1" ]; do + case "$1" in + "--help"|"-h") + print_usage + exit 0 + ;; + *) + err "Unexpected argument '$1'." + exit 1 + ;; + esac + shift +done +url=$(relation-get url) + +curl -Isf "$url" --max-time 5 >/dev/null diff --git a/apache/actions/relations/web-proxy/check-external-https b/apache/actions/relations/web-proxy/check-external-https new file mode 120000 index 0000000..7584938 --- /dev/null +++ b/apache/actions/relations/web-proxy/check-external-https @@ -0,0 +1 @@ +../publish-dir/check-external-https \ No newline at end of file -- 2.30.2 From e53e2cfac036fd3b9cd7caedfe258a2562f543f5 Mon Sep 17 00:00:00 2001 From: Boris Gallet Date: Mon, 3 Feb 2025 17:47:24 +0100 Subject: [PATCH 7/7] chg: ``send`` accept input from STDIN --- docker-host/src/bin/send | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docker-host/src/bin/send b/docker-host/src/bin/send index f8b99de..59d0028 100755 --- a/docker-host/src/bin/send +++ b/docker-host/src/bin/send @@ -66,6 +66,11 @@ Options: " +# Accept input from stdin +if [[ -p /dev/stdin ]]; then + message=$(cat) +fi + while [ "$#" -gt 0 ]; do arg="$1" shift -- 2.30.2