diff --git a/gogocarto/metadata.yml b/gogocarto/metadata.yml index 05b609b..bb163b3 100644 --- a/gogocarto/metadata.yml +++ b/gogocarto/metadata.yml @@ -6,6 +6,9 @@ requires: scope: container +provides: + map-server: + uses: publish-dir: #constraint: required | recommended | optional diff --git a/monujo/hooks/init b/monujo/hooks/init index 6c830f4..8433634 100755 --- a/monujo/hooks/init +++ b/monujo/hooks/init @@ -10,18 +10,11 @@ ## - SERVICE_DATASTORE Location on host of the DATASTORE of this service ## - SERVICE_CONFIGSTORE Location on host of the CONFIGSTORE of this service +. lib/common + set -e -APP_NAME=monujo -SOURCE_URL="https://docker.0k.io/downloads/$APP_NAME-0.0.1.tar.bz2" -LOCATION="$SERVICE_DATASTORE/opt/apps/$APP_NAME" +monujo:code_init -mkdir -p "$LOCATION" -if dir_is_empty "$LOCATION"; then - cd "$LOCATION" - wget -q "$SOURCE_URL" -O file.tar.bz2 - tar xjf file.tar.bz2 - rm file.tar.bz2 - chown root:root "$LOCATION" -R -fi +monujo:code_config_base diff --git a/monujo/hooks/pre_deploy b/monujo/hooks/pre_deploy new file mode 100755 index 0000000..6290966 --- /dev/null +++ b/monujo/hooks/pre_deploy @@ -0,0 +1,27 @@ +#!/bin/bash +## Should be executable N time in a row with same result. + +. lib/common + +set -e + +if ! url=$(relation:get "${SERVICE_NAME}":odoo-server:web-proxy url); then + err "Monujo doesn't support odoo-server not having a web-proxy yet." + exit 1 +fi +if ! dbname=$(relation:get "${SERVICE_NAME}":odoo-server:postgres-database dbname); then + err "Can't find db name of our odoo-server relation." + exit 1 +fi + +monujo:config_merge "{ + \"lokapiHost\": \"$url\", + \"lokapiDb\": \"$dbname\" +}" + + +if map_url=$(relation:get "${SERVICE_NAME}":map-server:publish-dir url); then + monujo:config_merge "{ + \"mapUrl\": \"$map_url\" + }" +fi diff --git a/monujo/lib/common b/monujo/lib/common new file mode 100644 index 0000000..e0bd4a6 --- /dev/null +++ b/monujo/lib/common @@ -0,0 +1,76 @@ + + +APP_NAME=monujo +VERSION=0.0.2 +SOURCE_URL="https://docker.0k.io/downloads/$APP_NAME-$VERSION.tar.bz2" +LOCATION="$SERVICE_DATASTORE/opt/apps/$APP_NAME" +CONFIGFILE="$LOCATION/config.json" + + +monujo:code_init() { + mkdir -p "$LOCATION" + if dir_is_empty "$LOCATION"; then + cd "$LOCATION" + wget -q "$SOURCE_URL" -O file.tar.bz2 + tar xjf file.tar.bz2 + rm file.tar.bz2 + chown root:root "$LOCATION" -R + fi +} + + +monujo:code_config_base() { + + MONUJO_OPTIONS=( + lokapi-host:string + lokapi-db:string + map-url:string + local-password-retention-time:string + ) + + MONUJO_OPTIONS_CONCAT=" ${MONUJO_OPTIONS[*]} " + + service_def=$(get_compose_service_def "$SERVICE_NAME") || return 1 + echo "{}" > "$CONFIGFILE" + ## XXXvlab: Should probably offer some lib to do this + while read-0 key val; do + key_option=${key//-/_} + case "$MONUJO_OPTIONS_CONCAT" in + *" ${key_option}:bool "*) + case "${val,,}" in + true|ok|yes|y) + val=yes + ;; + false|ko|nok|no|n) + val=no + ;; + *) + die "Invalid value for ${WHITE}$key$NORMAL, please use a boolean value." + ;; + esac + ;; + *" ${key_option}:numeric "*) + if ! is_int "$val"; then + die "Invalid value for ${WHITE}$key$NORMAL, please use numeric value." + fi + ;; + *" ${key_option}:string "*) + : + ;; + *) + key_option=$(echo "$key_option" | sed 's/_\([a-z0-9]\)/\U\1/g') + printf "%s %s\0" "$key_option" "$val" + ;; + esac + done < <(printf "%s" "$service_def" | shyaml key-values-0 options) | + jq -R 'split("\u0000") | map(split(" ") | {key: .[0], value: .[1]}) | from_entries' > \ + "$CONFIGFILE" + +} + + +monujo:config_merge() { + local old_config new_config="$1" + old_config=$(cat "$CONFIGFILE") + e "$old_config" "$new_config" | jq -s 'reduce .[] as $x ({}; . * $x)' > "$CONFIGFILE" +} \ No newline at end of file diff --git a/monujo/metadata.yml b/monujo/metadata.yml index d7b8028..67fcc19 100644 --- a/monujo/metadata.yml +++ b/monujo/metadata.yml @@ -15,3 +15,17 @@ uses: location: !var-expand "$DATASTORE/$BASE_SERVICE_NAME/opt/apps/monujo" # data-dirs: ## write permission for web-app # - . + odoo-server: + #constraint: required | recommended | optional + #auto: pair | summon | none ## default: pair + constraint: required + auto: pair + solves: + container: "LCC API provider" + map-server: + #constraint: required | recommended | optional + #auto: pair | summon | none ## default: pair + constraint: optional + auto: pair + solves: + container: "Map server" diff --git a/odoo-tecnativa/metadata.yml b/odoo-tecnativa/metadata.yml index 9c471d3..ee13bf5 100644 --- a/odoo-tecnativa/metadata.yml +++ b/odoo-tecnativa/metadata.yml @@ -28,6 +28,9 @@ default-options: # othersection: # myvalue: yyy +provides: + odoo-server: + uses: postgres-database: #constraint: required | recommended | optional