From 896bfeb6e5c4c34c2314135d496cf705960e284d Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Tue, 16 Oct 2018 21:38:43 +0200 Subject: [PATCH] new: [mattermost] new charm --- mattermost/hooks/init | 26 +++++++++++++++++++ .../hooks/postgres_database-relation-joined | 26 +++++++++++++++++++ mattermost/metadata.yml | 16 ++++++++++++ 3 files changed, 68 insertions(+) create mode 100755 mattermost/hooks/init create mode 100755 mattermost/hooks/postgres_database-relation-joined create mode 100644 mattermost/metadata.yml diff --git a/mattermost/hooks/init b/mattermost/hooks/init new file mode 100755 index 0000000..c27e453 --- /dev/null +++ b/mattermost/hooks/init @@ -0,0 +1,26 @@ +#!/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 + + +## +## checking permission of base directory +## + +dirs=("$SERVICE_CONFIGSTORE/mattermost/"{config,plugins} "$SERVICE_DATASTORE/mattermost/"{data,logs}) +for dir in "${dirs[@]}"; do + mkdir -p "$dir" + find "$dir" \! -uid 2000 -exec chown -v 2000 {} \; + find "$dir" \! -gid 2000 -exec chgrp -v 2000 {} \; +done diff --git a/mattermost/hooks/postgres_database-relation-joined b/mattermost/hooks/postgres_database-relation-joined new file mode 100755 index 0000000..a751df5 --- /dev/null +++ b/mattermost/hooks/postgres_database-relation-joined @@ -0,0 +1,26 @@ +#!/bin/bash + +set -e + +PASSWORD="$(relation-get password)" +USER="$(relation-get user)" +DBNAME="$(relation-get dbname)" + +control=$(echo -en "$USER\0$DBNAME\0$PASSWORD" | md5_compat) + +config-add "\ +services: + $MASTER_BASE_SERVICE_NAME: + environment: + DB_HOST: $MASTER_TARGET_SERVICE_NAME + MM_DBNAME: $DBNAME + MM_PASSWORD: $PASSWORD + MM_USERNAME: $USER +" + +[ "$control" == "$(relation-get control 2>/dev/null)" ] && exit 0 + + +relation-set control "$control" + +info "Configured $SERVICE_NAME code for $TARGET_SERVICE_NAME access." diff --git a/mattermost/metadata.yml b/mattermost/metadata.yml new file mode 100644 index 0000000..b90367f --- /dev/null +++ b/mattermost/metadata.yml @@ -0,0 +1,16 @@ +# description: "Mattermost" +# maintainer: "Valentin Lab " +## We fix image here to be sure of what we install +docker-image: docker.0k.io/mattermost-team +# docker-image: docker.0k.io/mattermost-enterprise +config-resources: + - /mattermost/config + - /mattermost/plugins +data-resources: + - /mattermost/data + - /mattermost/logs +host-resources: + - /etc/localtime:ro + +docker-compose: + restart: unless-stopped \ No newline at end of file