Make SAMBRO SPOC-compatible

This commit is contained in:
Disassembler 2020-03-22 20:59:26 +01:00
parent caf30e9958
commit 102761efac
No known key found for this signature in database
GPG Key ID: 524BD33A0EE29499
5 changed files with 62 additions and 55 deletions

View File

@ -34,6 +34,13 @@ envsubst <masterUsers.csv | install -o 108080 -g 108080 -m 640 /dev/stdin ${SAHA
# Populate database
spoc-container exec -u sahana sahana-demo -- sh -c 'cd /srv/web2py; ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py'
# Set "production values" (increases performance) only if the DEBUG environment variable is not set
if [ ${DEBUG:-0} -eq 0 ]; then
sed -i 's/settings.base.migrate = True/settings.base.migrate = False/' ${SAHANA_CONF}/000_config.py
sed -i 's/settings.base.debug = True/settings.base.debug = False/' ${SAHANA_CONF}/000_config.py
sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' ${SAHANA_CONF}/000_config.py
fi
# Stop services required for setup
spoc-container stop sahana-demo-postgres

30
lxc-apps/sambro/app Normal file
View File

@ -0,0 +1,30 @@
{
"version": "0.0.1-200313",
"meta": {
"title": "Sahana Eden - SAMBRO",
"desc-cs": "Řízení humanítární činnosti - Centrum hlášení a výstrah",
"desc-en": "Management of humanitarian activities - Reporting and alerting center",
"license": "GPL"
},
"containers": {
"sambro": {
"image": "sahana_0.0.1-200313",
"depends": [
"sambro-postgres"
],
"mounts": {
"sambro/sahana_conf": "srv/web2py/applications/eden/models",
"sambro/sahana_data/SAMBRO": "srv/web2py/applications/eden/modules/templates/SAMBRO",
"sambro/sahana_data/databases": "srv/web2py/applications/eden/databases",
"sambro/sahana_data/uploads": "srv/web2py/applications/eden/uploads",
"sambro/sahana_data/masterUsers.csv": "srv/web2py/applications/eden/modules/templates/default/users/masterUsers.csv:file"
}
},
"sambro-postgres": {
"image": "postgis_3.0.0-200313",
"mounts": {
"sambro/postgres_data": "var/lib/postgresql"
}
}
}
}

View File

@ -1,52 +1,51 @@
#!/bin/sh
set -ev
# Volumes
POSTGRES_DATA="${VOLUMES_DIR}/sambro/postgres_data"
SAHANA_DATA="${VOLUMES_DIR}/sambro/sahana_data"
SAHANA_CONF="${VOLUMES_DIR}/sambro/sahana_conf"
# Create Postgres instance
mkdir -p /srv/sambro/postgres_data
chown -R 105432:105432 /srv/sambro/postgres_data
chmod 700 /srv/sambro/postgres_data
lxc-execute -n sambro-postgres -- initdb -D /var/lib/postgresql
install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA}
spoc-container exec sambro-postgres -- initdb -D /var/lib/postgresql
# Configure Postgres
cp postgres_data/postgresql.conf /srv/sambro/postgres_data/postgresql.conf
cp postgres_data/pg_hba.conf /srv/sambro/postgres_data/pg_hba.conf
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
# Create PostgreSQL user and database
export SAMBRO_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
service lxc-sambro-postgres start
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 sambro-postgres -- psql
spoc-container start sambro-postgres
envsubst <createdb.sql | spoc-container exec sambro-postgres -- psql
# Prepare persistent directory structure
mkdir -p /srv/sambro/sahana_data/databases /srv/sambro/sahana_data/uploads
chown -R 108080:108080 /srv/sambro/sahana_data
lxchelper extract sambro /srv/web2py/applications/eden/models /srv/sambro/sahana_conf
lxchelper extract sambro /srv/web2py/applications/eden/modules/templates/SAMBRO /srv/sambro/sahana_data/SAMBRO
install -o 108080 -g 108080 -m 750 -d ${SAHANA_DATA}/databases
install -o 108080 -g 108080 -m 750 -d ${SAHANA_DATA}/uploads
cp -rp ${LAYERS_DIR}/sahana_0.0.1-200313/srv/web2py/applications/eden/models ${SAHANA_CONF}
cp -rp ${LAYERS_DIR}/sahana_0.0.1-200313/srv/web2py/applications/eden/modules/templates/SAMBRO ${SAHANA_DATA}/SAMBRO
# Configure SAMBRO
export SAMBRO_HMAC=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
export SAMBRO_ADMIN_USER=admin@example.com
export SAMBRO_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
envsubst <sahana_conf/000_config.py >/srv/sambro/sahana_conf/000_config.py
envsubst <masterUsers.csv >/srv/sambro/sahana_data/masterUsers.csv
cp sahana_conf/00_settings.py /srv/sambro/sahana_conf/00_settings.py
cp sahana_data/SAMBRO/config.py /srv/sambro/sahana_data/SAMBRO/config.py
chown -R 108080:108080 /srv/sambro/sahana_conf /srv/sambro/sahana_data
envsubst <sahana_conf/000_config.py | install -o 108080 -g 108080 -m 640 /dev/stdin ${SAHANA_CONF}/000_config.py
envsubst <sahana_data/masterUsers.csv | install -o 108080 -g 108080 -m 640 /dev/stdin ${SAHANA_DATA}/masterUsers.csv
install -o 108080 -g 108080 -m 640 sahana_conf/00_settings.py ${SAHANA_CONF}/00_settings.py
install -o 108080 -g 108080 -m 640 sahana_data/SAMBRO/config.py ${SAHANA_DATA}/SAMBRO/config.py
# Populate database
lxc-execute -u 8080 -g 8080 sambro -- sh -c 'cd /srv/web2py; ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py'
spoc-container exec -u sahana sambro -- sh -c 'cd /srv/web2py; ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py'
# Set "production values" (increases performance) only if the DEBUG environment variable is not set
if [ ${DEBUG:-0} -eq 0 ]; then
sed -i 's/settings.base.migrate = True/settings.base.migrate = False/' /srv/sambro/conf/000_config.py
sed -i 's/settings.base.debug = True/settings.base.debug = False/' /srv/sambro/conf/000_config.py
sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' /srv/sambro/conf/000_config.py
sed -i 's/settings.base.migrate = True/settings.base.migrate = False/' ${SAHANA_CONF}/000_config.py
sed -i 's/settings.base.debug = True/settings.base.debug = False/' ${SAHANA_CONF}/000_config.py
sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' ${SAHANA_CONF}/000_config.py
fi
# Install config update script
cp update-conf.sh /srv/sambro/update-conf.sh
# Stop services required for setup
service lxc-sambro-postgres stop
spoc-container stop sambro-postgres
# Register application
vmmgr register-app sambro sambro "${SAMBRO_ADMIN_USER}" "${SAMBRO_ADMIN_PWD}"

