2019-11-15 18:00:26 +01:00
|
|
|
#!/bin/sh
|
|
|
|
set -ev
|
|
|
|
|
2020-03-17 09:18:13 +01:00
|
|
|
# Volumes
|
|
|
|
POSTGRES_DATA="${VOLUMES_DIR}/decidim/postgres_data"
|
|
|
|
DECIDIM_CONF="${VOLUMES_DIR}/decidim/decidim_conf"
|
|
|
|
DECIDIM_DATA="${VOLUMES_DIR}/decidim/decidim_data"
|
|
|
|
|
2019-11-15 18:00:26 +01:00
|
|
|
# Create Postgres instance
|
2020-03-17 09:18:13 +01:00
|
|
|
install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA}
|
|
|
|
spoc-container exec decidim-postgres -- initdb -D /var/lib/postgresql
|
2019-11-15 18:00:26 +01:00
|
|
|
|
|
|
|
# Configure Postgres
|
2020-03-17 09:18:13 +01:00
|
|
|
install -o 105432 -g 105432 -m 600 postgres_data/postgresql.conf ${POSTGRES_DATA}/postgresql.conf
|
|
|
|
install -o 105432 -g 105432 -m 600 postgres_data/pg_hba.conf ${POSTGRES_DATA}/pg_hba.conf
|
2019-11-15 18:00:26 +01:00
|
|
|
|
|
|
|
# Create database
|
|
|
|
export DECIDIM_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
|
2020-03-17 09:18:13 +01:00
|
|
|
spoc-container start decidim-postgres
|
|
|
|
envsubst <createdb.sql | spoc-container exec decidim-postgres -- psql
|
2019-11-15 18:00:26 +01:00
|
|
|
|
|
|
|
# Copy existing config files into persistent storage
|
2020-03-17 09:18:13 +01:00
|
|
|
cp -rp ${LAYERS_DIR}/decidim_0.20.0-200313/srv/decidim-app/config ${DECIDIM_CONF}
|
2019-11-15 18:00:26 +01:00
|
|
|
|
|
|
|
# Configure Decidim
|
2020-03-17 09:18:13 +01:00
|
|
|
install -o 108080 -g 108080 -m 700 ${DECIDIM_DATA}/storage
|
|
|
|
install -o 108080 -g 108080 -m 700 ${DECIDIM_DATA}/uploads
|
|
|
|
export DECIDIM_SECRET=$(spoc-container exec -u 8080 -g 8080 decidim -- sh -c 'cd /srv/decidim-app; rake secret')
|
|
|
|
install -o 108080 -g 108080 -m 640 decidim_conf/environments/production.rb ${DECIDIM_CONF}/environments/production.rb
|
|
|
|
install -o 108080 -g 108080 -m 640 decidim_conf/initializers/decidim.rb ${DECIDIM_CONF}/initializers/decidim.rb
|
|
|
|
envsubst <decidim_conf/application.yml | install -o 108080 -g 108080 -m 640 /dev/stdin ${DECIDIM_CONF}/application.yml
|
2019-11-15 18:00:26 +01:00
|
|
|
|
|
|
|
# Populate database
|
2020-03-17 09:18:13 +01:00
|
|
|
spoc-container exec -u 8080 -g 8080 decidim -- sh -c 'cd /srv/decidim-app; bin/rails db:migrate'
|
2019-11-15 18:00:26 +01:00
|
|
|
|
|
|
|
# Create admin account
|
|
|
|
export DECIDIM_ADMIN_EMAIL=admin@example.com
|
|
|
|
export DECIDIM_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
|
2020-03-17 09:18:13 +01:00
|
|
|
envsubst <adminpwd.rb | spoc-container exec -u 8080 -g 8080 decidim -- sh -c 'cd /srv/decidim-app; bin/rails console -e production'
|
2019-11-15 18:00:26 +01:00
|
|
|
|
|
|
|
# Stop services required for setup
|
2020-03-17 09:18:13 +01:00
|
|
|
spoc-constainer stop decidim-postgres
|
2019-11-15 18:00:26 +01:00
|
|
|
|
|
|
|
# Register application
|
|
|
|
vmmgr register-app decidim decidim "${DECIDIM_ADMIN_EMAIL}" "${DECIDIM_ADMIN_PWD}"
|