Browse Source

new: [nextcloud] new charm

framadate
Valentin Lab 5 years ago
parent
commit
ce9a5e912c
  1. 32
      nextcloud/actions/occ
  2. 44
      nextcloud/hooks/init
  3. 37
      nextcloud/hooks/postgres_database-relation-joined
  4. 26
      nextcloud/hooks/web_proxy-relation-joined
  5. 3
      nextcloud/lib/common
  6. 26
      nextcloud/metadata.yml
  7. 18
      nextcloud/src/occ.batch

32
nextcloud/actions/occ

@ -0,0 +1,32 @@
#!/bin/bash
if [ -z "$SERVICE_DATASTORE" ]; then
echo "This script is meant to be run through 'compose' to work properly." >&2
exit 1
fi
export COMPOSE_IGNORE_ORPHANS=True
if ! [ -e "$SERVICE_DATASTORE/var/www/html/occ" ]; then
## Here we use a nasty trick to launch only the initialisation
## part of the ``entrypoint.sh``. By setting 'apache' as first
## call argument, we satisfy the big first 'if' condition
## triggering the installation if necessary, and will fail to
## launch any apache
## Last, we do not want the relation web-proxy to run in this
## bare-minimum nextcloud run AND we will use occ to set some info
## in this very same relation.
compose --without-relation="$SERVICE_NAME":web-proxy run \
--rm --entrypoint /entrypoint.sh "$SERVICE_NAME" apache >&2 || true
fi
## occ.batch will require /var/www/html to be populated ('occ' is
## supposed to exist). For that we need to make sure nextcloud have
## be ran and setup prior to running this next command.
compose -q --no-init --no-relations run \
-v "$CHARM_PATH/src/occ.batch:/var/www/html/occ.batch" \
-T --rm -u www-data "$SERVICE_NAME" /var/www/html/occ.batch "$@" | cat

44
nextcloud/hooks/init

@ -0,0 +1,44 @@
#!/bin/bash
## Init is run on host
## For now it is run every time the script is launched, but
## it should be launched only once after build.
## Accessible variables are:
## - SERVICE_NAME Name of current service
## - DOCKER_BASE_IMAGE Base image from which this service might be built if any
## - 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
admin_user=$(options-get admin.user 2>&1) || {
admin_user="admin"
}
admin_password=$(options-get admin.password 2>&1) || {
admin_password="$(gen_password)"
}
## XXXvlab: the directory here for datadir violates DRY as it is also
## in ``metadata.yml``
init-config-add "\
$MASTER_BASE_SERVICE_NAME:
environment:
NEXTCLOUD_ADMIN_USER: $admin_user
NEXTCLOUD_ADMIN_PASSWORD: $admin_password
NEXTCLOUD_DATA_DIR: /var/lib/nextcloud/data
"
## ensuring data directories are accessible by nextcloud
uid=$(docker_get_uid "$MASTER_BASE_SERVICE_NAME" "www-data")
dirs=("$SERVICE_DATASTORE/var/lib/nextcloud/data" "$SERVICE_DATASTORE/var/www/html")
mkdir -p "${dirs[@]}"
chown -R "$uid" "${dirs[@]}"

37
nextcloud/hooks/postgres_database-relation-joined

@ -0,0 +1,37 @@
#!/bin/bash
. lib/common
set -e
PASSWORD="$(relation-get password)"
USER="$(relation-get user)"
DBNAME="$(relation-get dbname)"
ADMIN_PASSWORD=$(relation-base-compose-get admin-password 2>/dev/null) || {
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
info "Generating odoo admin password"
ADMIN_PASSWORD=$(gen_password)
fi
}
# control=$(echo -en "$USER\0$DBNAME\0$PASSWORD\0$ADMIN_PASSWORD" | md5_compat)
config-add "\
services:
$MASTER_BASE_SERVICE_NAME:
environment:
POSTGRES_HOST: $MASTER_TARGET_SERVICE_NAME
POSTGRES_DB: $DBNAME
POSTGRES_PASSWORD: $PASSWORD
POSTGRES_USER: $USER
"
# [ "$control" == "$(relation-get control 2>/dev/null)" ] && exit 0
# relation-set control "$control"
info "Configured $SERVICE_NAME code for $TARGET_SERVICE_NAME access."

26
nextcloud/hooks/web_proxy-relation-joined

@ -0,0 +1,26 @@
#!/bin/bash
set -e
DOMAIN=$(relation-get domain) || exit 1
URL="$(relation-get url)" || exit 1
PROTO="${URL%%://*}"
trusted_domains="$(
compose -q --no-relations --no-init occ "$MASTER_BASE_SERVICE_NAME" \
config:system:get trusted_domains)"
occ_opts=(
## necessary as nextcloud do not detect correctly those, and behind
## a proxy, it will generate a lot of URL that are not detected
## by means of ``ReverseProxyPass`` on apache for instance
config:system:set overwritehost --value="$DOMAIN" \;
config:system:set overwriteprotocol --value="$PROTO"
)
if ! [[ "$'\n'$trusted_domains$'\n'" == *"$'\n'$MASTER_BASE_SERVICE_NAME$'\n'"* ]]; then
trusted_index=$(echo "$trusted_domains" | wc -l)
debug "Adding $MASTER_TARGET_SERVICE_NAME to ${WHITE}trusted_domains${NORMAL}."
occ_opts+=( \; config:system:set trusted_domains "$trusted_index" --value="$MASTER_BASE_SERVICE_NAME")
fi
compose --no-relations --no-init occ "$MASTER_BASE_SERVICE_NAME" "${occ_opts[@]}"

3
nextcloud/lib/common

@ -0,0 +1,3 @@
# -*- mode: shell-script -*-

26
nextcloud/metadata.yml

@ -0,0 +1,26 @@
docker-image: docker.0k.io/nextcloud:1.0.0
data-resources:
- /var/www/html
- /var/lib/nextcloud/data
config-resources:
- /var/www/html/config
provides:
nextcloud-app:
uses:
postgres-database:
#constraint: required | recommended | optional
#auto: pair | summon | none ## default: pair
constraint: required
auto: summon
solves:
database: "main storage"
web-proxy:
#constraint: required | recommended | optional
#auto: pair | summon | none ## default: pair
constraint: required
auto: summon
solves:
proxy: "Public access"
default-options:
target: !var-expand ${MASTER_BASE_SERVICE_NAME}:80

18
nextcloud/src/occ.batch

@ -0,0 +1,18 @@
#!/bin/bash
occ() {
/var/www/html/occ --no-warnings "$@"
}
args=()
for arg in "$@"; do
if [ "$arg" == ";" ]; then
echo "running: occ " "${args[@]}" >&2
occ "${args[@]}" # || exit 1
args=()
continue
fi
args+=("$arg")
done
occ "${args[@]}"
Loading…
Cancel
Save