Browse Source

new: [cyclos] new charm

Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>
dev1
Valentin Lab 4 years ago
parent
commit
abf2b548af
  1. 47
      cyclos/hooks/init
  2. 19
      cyclos/hooks/postgres_database-relation-joined
  3. 14
      cyclos/lib/common
  4. 41
      cyclos/metadata.yml
  5. 14
      postgres/lib/common

47
cyclos/hooks/init

@ -0,0 +1,47 @@
#!/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
# Please note that postgres detect on its own if its datadir needs to be populated
. lib/common
if ! [ -f "$HOST_CYCLOS_CONFIG" ]; then
## create cyclos.properties
cyclos:build || exit 1
fi
if ! [ -f "$HOST_CYCLOS_CONFIG" ]; then
err "No file '$HOST_CYCLOS_CONFIG'."
return 1
fi
PROPS=(
cyclos.header.remoteAddress X-Forwarded-For
cyclos.header.protocol X-Forwarded-Proto
)
while read-0 label value; do
sed -ri "s/^($label\s+=)\s*.*/\1 $value/g" "$HOST_CYCLOS_CONFIG" >&2
done < <(array_values_to_stdin PROPS)
init-config-add "
$SERVICE_NAME:
environment:
JAVA_OPTS: |
-Dcyclos.cors.origin=*
-Dcyclos.header.remoteAddress=X-Forwarded-For
-Dcyclos.header.protocol=X-Forwarded-Proto
"

19
cyclos/hooks/postgres_database-relation-joined

@ -0,0 +1,19 @@
#!/bin/bash
set -e
PASSWORD="$(relation-get password)"
USER="$(relation-get user)"
DBNAME="$(relation-get dbname)"
config-add "\
services:
$MASTER_BASE_SERVICE_NAME:
environment:
DB_HOST: \"$MASTER_TARGET_SERVICE_NAME\"
DB_NAME: \"$DBNAME\"
DB_USER: \"$USER\"
DB_PASSWORD: \"$PASSWORD\"
"
info "Configured $SERVICE_NAME code for $TARGET_SERVICE_NAME access."

14
cyclos/lib/common

@ -0,0 +1,14 @@
# -*- mode: bash -*-
CYCLOS_CONFIG="/usr/local/cyclos/WEB-INF/classes/cyclos.properties"
HOST_CYCLOS_CONFIG="$SERVICE_CONFIGSTORE$CYCLOS_CONFIG"
cyclos:build() {
docker pull "$DOCKER_BASE_IMAGE" || return 1
mkdir -p "$(dirname "$HOST_CYCLOS_CONFIG")"
container_id=$(docker run -d --entrypoint true "$DOCKER_BASE_IMAGE") || return 1
mkdir -p "$(dirname "$HOST_CYCLOS_CODE")" &&
docker cp "$container_id":"$CYCLOS_CONFIG" "$HOST_CYCLOS_CONFIG" &&
docker rm "$container_id"
}

41
cyclos/metadata.yml

@ -0,0 +1,41 @@
## Based on cyclos/cyclos:4.13.2
docker-image: docker.0k.io/cyclos:4.13.2
config-resources:
- /usr/local/cyclos/WEB-INF/classes/cyclos.properties
data-resources:
- /var/log/cyclos
default-options:
uses:
postgres-database:
#constraint: required | recommended | optional
#auto: pair | summon | none ## default: pair
constraint: required
auto: summon
solves:
database: "main storage"
default-options:
extensions:
- cube
- earthdistance
- postgis
- unaccent
log-rotate:
#constraint: required | recommended | optional
#auto: pair | summon | none ## default: pair
constraint: recommended
auto: pair
solves:
unmanaged-logs: "in docker logs"
#default-options:
web-proxy:
#constraint: required | recommended | optional
#auto: pair | summon | none ## default: pair
constraint: recommended
auto: pair
solves:
proxy: "Public access"
default-options:
target: !var-expand ${MASTER_BASE_SERVICE_NAME}:8080

14
postgres/lib/common

@ -73,7 +73,19 @@ db_install_extensions() {
while [ "$#" != 0 ]; do
case "$1" in
postgis)
ddb -d "$dbname" < <(echo "CREATE EXTENSION postgis; CREATE EXTENSION postgis_topology;") || return 1
if out=$(ddb -d "$dbname" < <(echo "SELECT extname
FROM pg_extension
WHERE extname = 'postgis';")); then
if [ "$out" ]; then
info "PostGIS already installed."
shift
continue
fi
fi
ddb -d "$dbname" < <(echo "CREATE EXTENSION IF NOT EXISTS postgis;
CREATE EXTENSION IF NOT EXISTS postgis_topology;") || return 1
dcmd /bin/bash -c "psql -d '$dbname' -v ON_ERROR_STOP=1 -f /usr/local/share/postgresql/contrib/postgis-*/legacy.sql" || return 1
info "Installed postgis extensions on database '$dbname'."
;;

Loading…
Cancel
Save