From 81768fd0f8ba7f9c94c63878ec02b0985fd5339f Mon Sep 17 00:00:00 2001 From: Boris Gallet Date: Thu, 7 Dec 2023 15:08:47 +0100 Subject: [PATCH] new: [discourse] add charm --- discourse/README.org | 31 +++++++++++ discourse/hooks/init | 22 ++++++++ .../hooks/postgres_database-relation-joined | 20 +++++++ .../hooks/redis_database-relation-joined | 15 ++++++ discourse/hooks/web_proxy-relation-joined | 13 +++++ discourse/metadata.yml | 52 +++++++++++++++++++ 6 files changed, 153 insertions(+) create mode 100644 discourse/README.org create mode 100755 discourse/hooks/init create mode 100755 discourse/hooks/postgres_database-relation-joined create mode 100644 discourse/hooks/redis_database-relation-joined create mode 100755 discourse/hooks/web_proxy-relation-joined create mode 100644 discourse/metadata.yml diff --git a/discourse/README.org b/discourse/README.org new file mode 100644 index 0000000..feb8cb1 --- /dev/null +++ b/discourse/README.org @@ -0,0 +1,31 @@ +# -*- ispell-local-dictionary: "english" -*- + +* Info + +From: https://hub.docker.com/r/bitnami/discourse + +* Usage + +Need a complete SMTP config to be functionnal + +#+begin_src yaml +rallly: + charm: rallly + docker-compose: + options: + secret: <> + support_email: # email used for support + # OPTIONAL + allowed_emails: "*@example.coop, test@example2.com" # All by default if not set + + +smtp-extern: + charm: smtp-extern + options: + host: + port: <465> + secure: "true" + user: + password: + +#+end_src \ No newline at end of file diff --git a/discourse/hooks/init b/discourse/hooks/init new file mode 100755 index 0000000..49e4da2 --- /dev/null +++ b/discourse/hooks/init @@ -0,0 +1,22 @@ +#!/bin/bash + +set -e + +username="$(options-get username)" || exit 1 +password="$(options-get password)" || exit 1 +email="$(options-get email)" || exit 1 +first_name="$(options-get first_name)" || exit 1 +last_name="$(options-get last_name)" || exit 1 +site_name="$(options-get site_name)" || exit 1 + + +init-config-add "\ +$SERVICE_NAME: + environment: + DISCOURSE_USERNAME: $username + DISCOURSE_PASSWORD: $password + DISCOURSE_EMAIL: $email + DISCOURSE_FIRST_NAME: $first_name + DISCOURSE_LAST_NAME: $last_name + DISCOURSE_SITE_NAME: $site_name +" diff --git a/discourse/hooks/postgres_database-relation-joined b/discourse/hooks/postgres_database-relation-joined new file mode 100755 index 0000000..b82c158 --- /dev/null +++ b/discourse/hooks/postgres_database-relation-joined @@ -0,0 +1,20 @@ +#!/bin/bash + +set -e + +PASSWORD="$(relation-get password)" +USER="$(relation-get user)" +DBNAME="$(relation-get dbname)" + + +config-add "\ +services: + $MASTER_BASE_SERVICE_NAME: + environment: + DISCOURSE_DATABASE_USER: $USER + DISCOURSE_DATABASE_PASSWORD: $PASSWORD + DISCOURSE_DATABASE_HOST: $TARGET_SERVICE_NAME + DISCOURSE_DATABASE_NAME: $DBNAME +" + +info "Configured $SERVICE_NAME code for $TARGET_SERVICE_NAME access." diff --git a/discourse/hooks/redis_database-relation-joined b/discourse/hooks/redis_database-relation-joined new file mode 100644 index 0000000..5ef3449 --- /dev/null +++ b/discourse/hooks/redis_database-relation-joined @@ -0,0 +1,15 @@ +#!/bin/bash +set -e +PASSWORD="$(relation-get password)" +USER="$(relation-get user)" + +# Configure Discourse to use a separate Redis server +config-add "\ +services: + $MASTER_BASE_SERVICE_NAME: + environment: + DISCOURSE_REDIS_USER: $USER + DISCOURSE_REDIS_PASSWORD: $PASSWORD + DISCOURSE_REDIS_HOST: $TARGET_SERVICE_NAME +" +info "Configured $SERVICE_NAME code for $TARGET_SERVICE_NAME access." \ No newline at end of file diff --git a/discourse/hooks/web_proxy-relation-joined b/discourse/hooks/web_proxy-relation-joined new file mode 100755 index 0000000..236a89d --- /dev/null +++ b/discourse/hooks/web_proxy-relation-joined @@ -0,0 +1,13 @@ +#!/bin/bash + +set -e + +DOMAIN=$(relation-get domain) || exit 1 + +config-add "\ +services: + $MASTER_BASE_SERVICE_NAME: + environment: + DISCOURSE_HOST: $DOMAIN +" + diff --git a/discourse/metadata.yml b/discourse/metadata.yml new file mode 100644 index 0000000..21c0875 --- /dev/null +++ b/discourse/metadata.yml @@ -0,0 +1,52 @@ +docker-image: bitnami/discourse:latest +data-resources: + - /bitnami/discourse +data-config: + - /templates/ + +uses: + postgres-database: + #constraint: required | recommended | optional + #auto: pair | summon | none ## default: pair + constraint: required + auto: summon + solves: + database: "main storage" + options: + extensions: + - hstore + - pg_trgm + redis-database: + constraint: required + auto: summon + solves: + redis: "short time storage" + smtp-server: + constraint: required + auto: pair + solves: + smtp: "mail sending" + 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}:3000 + backup: + constraint: recommended + auto: pair + solves: + backup: "Automatic regular backup" + default-options: + ## First pattern matching wins, no pattern matching includes. + ## include-patterns are checked first, then exclude-patterns + ## Patterns rules: + ## - ending / for directory + ## - '*' authorized + ## - must start with a '/', will start from $SERVICE_DATASTORE + #exclude-patterns: + # - "/var/lib/odoo/sessions/" +