LXCize SAMBRO setup

This commit is contained in:
Disassembler 2018-09-14 08:53:27 +02:00
parent 8ac781bd8b
commit 8cc184c7e7
Signed by: Disassembler
GPG Key ID: 524BD33A0EE29499
10 changed files with 49 additions and 50 deletions

View File

@ -25,12 +25,11 @@ envsubst <${SOURCE_DIR}/srv/sahana-demo/conf/000_config.py >/srv/sahana-demo/con
envsubst <${SOURCE_DIR}/masterUsers.csv >/var/lib/lxc/sahana/sahana/tmp/masterUsers.csv envsubst <${SOURCE_DIR}/masterUsers.csv >/var/lib/lxc/sahana/sahana/tmp/masterUsers.csv
vmmgr update-login sahana-demo "${SAHANADEMO_ADMIN_USER}" "${SAHANADEMO_ADMIN_PWD}" vmmgr update-login sahana-demo "${SAHANADEMO_ADMIN_USER}" "${SAHANADEMO_ADMIN_PWD}"
# Replace template in LXC container definition # Replace template in LXC container mount definition
sed -i "s/default/${TEMPLATE}/g" /var/lib/lxc/sahana-demo/config sed -i "s/default/${TEMPLATE}/g" /var/lib/lxc/sahana-demo/config
# Populate database # Populate database
lxc-execute -u 8001 -g 8001 sahana -- sh -c 'cd /srv/web2py; cp /tmp/masterUsers.csv applications/eden/modules/templates/default/users/masterUsers.csv; ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py' lxc-execute -u 8001 -g 8001 sahana -- sh -c 'cd /srv/web2py; cp /tmp/masterUsers.csv applications/eden/modules/templates/default/users/masterUsers.csv; ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py'
docker run --rm -h sahana-demo --link postgres -v /srv/sahana-demo/conf:/srv/web2py/applications/eden/models -v /srv/sahana-demo/data/${TEMPLATE}:/srv/web2py/applications/eden/modules/templates/${TEMPLATE} -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"
rm /var/lib/lxc/sahana/sahana/tmp/masterUsers.csv rm /var/lib/lxc/sahana/sahana/tmp/masterUsers.csv
# Install service # Install service

View File

@ -1,32 +0,0 @@
#!/sbin/openrc-run
description="SAMBRO docker container"
depend() {
need docker postfix postgres
}
start() {
/usr/bin/docker run -d --rm \
--name sambro \
-h sambro \
--link postfix \
--link postgres \
-v /srv/sambro/conf:/srv/web2py/applications/eden/models \
-v /srv/sambro/data/SAMBRO:/srv/web2py/applications/eden/modules/templates/SAMBRO \
-v /srv/sambro/data/databases:/srv/web2py/applications/eden/databases \
-v /srv/sambro/data/uploads:/srv/web2py/applications/eden/uploads \
sahana
}
start_post() {
/usr/bin/vmmgr register-proxy sambro
}
stop_pre() {
/usr/bin/vmmgr unregister-proxy sambro
}
stop() {
/usr/bin/docker stop sambro
}

12
sambro/lxcfile Normal file
View File

@ -0,0 +1,12 @@
IMAGE sambro
LAYER shared/alpine
LAYER shared/libxml
LAYER shared/python2
LAYER sahana/sahana
MOUNT /srv/sahana/conf srv/web2py/applications/eden/models
MOUNT /srv/sahana/data/SAMBRO srv/web2py/applications/eden/modules/templates/SAMBRO
MOUNT /srv/sahana/data/databases srv/web2py/applications/eden/databases
MOUNT /srv/sahana/data/uploads srv/web2py/applications/eden/uploads
CMD s6-svscan /etc/services.d

View File

