smtp: config keycloak, mastodon, matrix, and mobilizon

single-dockerfile
Trammell Hudson 3 years ago
parent 8e0a8b7304
commit b85d73c379
  1. 1
      .gitignore
  2. 10
      env.smtp.template
  3. 27
      keycloak/setup
  4. 6
      mastodon/env.production
  5. 11
      mastodon/setup
  6. 20
      matrix/setup
  7. 12
      mobilizon/setup

1
.gitignore vendored

@ -1,3 +1,4 @@
.*.swp .*.swp
data data
*.secrets *.secrets
env.smtp

@ -0,0 +1,10 @@
#
# To enable sending emails, please make an account at sendgrind (free should be fine)
# and copy the API key into the SMTP password. If you don't do this first, you'll
# have to setup it later, which will involve some manual effort to configure each
# sub-site.
#
SMTP_SERVER=smtp.sendgrid.net
SMTP_PORT=587
SMTP_USER=apikey
SMTP_PASSWORD=LONG-STRING-GOES-HERE

@ -1,11 +1,12 @@
#!/bin/bash #!/bin/bash
die() { echo >&2 "ERROR: $@" ; exit 1 ; } die() { echo >&2 "keycloak: ERROR: $@" ; exit 1 ; }
info() { echo >&2 "$@" ; } info() { echo >&2 "keycloak: $@" ; }
DIRNAME="$(dirname $0)" DIRNAME="$(dirname $0)"
cd "$DIRNAME" cd "$DIRNAME"
source ../env.production source ../env.production
source ./env.production source ./env.production
source "../env.smtp" 2>/dev/null
SECRETS="../data/keycloak/env.secrets" SECRETS="../data/keycloak/env.secrets"
@ -82,6 +83,28 @@ docker-compose exec -T keycloak \
} }
EOF EOF
if [ -n "$SMTP_SERVER" ]; then
info "configuring email"
docker-compose exec -T keycloak \
/opt/keycloak/bin/kcadm.sh update "realms/$REALM" \
-f - <<EOF || die "unable to configure email"
{
"resetPasswordAllowed": "true",
"smtpServer" : {
"auth" : "true",
"starttls" : "true",
"user" : "$SMTP_USER",
"password" : "$SMTP_PASSWORD",
"port" : "$SMTP_PORT",
"host" : "$SMTP_SERVER",
"from" : "keycloak@$DOMAIN_NAME",
"fromDisplayName" : "Keycloak @ $DOMAIN_NAME",
"ssl" : "false"
}
}
EOF
fi
info "Create an admin user in realm" info "Create an admin user in realm"
docker-compose exec -T keycloak \ docker-compose exec -T keycloak \

@ -57,11 +57,7 @@ ES_PASS=password
# Sending mail # Sending mail
# ------------ # ------------
SMTP_SERVER=smtp.mailgun.org # configured in env.secrets
SMTP_PORT=587
SMTP_LOGIN=
SMTP_PASSWORD=
SMTP_FROM_ADDRESS=notifications@example.com
# File storage (optional) # File storage (optional)
# ----------------------- # -----------------------

@ -6,6 +6,7 @@ DIRNAME="$(dirname $0)"
cd "$DIRNAME" cd "$DIRNAME"
source ../env.production source ../env.production
source ./env.production source ./env.production
source "../env.smtp" 2>/dev/null
mkdir -p ../data/mastodon/system mkdir -p ../data/mastodon/system
chmod 777 ../data/mastodon/system chmod 777 ../data/mastodon/system
@ -37,6 +38,16 @@ SECRET_KEY_BASE=$(openssl rand -hex 32)
OTP_SECRET=$(openssl rand -hex 32) OTP_SECRET=$(openssl rand -hex 32)
EOF EOF
if [ -n "$SMTP_SERVER" ]; then
cat <<EOF >> "$SECRETS"
SMTP_SERVER=$SMTP_SERVER
SMTP_PORT=$SMTP_PORT
SMTP_LOGIN=$SMTP_USER
SMTP_PASSWORD=$SMTP_PASSWORD
SMTP_FROM_ADDRESS=mastodon@$DOMAIN_NAME
EOF
fi
info "mastodon: creating push keys" info "mastodon: creating push keys"
docker-compose run --rm mastodon \ docker-compose run --rm mastodon \
rails mastodon:webpush:generate_vapid_key \ rails mastodon:webpush:generate_vapid_key \

