2018-04-21 22:30:25 +02:00
|
|
|
#!/bin/sh
|
2018-07-15 21:55:35 +02:00
|
|
|
set -e
|
2018-04-21 22:30:25 +02:00
|
|
|
|
|
|
|
SOURCE_DIR=$(realpath $(dirname "${0}"))/crisiscleanup
|
|
|
|
|
|
|
|
# Check prerequisites
|
|
|
|
docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh
|
|
|
|
docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh
|
|
|
|
service postgres start
|
|
|
|
|
|
|
|
# Build Docker container
|
|
|
|
docker build -t crisiscleanup ${SOURCE_DIR}
|
|
|
|
cp ${SOURCE_DIR}/etc/init.d/crisiscleanup /etc/init.d/crisiscleanup
|
|
|
|
rc-update -u
|
|
|
|
|
|
|
|
# Create database
|
|
|
|
export CRISISCLEANUP_PWD=$(head -c 18 /dev/urandom | base64)
|
|
|
|
envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql
|
|
|
|
|
|
|
|
# Copy existing config files into persistent storage
|
|
|
|
mkdir -p /srv/crisiscleanup/conf
|
|
|
|
chown 8005:8005 /srv/crisiscleanup/conf
|
|
|
|
docker run --rm -v /srv/crisiscleanup/conf:/mnt/conf crisiscleanup cp -rp /srv/crisiscleanup/config/. /mnt/conf
|
|
|
|
chown root:root /srv/crisiscleanup/conf
|
|
|
|
|
|
|
|
# Configure CrisisCleanup
|
|
|
|
export CRISISCLEANUP_ADMIN_USER="Admin"
|
|
|
|
export CRISISCLEANUP_ADMIN_EMAIL="admin@example.com"
|
|
|
|
export CRISISCLEANUP_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
|
|
|
|
envsubst <${SOURCE_DIR}/srv/crisiscleanup/conf/database.yml >/srv/crisiscleanup/conf/database.yml
|
|
|
|
cp ${SOURCE_DIR}/srv/crisiscleanup/conf/boot.rb /srv/crisiscleanup/conf/boot.rb
|
|
|
|
cp ${SOURCE_DIR}/srv/crisiscleanup/conf/initializers/devise.rb /srv/crisiscleanup/conf/initializers/devise.rb
|
|
|
|
cp ${SOURCE_DIR}/srv/crisiscleanup/conf/environments/production.rb /srv/crisiscleanup/conf/environments/production.rb
|
2018-09-03 17:24:48 +02:00
|
|
|
vm-appmgr update-login crisiscleanup "${CRISISCLEANUP_ADMIN_EMAIL}" "${CRISISCLEANUP_ADMIN_PWD}"
|
2018-04-21 22:30:25 +02:00
|
|
|
|
|
|
|
# Populate database
|
|
|
|
envsubst <${SOURCE_DIR}/srv/crisiscleanup/db/seeds.rb >/tmp/seeds.rb
|
|
|
|
docker run --rm -h crisiscleanup --link postgres -v /srv/crisiscleanup/conf:/srv/crisiscleanup/config crisiscleanup rake db:schema:load
|
|
|
|
docker run --rm -h crisiscleanup --link postgres -v /srv/crisiscleanup/conf:/srv/crisiscleanup/config -v /tmp/seeds.rb:/srv/crisiscleanup/db/seeds.rb crisiscleanup rake db:seed
|
|
|
|
rm /tmp/seeds.rb
|
2018-07-15 21:55:35 +02:00
|
|
|
|
|
|
|
# Stop services required for build
|
|
|
|
service postgres stop
|