Browse Source

new: [rallly] add charm

pull/36/head
Boris Gallet 1 year ago
committed by Valentin Lab
parent
commit
95981678c8
  1. 29
      rallly/README.org
  2. 38
      rallly/hooks/init
  3. 18
      rallly/hooks/postgres_database-relation-joined
  4. 54
      rallly/hooks/smtp_server-relation-joined
  5. 12
      rallly/hooks/web_proxy-relation-joined
  6. 32
      rallly/metadata.yml
  7. 8
      rallly/resources/app/docker-start.sh

29
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

38
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\"
"

18
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."

54
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)
"

12
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\"
"

32
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"

8
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
Loading…
Cancel
Save