From 95981678c863cb37869181ac42a952d680d2a54c Mon Sep 17 00:00:00 2001 From: Boris Gallet Date: Thu, 14 Dec 2023 21:34:37 +0100 Subject: [PATCH] new: [rallly] add charm --- rallly/README.org | 29 ++++++++++ rallly/hooks/init | 38 +++++++++++++ .../hooks/postgres_database-relation-joined | 18 +++++++ rallly/hooks/smtp_server-relation-joined | 54 +++++++++++++++++++ rallly/hooks/web_proxy-relation-joined | 12 +++++ rallly/metadata.yml | 32 +++++++++++ rallly/resources/app/docker-start.sh | 8 +++ 7 files changed, 191 insertions(+) create mode 100644 rallly/README.org create mode 100755 rallly/hooks/init create mode 100755 rallly/hooks/postgres_database-relation-joined create mode 100755 rallly/hooks/smtp_server-relation-joined create mode 100755 rallly/hooks/web_proxy-relation-joined create mode 100644 rallly/metadata.yml create mode 100755 rallly/resources/app/docker-start.sh diff --git a/rallly/README.org b/rallly/README.org new file mode 100644 index 0000000..f6c9763 --- /dev/null +++ b/rallly/README.org @@ -0,0 +1,29 @@ +# -*- ispell-local-dictionary: "english" -*- + +* Info + +From: https://github.com/lukevella/rallly + +* Usage + +Config info: https://support.rallly.co/self-hosting/configuration-options + +Requires a =smtp-server= provider to be functional, you can use +=smtp-stub= charm to provide information to externally managed =SMTP=. + +#+begin_src yaml +rallly: + options: + support-email: support@myhost.com # is used as the sender of auth emails + #allowed-emails: "*@example.coop, test@example2.com" + +smtp-stub: + options: + host: smtp.myhost.com + port: 465 + connection-security: "ssl/tls" + auth-method: password + user: myuser + password: myp4ssw0rd +#+end_src + diff --git a/rallly/hooks/init b/rallly/hooks/init new file mode 100755 index 0000000..ae52654 --- /dev/null +++ b/rallly/hooks/init @@ -0,0 +1,38 @@ +#!/bin/bash + +set -e + +## bug: https://github.com/adoptium/containers/issues/215#issuecomment-1142046045 +docker_version=$(docker info --format '{{.ServerVersion}}') +if ! version_gt "$docker_version" 20.10.0; then + err "Sorry, $SERVICE_NAME require docker version >= 20.10 (current: $docker_version)" + exit 1 +fi + + +PASSWORD_FILE="$SERVICE_DATASTORE"/secret-password + +if ! [ -f "$PASSWORD_FILE" ]; then + info "Generating secret password" + mkdir -p "${PASSWORD_FILE%/*}" + umask 077 + openssl rand -base64 32 > "$PASSWORD_FILE" +else + info "Using existing secret password" +fi + +secret_password=$(cat "$PASSWORD_FILE") +support_email=$(options-get support-email) +allowed_emails=$(options-get allowed-emails "") || true + +if [ -z "$allowed_emails" ]; then + allowed_emails="*" +fi + +init-config-add "\ + $MASTER_BASE_SERVICE_NAME: + environment: + SECRET_PASSWORD: \"$secret_password\" + SUPPORT_EMAIL: \"$support_email\" + ALLOWED_EMAILS: \"$allowed_emails\" +" diff --git a/rallly/hooks/postgres_database-relation-joined b/rallly/hooks/postgres_database-relation-joined new file mode 100755 index 0000000..d46bff4 --- /dev/null +++ b/rallly/hooks/postgres_database-relation-joined @@ -0,0 +1,18 @@ +#!/bin/bash + +set -e + +PASSWORD="$(relation-get password)" +USER="$(relation-get user)" +DBNAME="$(relation-get dbname)" + + +config-add "\ +services: + $MASTER_BASE_SERVICE_NAME: + environment: + DATABASE_URL: \"postgres://$USER:$PASSWORD@$TARGET_SERVICE_NAME/$DBNAME\" +" + + +info "Configured $SERVICE_NAME code for $TARGET_SERVICE_NAME access." diff --git a/rallly/hooks/smtp_server-relation-joined b/rallly/hooks/smtp_server-relation-joined new file mode 100755 index 0000000..8b64b31 --- /dev/null +++ b/rallly/hooks/smtp_server-relation-joined @@ -0,0 +1,54 @@ +#!/bin/bash + +set -e + +host=$(relation-get host) +port=$(relation-get port) +connection_security=$(relation-get connection-security) +auth_method=$(relation-get auth-method) + +declare -A ENV +case "$connection_security" in + "none") + secure="false" + ;; + "starttls") + secure="true" + ENV[SMTP_TLS_ENABLED]="true" + ;; + "ssl/tls") + secure="true" + ENV[SMTP_SECURE]="true" + ENV[SMTP_TLS_ENABLED]="true" + ;; + *) + error "Unsupported connection security: $connection_security" + exit 1 + ;; +esac +case "$auth_method" in + "none") + : + ;; + "password") + login=$(relation-get login) || true + password=$(relation-get password) || true + ENV[SMTP_USER]="$login" + ENV[SMTP_PWD]="$password" + ;; + *) + error "Unsupported auth method: $auth_method" + exit 1 + ;; +esac + + +config-add "\ +services: + $MASTER_BASE_SERVICE_NAME: + environment: + SMTP_HOST: \"$host\" + SMTP_PORT: \"$port\" +$(for key in "${!ENV[@]}"; do echo " $key: \"${ENV[$key]//\$/\$\$}\""; done) +" + diff --git a/rallly/hooks/web_proxy-relation-joined b/rallly/hooks/web_proxy-relation-joined new file mode 100755 index 0000000..625d475 --- /dev/null +++ b/rallly/hooks/web_proxy-relation-joined @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +url=$(relation-get url) + +config-add "\ +services: + $MASTER_BASE_SERVICE_NAME: + environment: + NEXT_PUBLIC_BASE_URL: \"$url\" +" \ No newline at end of file diff --git a/rallly/metadata.yml b/rallly/metadata.yml new file mode 100644 index 0000000..61d2965 --- /dev/null +++ b/rallly/metadata.yml @@ -0,0 +1,32 @@ + +docker-image: docker.0k.io/rallly:3.3.0 + +charm-resources: + - /app/docker-start.sh + +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: + - pgcrypto + - citext + web-proxy: + constraint: recommended + auto: pair + solves: + proxy: "Public access" + default-options: + target: !var-expand ${MASTER_BASE_SERVICE_NAME}:3000 + smtp-server: + constraint: required + auto: pair + solves: + proxy: "Public access" diff --git a/rallly/resources/app/docker-start.sh b/rallly/resources/app/docker-start.sh new file mode 100755 index 0000000..71c34cb --- /dev/null +++ b/rallly/resources/app/docker-start.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e +prisma migrate deploy --schema=./prisma/schema.prisma +if [ -z "$NEXT_PUBLIC_BASE_URL" ]; then + IPS=($(hostname -I)) + NEXT_PUBLIC_BASE_URL="http://${IPS[0]}:3000" +fi +NEXTAUTH_URL=$NEXT_PUBLIC_BASE_URL node apps/web/server.js