|
@ -17,37 +17,38 @@ function _create() { |
|
|
echo "creating discourse instance for <$shortname> ... " |
|
|
echo "creating discourse instance for <$shortname> ... " |
|
|
echo "initialize discourse $shortname $longname ... OK" |
|
|
echo "initialize discourse $shortname $longname ... OK" |
|
|
|
|
|
|
|
|
|
|
|
if ! (db-psql list | grep -q "$longname"); then |
|
|
|
|
|
echo "create empty database <$longname> ... " |
|
|
|
|
|
db-psql create "$longname" |
|
|
|
|
|
db-psql use "$longname" "CREATE EXTENSION IF NOT EXISTS hstore" |
|
|
|
|
|
db-psql use "$longname" "CREATE EXTENSION IF NOT EXISTS pg_trgm" |
|
|
|
|
|
echo "create empty database <$longname> ... OK" |
|
|
|
|
|
else |
|
|
|
|
|
echo "database already exists!" |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
admin_username=$(load_yaml_from_expanded services[\""$domain"\"][\""$subdomain"\"].data.admin.username) |
|
|
admin_username=$(load_yaml_from_expanded services[\""$domain"\"][\""$subdomain"\"].data.admin.username) |
|
|
admin_email=$(load_yaml_from_expanded services[\""$domain"\"][\""$subdomain"\"].data.admin.email) |
|
|
admin_email=$(load_yaml_from_expanded services[\""$domain"\"][\""$subdomain"\"].data.admin.email) |
|
|
admin_password=$(load_yaml_from_expanded services[\""$domain"\"][\""$subdomain"\"].data.admin.password) |
|
|
admin_password=$(load_yaml_from_expanded services[\""$domain"\"][\""$subdomain"\"].data.admin.password) |
|
|
redis_password=$(load_yaml_from_expanded credential.redis) |
|
|
redis_password=$(load_yaml_from_expanded credential.redis) |
|
|
|
|
|
|
|
|
mkdir -p "$MIAOU_CONFIGDIR/apps/discourse" |
|
|
mkdir -p "$MIAOU_CONFIGDIR/apps/discourse" |
|
|
APP_REDIS_PASSWORD=$redis_password APP_DOMAIN=$domain APP_SUBDOMAIN=$subdomain APP_FQDN=$fqdn APP_PORT=$port APP_NAME=$longname tera -e --env-key env -t "$MIAOU_BASEDIR/templates/apps/discourse/forum.yml.j2" -o "$MIAOU_CONFIGDIR/apps/discourse/$longname.yml" "$MIAOU_CONFIGDIR/miaou.expanded.yaml" |
|
|
|
|
|
|
|
|
APP_REDIS_PASSWORD=$redis_password APP_DOMAIN=$domain APP_SUBDOMAIN=$subdomain APP_FQDN=$fqdn APP_PORT=$port APP_NAME=$longname tera -e --env-key env -t "$MIAOU_BASEDIR/templates/apps/discourse/forum.yml.j2" -o "$MIAOU_CONFIGDIR/apps/discourse/$longname.yml" "$MIAOU_CONFIGDIR/miaou.expanded.yaml" >/dev/null |
|
|
echo "creating templates ... OK" |
|
|
echo "creating templates ... OK" |
|
|
|
|
|
|
|
|
echo "copying files to container <$container> ... " |
|
|
echo "copying files to container <$container> ... " |
|
|
lxc file push --uid 0 --gid 0 "$MIAOU_CONFIGDIR/apps/discourse/$longname.yml" "$container/var/discourse/containers/$longname.yml" |
|
|
|
|
|
|
|
|
lxc file push --uid 0 --gid 0 --mode 600 "$MIAOU_CONFIGDIR/apps/discourse/$longname.yml" "$container/var/discourse/containers/$longname.yml" |
|
|
echo "copying files to container <$container> ... OK" |
|
|
echo "copying files to container <$container> ... OK" |
|
|
|
|
|
|
|
|
if ! (db-psql list | grep -q "$longname"); then |
|
|
|
|
|
echo "create empty database <$longname> ... " |
|
|
|
|
|
db-psql create "$longname" |
|
|
|
|
|
db-psql use "$longname" "CREATE EXTENSION IF NOT EXISTS hstore" |
|
|
|
|
|
db-psql use "$longname" "CREATE EXTENSION IF NOT EXISTS pg_trgm" |
|
|
|
|
|
echo "create empty database <$longname> ... OK" |
|
|
|
|
|
else |
|
|
|
|
|
echo "database already exists!" |
|
|
|
|
|
fi |
|
|
|
|
|
|
|
|
console="u=User.create_with(email: '$admin_email', password: '$admin_password').find_or_initialize_by(username: '$admin_username'); u.save; u.activate" |
|
|
|
|
|
# console="puts User.count" |
|
|
|
|
|
activate_admin="rails runner \"$console\"" |
|
|
|
|
|
|
|
|
echo "build docker container $longname ..." |
|
|
echo "build docker container $longname ..." |
|
|
lxc exec "$container" -- bash <<EOF |
|
|
|
|
|
set -Eeuo pipefail |
|
|
|
|
|
cd /var/discourse |
|
|
|
|
|
./launcher rebuild $longname |
|
|
|
|
|
command='u=User.create_with(email: "$admin_email", password: "$admin_password").find_or_initialize_by(username: "$admin_username"); u.save; u.activate' |
|
|
|
|
|
./launcher run $longname "rails runner '\$command'" |
|
|
|
|
|
EOF |
|
|
|
|
|
|
|
|
lxc exec "$container" -- /var/discourse/launcher rebuild "$longname" |
|
|
|
|
|
|
|
|
|
|
|
echo "initialize admin user <$admin_username>" |
|
|
|
|
|
lxc exec "$container" -- /var/discourse/launcher run "$longname" "$activate_admin" |
|
|
echo "initialize discourse $longname ... OK" |
|
|
echo "initialize discourse $longname ... OK" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|