Make Sahana SPOC-compatible

This commit is contained in:
Disassembler 2020-03-22 19:50:18 +01:00
parent 2b9d73c847
commit b804987254
Signed by: Disassembler
GPG Key ID: 524BD33A0EE29499
6 changed files with 55 additions and 85 deletions

29
lxc-apps/sahana/app Normal file
View File

@ -0,0 +1,29 @@
{
"version": "0.0.1-200313",
"meta": {
"title": "Sahana Eden",
"desc-cs": "Řízení humanítární činnosti",
"desc-en": "Management of humanitarian activities",
"license": "GPL"
},
"containers": {
"sahana": {
"image": "sahana_0.0.1-200313",
"depends": [
"sahana-postgres"
],
"mounts": {
"sahana/sahana_conf": "srv/web2py/applications/eden/models",
"sahana/sahana_data/Spotter": "srv/web2py/applications/eden/modules/templates/Spotter",
"sahana/sahana_data/databases": "srv/web2py/applications/eden/databases",
"sahana/sahana_data/uploads": "srv/web2py/applications/eden/uploads"
}
},
"sahana-postgres": {
"image": "postgis_3.0.0-200313",
"mounts": {
"sahana/postgres_data": "/var/lib/postgresql"
}
}
}
}

View File

@ -1,5 +1,5 @@
IMAGE sahana_0.0.1-200207 IMAGE sahana_0.0.1-200313
FROM alpine3.11-python3.8_3.8.1-200207 FROM alpine3.11-python3.8_3.8.2-200313
RUN EOF RUN EOF
# Install runtime dependencies # Install runtime dependencies
@ -37,8 +37,8 @@ COPY image.d
RUN EOF RUN EOF
# Create OS user # Create OS user
addgroup -S sahana addgroup -S -g 8080 sahana
adduser -S -h /srv/web2py -s /bin/false -g sahana -G sahana sahana adduser -S -u 8080 -h /srv/web2py -s /bin/false -g sahana -G sahana sahana
chown -R sahana:sahana /srv/web2py chown -R sahana:sahana /srv/web2py
# Patch web2py for python 3.8 # Patch web2py for python 3.8
@ -48,7 +48,6 @@ RUN EOF
# Cleanup # Cleanup
apk --no-cache del .deps apk --no-cache del .deps
find /srv/web2py -name '.git*' -exec rm -rf {} + find /srv/web2py -name '.git*' -exec rm -rf {} +
# rm -r /srv/web2py/applications/admin /srv/web2py/applications/examples /srv/web2py/applications/welcome
rm -r /root/.cache rm -r /root/.cache
rm /tmp/python38.patch rm /tmp/python38.patch
EOF EOF

View File