@ -1,41 +1,34 @@
#!/bin/sh #!/bin/sh
set -e set -e
SOURCE_DIR=$(realpath $(dirname "${0}"))/sambro SOURCE_DIR=$(realpath $(dirname "${0}"))/setup
# Check prerequisites # Check prerequisites
lxc-ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh [ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
lxc-ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh
service postgres start
# Build Docker container
docker build -t sahana $(realpath $(dirname "${0}"))/sahana
cp ${SOURCE_DIR}/etc/init.d/sambro /etc/init.d/sambro
rc-update -u
# Create PostgreSQL user and database # Create PostgreSQL user and database
export SAMBRO_PWD=$(head -c 18 /dev/urandom | base64) export SAMBRO_PWD=$(head -c 18 /dev/urandom | base64)
envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql envsubst <${SOURCE_DIR}/createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql
# Prepare persistent directory structure # Prepare persistent directory structure
mkdir -p /srv/sambro/conf /srv/sambro/data/databases /srv/sambro/data/uploads /srv/sambro/data/SAMBRO mkdir -p /srv/sambro/conf /srv/sambro/data/databases /srv/sambro/data/uploads /srv/sambro/data/SAMBRO
chown -R 8001:8001 /srv/sambro/conf /srv/sambro/data chown -R 8001:8001 /srv/sambro/conf /srv/sambro/data
docker run --rm -v /srv/sambro/conf:/mnt/conf sahana cp -rp /srv/web2py/applications/eden/models/. /mnt/conf cp -rp /var/lib/lxc/sahana/sahana/srv/web2py/applications/eden/models/. /srv/sahana-demo/conf
docker run --rm -v /srv/sambro/data/SAMBRO:/mnt/data sahana cp -rp /srv/web2py/applications/eden/modules/templates/SAMBRO/. /mnt/data cp -rp /srv/web2py/applications/eden/modules/templates/SAMBRO/. /srv/sahana-demo/data/SAMBRO
# Configure SAMBRO # Configure SAMBRO
export SAMBRO_HMAC=$(head -c 18 /dev/urandom | base64) export SAMBRO_HMAC=$(head -c 18 /dev/urandom | base64)
export SAMBRO_ADMIN_USER=admin@example.com export SAMBRO_ADMIN_USER=admin@example.com
export SAMBRO_ADMIN_PWD=$(head -c 12 /dev/urandom | base64) export SAMBRO_ADMIN_PWD=$(head -c 12 /dev/urandom | base64)
envsubst <${SOURCE_DIR}/srv/sambro/conf/000_config.py >/srv/sambro/conf/000_config.py envsubst <${SOURCE_DIR}/srv/sambro/conf/000_config.py >/srv/sambro/conf/000_config.py
envsubst <${SOURCE_DIR}/masterUsers.csv >/tmp/masterUsers.csv envsubst <${SOURCE_DIR}/masterUsers.csv >/var/lib/lxc/sahana/sahana/tmp/masterUsers.csv
cp ${SOURCE_DIR}/srv/sambro/conf/00_settings.py /srv/sambro/conf/00_settings.py cp ${SOURCE_DIR}/srv/sambro/conf/00_settings.py /srv/sambro/conf/00_settings.py
cp ${SOURCE_DIR}/srv/sambro/data/SAMBRO/config.py /srv/sambro/data/SAMBRO/config.py cp ${SOURCE_DIR}/srv/sambro/data/SAMBRO/config.py /srv/sambro/data/SAMBRO/config.py
vmmgr update-login sambro "${SAMBRO_ADMIN_USER}" "${SAMBRO_ADMIN_PWD}" vmmgr update-login sambro "${SAMBRO_ADMIN_USER}" "${SAMBRO_ADMIN_PWD}"
# Populate database # Populate database
docker run --rm -h sambro --link postgres -v /srv/sambro/conf:/srv/web2py/applications/eden/models -v /srv/sambro/data/SAMBRO:/srv/web2py/applications/eden/modules/templates/SAMBRO -v /tmp/masterUsers.csv:/srv/web2py/applications/eden/modules/templates/default/users/masterUsers.csv -v /srv/sambro/data/databases:/srv/web2py/applications/eden/databases sahana su - sahana -c "./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py" lxc-execute -u 8001 -g 8001 sahana -- sh -c 'cd /srv/web2py; cp /tmp/masterUsers.csv applications/eden/modules/templates/default/users/masterUsers.csv; ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py'
rm /tmp/masterUsers.csv rm /var/lib/lxc/sahana/sahana/tmp/masterUsers.csv
# Set "production values" (increases performance) only if the DEBUG environment variable is not set # Set "production values" (increases performance) only if the DEBUG environment variable is not set
if [ ${DEBUG:-0} -eq 0 ]; then if [ ${DEBUG:-0} -eq 0 ]; then
@ -44,5 +37,9 @@ if [ ${DEBUG:-0} -eq 0 ]; then
sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' /srv/sambro/conf/000_config.py sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' /srv/sambro/conf/000_config.py
fi fi
# Install service
cp ${SOURCE_DIR}/etc/init.d/sambro /etc/init.d/sambro
rc-update -u
# Stop services required for build # Stop services required for build
service postgres stop [ ! -z ${STOP_POSTGRES} ] && service postgres stop

23
sambro/setup/etc/init.d/sambro Executable file
View File

@ -0,0 +1,23 @@
#!/sbin/openrc-run
description="SAMBRO container"
depend() {
need cgroups postgres
}
start() {
lxc-start sambro
}
start_post() {
/usr/bin/vmmgr register-proxy sambro
}
stop_pre() {
/usr/bin/vmmgr unregister-proxy sambro
}
stop() {
lxc-stop sambro
}