@ -1,9 +1,11 @@
#!/bin/bash #!/bin/bash
die() { echo >&2 "$@" ; exit 1 ; } die() { echo >&2 "matrix: ERROR $@" ; exit 1 ; }
info() { echo >&2 "matrix: $@" ; }
DIRNAME="$(dirname $0)" DIRNAME="$(dirname $0)"
cd "$DIRNAME" cd "$DIRNAME"
source ../env.production || die "no top levle env?" source ../env.production || die "no top levle env?"
source ../env.smtp 2>/dev/null
source env.production || die "no local env?" source env.production || die "no local env?"
DATA="../data/matrix" DATA="../data/matrix"
@ -53,6 +55,21 @@ oidc_providers:
display_name_template: "{{ user.name }}" display_name_template: "{{ user.name }}"
EOF EOF
if [ -n "$SMTP_SERVER" ]; then
info "configuring email"
cat <<EOF >> "$HOMESERVER_YAML"
email:
smtp_host: ${SMTP_SERVER}
smtp_port: ${SMTP_PORT}
smtp_user: "${SMTP_USER}"
smtp_pass: "${SMTP_PASSWORD}"
require_transport_security: true
notif_from: "%(app)s matrix homeserver <noreply@${DOMAIN_NAME}>"
app_name: ${DOMAIN_NAME}
EOF
fi
../keycloak/client-delete 'synapse' 2>/dev/null ../keycloak/client-delete 'synapse' 2>/dev/null
../keycloak/client-create << EOF || die "unable to create client id" ../keycloak/client-create << EOF || die "unable to create client id"
@ -67,4 +84,5 @@ EOF
} }
EOF EOF
docker-compose up -d || die "matrix: unable to start container" docker-compose up -d || die "matrix: unable to start container"

@ -5,6 +5,7 @@ DIRNAME="$(dirname $0)"
cd "$DIRNAME" cd "$DIRNAME"
source ../env.production || die "no top level env?" source ../env.production || die "no top level env?"
source env.production || die "no local env?" source env.production || die "no local env?"
source ../env.smtp 2>/dev/null
DATA="../data/mobilizon" DATA="../data/mobilizon"
SECRETS="$DATA/env.secrets" SECRETS="$DATA/env.secrets"
@ -31,6 +32,17 @@ MOBILIZON_INSTANCE_SECRET_KEY=$(openssl rand -hex 20)
MOBILIZON_CLIENT_SECRET=${CLIENT_SECRET} MOBILIZON_CLIENT_SECRET=${CLIENT_SECRET}
EOF EOF
if [ -n "$SMTP_SERVER" ]; then
cat <<EOF >> "$SECRETS"
MOBILIZON_INSTANCE_EMAIL=events@${DOMAIN_NAME}
MOBILIZON_REPLY_EMAIL=noreply@${DOMAIN_NAME}
MOBILIZON_SMTP_SERVER=${SMTP_SERVER}
MOBILIZON_SMTP_PORT=${SMTP_PORT}
MOBILIZON_SMTP_USERNAME=${SMTP_USER}
MOBILIZON_SMTP_PASSWORD=${SMTP_PASSWORD}
EOF
fi
../keycloak/client-delete mobilizon ../keycloak/client-delete mobilizon
../keycloak/client-create <<EOF || die "unable to create client" ../keycloak/client-create <<EOF || die "unable to create client"

Loading…
Cancel
Save