@ -1,39 +1,18 @@
#!/bin/sh #!/bin/sh
set -ev set -ev
# Create containers # Volumes
spoc-container create \ POSTGRES_DATA="${VOLUMES_DIR}/sahana/postgres_data"
-m sahana/postgres_data:var/lib/postgresql \ SAHANA_DATA="${VOLUMES_DIR}/sahana/sahana_data"
sahana-postgres postgis_3.0.0-200207 SAHANA_CONF="${VOLUMES_DIR}/sahana/sahana_conf"
spoc-container create \
-d sahana-postgres \
-m sahana/sahana_conf:srv/web2py/applications/eden/models \
-m sahana/sahana_data/Spotter:srv/web2py/applications/eden/modules/templates/Spotter \
-m sahana/sahana_data/databases:srv/web2py/applications/eden/databases \
-m sahana/sahana_data/uploads:srv/web2py/applications/eden/uploads \
sahana sahana_0.0.1-200207
# TODO: Populate from spoc
LAYER_DIR="/var/lib/spoc/layers"
VOLUME_DIR="/var/lib/spoc/volumes/sahana"
POSTGRES_UID=70
POSTGRES_GID=70
POSTGRES_NSUID=100070
POSTGRES_NSGID=100070
SAHANA_UID=103
SAHANA_GID=104
SAHANA_NSUID=100103
SAHANA_NSGID=100104
# Create Postgres instance # Create Postgres instance
mkdir -p ${VOLUME_DIR}/postgres_data install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA}
chown -R ${POSTGRES_NSUID}:${POSTGRES_NSGID} ${VOLUME_DIR}/postgres_data
chmod 700 ${VOLUME_DIR}/postgres_data
spoc-container exec sahana-postgres -- initdb -D /var/lib/postgresql spoc-container exec sahana-postgres -- initdb -D /var/lib/postgresql
# Configure Postgres # Configure Postgres
cp postgres_data/postgresql.conf ${VOLUME_DIR}/postgres_data/postgresql.conf install -o 105432 -g 105432 -m 600 postgres_data/postgresql.conf ${POSTGRES_DATA}/postgresql.conf
cp postgres_data/pg_hba.conf ${VOLUME_DIR}/postgres_data/pg_hba.conf install -o 105432 -g 105432 -m 600 postgres_data/pg_hba.conf ${POSTGRES_DATA}/pg_hba.conf
# Create PostgreSQL user and database # Create PostgreSQL user and database
export SAHANA_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=') export SAHANA_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
@ -41,38 +20,34 @@ spoc-container start sahana-postgres
envsubst <createdb.sql | spoc-container exec sahana-postgres -- psql envsubst <createdb.sql | spoc-container exec sahana-postgres -- psql
# Prepare persistent directory structure # Prepare persistent directory structure
mkdir -p ${VOLUME_DIR}/sahana_data/databases ${VOLUME_DIR}/sahana_data/uploads install -u 108080 -g 108080 -m 750 -d ${SAHANA_DATA}/databases
chown -R ${SAHANA_NSUID}:${SAHANA_NSGID} ${VOLUME_DIR}/sahana_data install -u 108080 -g 108080 -m 750 -d ${SAHANA_DATA}/uploads
cp -rp ${LAYER_DIR}/sahana_0.0.1-200207/srv/web2py/applications/eden/models ${VOLUME_DIR}/sahana_conf cp -rp ${LAYERS_DIR}/sahana_0.0.1-200313/srv/web2py/applications/eden/models ${SAHANA_CONF}
# Copy Spotter template # Copy Spotter template
cp -r sahana_data/Spotter ${VOLUME_DIR}/sahana_data/ cp -r sahana_data/Spotter ${SAHANA_DATA}/Spotter
chown -R ${SAHANA_NSUID}:${SAHANA_NSGID} ${VOLUME_DIR}/sahana_data chown -R 108080:108080 ${SAHANA_DATA}/Spotter
# Configure Sahana # Configure Sahana
export SAHANA_HMAC=$(head -c 18 /dev/urandom | base64 | tr -d '+/=') export SAHANA_HMAC=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
export SAHANA_ADMIN_USER=admin@example.com export SAHANA_ADMIN_USER=admin@example.com
export SAHANA_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=') export SAHANA_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
envsubst <sahana_conf/000_config.py >${VOLUME_DIR}/sahana_conf/000_config.py envsubst <sahana_conf/000_config.py | install -o 108080 -g 108080 -m 640 /dev/stdin ${SAHANA_CONF}/000_config.py
envsubst <sahana_data/Spotter/masterUsers.csv >${VOLUME_DIR}/sahana_data/Spotter/masterUsers.csv envsubst <sahana_data/Spotter/masterUsers.csv | install -o 108080 -g 108080 -m 640 /dev/stdin ${VOLUME_DIR}/sahana_data/Spotter/masterUsers.csv
cp sahana_conf/00_settings.py ${VOLUME_DIR}/sahana_conf/00_settings.py | install -o 108080 -g 108080 -m 640 /dev/stdin sahana_conf/00_settings.py ${SAHANA_CONF}/00_settings.py
chown -R ${SAHANA_NSUID}:${SAHANA_NSGID} ${VOLUME_DIR}/sahana_conf ${VOLUME_DIR}/sahana_data
# Populate database # Populate database
spoc-container exec -u sahana sahana -- sh -c 'cd /srv/web2py; ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py' spoc-container exec -u sahana sahana -- 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 # 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
sed -i 's/settings.base.migrate = True/settings.base.migrate = False/' ${VOLUME_DIR}/sahana_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/' ${VOLUME_DIR}/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/' ${VOLUME_DIR}/sahana_conf/000_config.py sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' ${SAHANA_CONF}/000_config.py
fi fi
# Install config update script
cp update-conf.sh ${VOLUME_DIR}/update-conf.sh
# Stop services required for setup # Stop services required for setup
spoc-container stop sahana-postgres spoc-container stop sahana-postgres
# Register application # Register application
#vmmgr register-app sahana sahana "${SAHANA_ADMIN_USER}" "${SAHANA_ADMIN_PWD}" vmmgr register-app sahana sahana "${SAHANA_ADMIN_USER}" "${SAHANA_ADMIN_PWD}"

View File

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

View File

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

View File

@ -18,6 +18,7 @@ envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 sambro-postgres -- psql
# Prepare persistent directory structure # Prepare persistent directory structure
mkdir -p /srv/sambro/sahana_data/databases /srv/sambro/sahana_data/uploads 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/models /srv/sambro/sahana_conf
lxchelper extract sambro /srv/web2py/applications/eden/modules/templates/SAMBRO /srv/sambro/sahana_data/SAMBRO lxchelper extract sambro /srv/web2py/applications/eden/modules/templates/SAMBRO /srv/sambro/sahana_data/SAMBRO
@ -26,14 +27,9 @@ export SAMBRO_HMAC=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
export SAMBRO_ADMIN_USER=admin@example.com export SAMBRO_ADMIN_USER=admin@example.com
export SAMBRO_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=') 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 <sahana_conf/000_config.py >/srv/sambro/sahana_conf/000_config.py
# TODO: envsubst <masterUsers.csv >/srv/sambro/sahana_data/masterUsers.csv
#mkdir -p /var/lib/lxc/sambro/sambro/srv/web2py/applications/eden/modules/templates/default/users
#envsubst <masterUsers.csv >/var/lib/lxc/sambro/sambro/srv/web2py/applications/eden/modules/templates/default/users/masterUsers.csv
#chown -R 8080:8080 /var/lib/lxc/sambro/sambro/srv/web2py
cp sahana_conf/00_settings.py /srv/sambro/sahana_conf/00_settings.py 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 cp sahana_data/SAMBRO/config.py /srv/sambro/sahana_data/SAMBRO/config.py
# Hackfix for https://github.com/sahana/eden/issues/1530
echo 'CANARY_UPDATE_CHECK_ID = 4' >/srv/sambro/sahana_conf/0000_update_check.py
chown -R 108080:108080 /srv/sambro/sahana_conf /srv/sambro/sahana_data chown -R 108080:108080 /srv/sambro/sahana_conf /srv/sambro/sahana_data
# Populate database # Populate database