Browse Source

new: [collabora] support connection to several ``nextcloud-app``

bgallet/nextcloud
Valentin Lab 1 month ago
parent
commit
327b54c449
  1. 23
      collabora/hooks/nextcloud_app-relation-joined
  2. 131
      collabora/hooks/post_deploy

23
collabora/hooks/nextcloud_app-relation-joined

@ -0,0 +1,23 @@
#!/bin/bash
set -e
NEXTCLOUD_APP_CONNECTION_DIR="$state_tmpdir/$PROJECT_NAME/$SERVICE_NAME/"
mkdir -p "$NEXTCLOUD_APP_CONNECTION_DIR"
# Atomicity
i=1
while ! mkdir "$NEXTCLOUD_APP_CONNECTION_DIR"/"$i"; do ((i++)) ; done
if ! nextcloud_url=$(relation:get "$MASTER_TARGET_SERVICE_NAME":web-proxy url) || [ -z "$nextcloud_url" ]; then
nextcloud_url="http://$TARGET_SERVICE_NAME:80"
fi
config-add "\
services:
$MASTER_BASE_SERVICE_NAME:
environment:
aliasgroup$i: \"${nextcloud_url}\"
"

131
collabora/hooks/post_deploy

@ -2,54 +2,85 @@
set -e set -e
# if ! nextcloud_domain=$(relation:get "$MASTER_TARGET_SERVICE_NAME":web-proxy domain) || [ -z "$nextcloud_domain" ]; then
# ## No domain, probably no web-proxy then.
# container=$(get_running_containers_for_service "$MASTER_TARGET_SERVICE_NAME" | head -n 1)
# container_network_ip=$(get_docker_ip "$container")
# container_ip=${container_network_ip#*:}
# nextcloud_domain="${container_ip}:80"
# fi
if ! nextcloud_app_service=$(service:traverse "$MASTER_BASE_SERVICE_NAME":nextcloud-app); then
err "Couldn't find service for"\
"${DARKYELLOW}$MASTER_BASE_SERVICE_NAME${NORMAL}--${DARKCYAN}nextcloud-app${NORMAL}--> ?"
exit 1
fi
if ! collabora_domain=$(relation:get "$MASTER_BASE_SERVICE_NAME":web-proxy url) || [ -z "$collabora_domain" ]; then
## No domain, probably no web-proxy then.
# container=$(get_running_containers_for_service "$MASTER_BASE_SERVICE_NAME" | head -n 1)
# container_network_ip=$(get_docker_ip "$container")
# container_ip=${container_network_ip#*:}
collabora_domain="$SERVICE_NAME:9980"
service:relations() {
local service="$1" relation="$2" cache_file="$state_tmpdir/$FUNCNAME.cache.$1.$2" \
rn ts rc td
if [ -e "$cache_file" ]; then
#debug "$FUNCNAME: SESSION cache hit $1"
cat "$cache_file"
return 0
fi
while read-0-err E rn ts rc td; do
[ "$relation" == "$rn" ] && {
printf "%s\0" "$ts" "$rc" "$td"
}
done < <(p-err get_service_relations "$service") > "$cache_file"
if [ "$E" != 0 ]; then
rm -f "$cache_file" ## no cache
return 1
fi
cat "$cache_file"
}
export -f service:relations
export TRAVERSE_SEPARATOR=:
## Traverse on all service satisfying relation
service:traverse:all() {
local service_path="$1"
local service relation path relation
service=${service_path%%$TRAVERSE_SEPARATOR*}
path=${service_path#*$TRAVERSE_SEPARATOR}
if [[ "$path" == *$TRAVERSE_SEPARATOR* ]]; then
relation=${path%%$TRAVERSE_SEPARATOR*}
path=${path#*$TRAVERSE_SEPARATOR}
else
relation=$path
path=
fi
while read-0-err E ts _ _; do
if [ -n "$path" ]; then
service:traverse "$ts$TRAVERSE_SEPARATOR$path"
else
printf "%s\n" "$ts"
fi
done < <(p-err service:relations "${service}" "${relation}")
if [ "$E" != 0 ]; then
err "Couldn't find service for ${DARKYELLOW}$service${NORMAL}--${DARKCYAN}$relation${NORMAL}--> ?"
return 1
fi
}
export -f service:traverse:all
##
## Finish live connection for relation nextcloud_app
##
nextcloud_services=($(service:traverse:all "$MASTER_BASE_SERVICE_NAME":nextcloud-app)) || return 1
if [ ${#nextcloud_services[@]} != 0 ]; then
if ! collabora_url=$(relation:get "$MASTER_BASE_SERVICE_NAME":web-proxy url) || [ -z "$collabora_url" ]; then
collabora_url="http://$BASE_SERVICE_NAME:9980"
fi
if ! get_healthy_container_ip_for_service "$SERVICE_NAME" 9980; then
exit 17
fi
info "collabora_domain: '$collabora_url'"
for nextcloud_service in "${nextcloud_services[@]}"; do
## Activate-config will make nextcloud try to connect to collabora.
## This is why we must run this in post_deploy
compose --no-relations --no-init \
occ "$nextcloud_service" \
app:install richdocuments \; \
config:app:set --value="${collabora_url}" richdocuments wopi_url \; \
richdocuments:activate-config || return 1
done
fi fi
info "collabora_domain: '$collabora_domain'"
if ! get_healthy_container_ip_for_service "$SERVICE_NAME" 9980; then
exit 17
fi
## XXXvlab: we really need to have a state based cache thingy, because
## setting the same password each time is really time consumming.
compose --no-relations --no-init \
occ "$nextcloud_app_service" \
app:install richdocuments \; \
config:app:set --value="${collabora_domain}" richdocuments wopi_url \; \
richdocuments:activate-config
# nextcloud_domain="${nextcloud_domain//./\\.}"
# config-add "\
# services:
# $MASTER_BASE_SERVICE_NAME:
# environment:
# domain: \"${nextcloud_domain}\"
# "
Loading…
Cancel
Save