mirror of
https://github.com/element-hq/element-docker-demo.git
synced 2026-03-26 11:50:58 +03:00
a first stab at a docker compose up matrix 2.0 stack
This commit is contained in:
82
init/init.sh
Executable file
82
init/init.sh
Executable file
@@ -0,0 +1,82 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
#set -x
|
||||
|
||||
# basic script to generate templated config for our various docker images.
|
||||
# it runs in its own alpine docker image to pull in yq as a dep, and to let the whole thing be managed by docker-compose.
|
||||
|
||||
# by this point, synapse & mas should generated default config files & secrets
|
||||
# via generate-synapse-secrets.sh and generate-mas-secrets.sh
|
||||
|
||||
if [[ ! -f /secrets/synapse/${DOMAIN}.signing.key ]] # TODO: check for existence of other secrets?
|
||||
then
|
||||
# extract synapse secrets from the config and move them into ./secrets
|
||||
echo "Extracting generated synapse secrets..."
|
||||
mkdir -p /secrets/synapse
|
||||
for secret in registration_shared_secret macaroon_secret_key form_secret
|
||||
do
|
||||
yq .$secret /data/synapse/homeserver.yaml.default > /secrets/synapse/$secret
|
||||
done
|
||||
# ...and files too, just to keep all our secrets in one place
|
||||
mv /data/synapse/${DOMAIN}.signing.key /secrets/synapse
|
||||
fi
|
||||
|
||||
if [[ ! -f /secrets/mas/secrets ]] # TODO: check for existence of other secrets?
|
||||
then
|
||||
echo "Extracting generated MAS secrets..."
|
||||
mkdir -p /secrets/mas
|
||||
# extract MAS secrets from the config and move them into ./secrets
|
||||
for secret in matrix.secret
|
||||
do
|
||||
yq .$secret /data/mas/config.yaml.default > /secrets/mas/$secret
|
||||
done
|
||||
yq '(.secrets) as $s
|
||||
ireduce({}; setpath($s | path; $s))' /data/mas/config.yaml.default > /secrets/mas/secrets
|
||||
head -c16 /dev/urandom | base64 | tr -d '=' > /secrets/mas/client.secret
|
||||
fi
|
||||
|
||||
if [[ ! -f /secrets/postgres/postgres_password ]]
|
||||
then
|
||||
mkdir -p /secrets/postgres
|
||||
head -c16 /dev/urandom | base64 | tr -d '=' > /secrets/postgres/postgres_password
|
||||
fi
|
||||
|
||||
# TODO: compare the default generated config with our templates to see if our templates are stale
|
||||
# we'd have to strip out the secrets from the generated configs to be able to diff them sensibly
|
||||
|
||||
# now we have our secrets extracted from the default configs, overwrite the configs with our templates
|
||||
|
||||
# for simplicity, we just use envsubst for now rather than ansible+jinja or something.
|
||||
template() {
|
||||
dir=$1
|
||||
echo "Templating configs in $dir"
|
||||
for file in `find $dir -type f`
|
||||
do
|
||||
mkdir -p `dirname ${file/-template/}`
|
||||
envsubst < $file > ${file/-template/}
|
||||
done
|
||||
}
|
||||
|
||||
export CONFIG_HEADER="# WARNING: This file is autogenerated by element-quick-start from templates"
|
||||
(
|
||||
export SECRETS_SYNAPSE_REGISTRATION_SHARED_SECRET=$(</secrets/synapse/registration_shared_secret)
|
||||
export SECRETS_SYNAPSE_MACAROON_SECRET_KEY=$(</secrets/synapse/macaroon_secret_key)
|
||||
export SECRETS_SYNAPSE_FORM_SECRET=$(</secrets/synapse/form_secret)
|
||||
export SECRETS_MAS_MATRIX_SECRET=$(</secrets/mas/matrix.secret)
|
||||
export SECRETS_MAS_CLIENT_SECRET=$(</secrets/mas/client.secret)
|
||||
export SECRETS_POSTGRES_PASSWORD=$(</secrets/postgres/postgres_password)
|
||||
template "/data-template/synapse"
|
||||
)
|
||||
|
||||
(
|
||||
export SECRETS_MAS_SECRETS=$(</secrets/mas/secrets)
|
||||
export SECRETS_MAS_MATRIX_SECRET=$(</secrets/mas/matrix.secret)
|
||||
export SECRETS_MAS_CLIENT_SECRET=$(</secrets/mas/client.secret)
|
||||
export SECRETS_POSTGRES_PASSWORD=$(</secrets/postgres/postgres_password)
|
||||
template "/data-template/mas"
|
||||
)
|
||||
|
||||
template "/data-template/element-web"
|
||||
template "/data-template/element-call"
|
||||
template "/data-template/nginx"
|
||||
Reference in New Issue
Block a user