2018-02-09 19:20:32 +01:00
|
|
|
#!/bin/sh
|
2018-07-15 21:55:35 +02:00
|
|
|
set -e
|
2018-02-09 19:20:32 +01:00
|
|
|
|
|
|
|
SOURCE_DIR=$(realpath $(dirname "${0}"))/sahana-demo
|
2018-02-20 14:17:16 +01:00
|
|
|
export TEMPLATE=${TEMPLATE:-"default"}
|
2018-02-09 19:20:32 +01:00
|
|
|
|
|
|
|
# Check prerequisites
|
|
|
|
docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh
|
|
|
|
docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh
|
2018-04-29 20:48:57 +02:00
|
|
|
service postgres start
|
|
|
|
|
|
|
|
# Build Docker container
|
2018-07-12 22:19:10 +02:00
|
|
|
docker build -t sahana $(realpath $(dirname "${0}"))/sahana
|
2018-04-29 20:48:57 +02:00
|
|
|
envsubst <${SOURCE_DIR}/etc/init.d/sahana-demo >/etc/init.d/sahana-demo
|
|
|
|
chmod +x /etc/init.d/sahana-demo
|
2018-02-09 19:20:32 +01:00
|
|
|
|
|
|
|
# Create PostgreSQL user and database
|
|
|
|
export SAHANADEMO_PWD=$(head -c 18 /dev/urandom | base64)
|
|
|
|
envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql
|
|
|
|
|
|
|
|
# Prepare persistent directory structure
|
2018-02-20 14:17:16 +01:00
|
|
|
mkdir -p /srv/sahana-demo/conf /srv/sahana-demo/data/databases /srv/sahana-demo/data/uploads /srv/sahana-demo/data/${TEMPLATE}
|
2018-02-09 19:20:32 +01:00
|
|
|
chown -R 8001:8001 /srv/sahana-demo/conf /srv/sahana-demo/data
|
|
|
|
docker run --rm -v /srv/sahana-demo/conf:/mnt/conf sahana cp -rp /srv/web2py/applications/eden/models/. /mnt/conf
|
2018-02-20 14:17:16 +01:00
|
|
|
docker run --rm -v /srv/sahana-demo/data/${TEMPLATE}:/mnt/data sahana cp -rp /srv/web2py/applications/eden/modules/templates/${TEMPLATE}/. /mnt/data
|
2018-02-09 19:20:32 +01:00
|
|
|
|
|
|
|
# Configure Sahana
|
|
|
|
export SAHANADEMO_HMAC=$(head -c 18 /dev/urandom | base64)
|
|
|
|
export SAHANADEMO_ADMIN_USER=admin@example.com
|
|
|
|
export SAHANADEMO_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
|
2018-03-25 23:20:08 +02:00
|
|
|
envsubst <${SOURCE_DIR}/srv/sahana-demo/conf/000_config.py >/srv/sahana-demo/conf/000_config.py
|
2018-02-09 19:20:32 +01:00
|
|
|
envsubst <${SOURCE_DIR}/masterUsers.csv >/tmp/masterUsers.csv
|
2018-03-25 23:20:08 +02:00
|
|
|
cp ${SOURCE_DIR}/srv/sahana-demo/update-url.sh /srv/sahana-demo/update-url.sh
|
2018-04-29 20:48:57 +02:00
|
|
|
spotter-appmgr update-login sahana-demo "${SAHANADEMO_ADMIN_USER}" "${SAHANADEMO_ADMIN_PWD}"
|
2018-02-09 19:20:32 +01:00
|
|
|
|
|
|
|
# Populate database
|
2018-03-14 12:13:00 +01:00
|
|
|
docker run --rm -h sahana-demo --link postgres -v /srv/sahana-demo/conf:/srv/web2py/applications/eden/models -v /srv/sahana-demo/data/databases:/srv/web2py/applications/eden/databases -v /tmp/masterUsers.csv:/srv/web2py/applications/eden/modules/templates/default/users/masterUsers.csv sahana su - sahana -c "./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py"
|
2018-02-09 19:20:32 +01:00
|
|
|
rm /tmp/masterUsers.csv
|
2018-07-15 21:55:35 +02:00
|
|
|
|
|
|
|
# Stop services required for build
|
|
|
|
service postgres stop
|