View File

@ -1,29 +0,0 @@
{
"version": "0.0.1-190620",
"meta": {
"title": "Sahana Eden - SAMBRO",
"desc-cs": "Řízení humanítární činnosti - Centrum hlášení a výstrah",
"desc-en": "Management of humanitarian activities - Reporting and alerting center",
"license": "GPL"
},
"containers": {
"sambro": {
"image": "sahana_0.0.1-190620",
"depends": [
"sambro-postgres"
],
"mounts": [
["DIR", "/srv/sambro/sahana_conf", "/srv/web2py/applications/eden/models"],
["DIR", "/srv/sambro/sahana_data/SAMBRO", "/srv/web2py/applications/eden/modules/templates/SAMBRO"],
["DIR", "/srv/sambro/sahana_data/databases", "/srv/web2py/applications/eden/databases"],
["DIR", "/srv/sambro/sahana_data/uploads", "/srv/web2py/applications/eden/uploads"]
]
},
"sambro-postgres": {
"image": "postgis_2.5.1-190620",
"mounts": [
["DIR", "/srv/sambro/postgres_data", "/var/lib/postgresql"]
]
}
}
}

View File

@ -2,7 +2,7 @@
set -ev
# Remove persistent data
rm -rf /srv/sambro
rm -rf "${VOLUMES_DIR}/sambro"
# Unregister application
vmmgr unregister-app sambro