From 473dd4af6176891baffbcda7dcf83a41f4883075 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Sun, 9 Feb 2020 15:56:37 +0100 Subject: [PATCH] Update Sahana + Sahana Demo for spoc --- lxc-apps/sahana-demo/install.sh | 62 +++++++--- lxc-apps/sahana/image | 21 ++-- .../sahana/image.d/etc/services.d/nginx/run | 0 .../image.d/etc/services.d/uwsgi/down-signal | 0 .../sahana/image.d/etc/services.d/uwsgi/run | 0 lxc-apps/sahana/image.d/srv/web2py/routes.py | 1 - lxc-apps/sahana/image.d/tmp/python38.patch | 115 ++++++++++++++++++ lxc-apps/sahana/install.sh | 72 +++++++---- 8 files changed, 219 insertions(+), 52 deletions(-) mode change 100644 => 100755 lxc-apps/sahana/image.d/etc/services.d/nginx/run mode change 100644 => 100755 lxc-apps/sahana/image.d/etc/services.d/uwsgi/down-signal mode change 100644 => 100755 lxc-apps/sahana/image.d/etc/services.d/uwsgi/run create mode 100644 lxc-apps/sahana/image.d/tmp/python38.patch diff --git a/lxc-apps/sahana-demo/install.sh b/lxc-apps/sahana-demo/install.sh index fc53d9e..0505c48 100755 --- a/lxc-apps/sahana-demo/install.sh +++ b/lxc-apps/sahana-demo/install.sh @@ -1,43 +1,67 @@ #!/bin/sh set -ev +# Create containers +spoc-container create \ + -m sahana-demo/postgres_data:var/lib/postgresql \ + sahana-demo-postgres postgis_3.0.0-200207 +spoc-container create \ + -d sahana-demo-postgres \ + -m sahana-demo/sahana_conf:srv/web2py/applications/eden/models \ + -m sahana-demo/sahana_data/default:srv/web2py/applications/eden/modules/templates/default \ + -m sahana-demo/sahana_data/databases:srv/web2py/applications/eden/databases \ + -m sahana-demo/sahana_data/uploads:srv/web2py/applications/eden/uploads \ + sahana-demo sahana_0.0.1-200207 + +# TODO: Populate from spoc +LAYER_DIR="/var/lib/spoc/layers" +VOLUME_DIR="/var/lib/spoc/volumes/sahana-demo" +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 -mkdir -p /srv/sahana-demo/postgres_data -chown -R 105432:105432 /srv/sahana-demo/postgres_data -chmod 700 /srv/sahana-demo/postgres_data -lxc-execute -n sahana-demo-postgres -- initdb -D /var/lib/postgresql +mkdir -p ${VOLUME_DIR}/postgres_data +chown -R ${POSTGRES_NSUID}:${POSTGRES_NSGID} ${VOLUME_DIR}/postgres_data +chmod 700 ${VOLUME_DIR}/postgres_data +spoc-container exec sahana-demo-postgres -- initdb -D /var/lib/postgresql # Configure Postgres -cp postgres_data/postgresql.conf /srv/sahana-demo/postgres_data/postgresql.conf -cp postgres_data/pg_hba.conf /srv/sahana-demo/postgres_data/pg_hba.conf +cp postgres_data/postgresql.conf ${VOLUME_DIR}/postgres_data/postgresql.conf +cp postgres_data/pg_hba.conf ${VOLUME_DIR}/postgres_data/pg_hba.conf # Create PostgreSQL user and database export SAHANADEMO_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=') -service lxc-sahana-demo-postgres start -envsubst /srv/sahana-demo/sahana_conf/000_config.py -envsubst /srv/sahana-demo/sahana_data/default/users/masterUsers.csv -chown -R 108080:108080 /srv/sahana/sahana_conf /srv/sahana/sahana_data +envsubst ${VOLUME_DIR}/sahana_conf/000_config.py +envsubst ${VOLUME_DIR}/sahana_data/default/users/masterUsers.csv +chown -R ${SAHANA_NSUID}:${SAHANA_NSGID} ${VOLUME_DIR}/sahana_conf ${VOLUME_DIR}/sahana_data # Populate database -lxc-execute -u 8080 -g 8080 sahana-demo -- sh -c 'cd /srv/web2py; ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py' +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' # Install config update script -cp update-conf.sh /srv/sahana-demo/update-conf.sh +cp update-conf.sh ${VOLUME_DIR}/update-conf.sh # Stop services required for setup -service lxc-sahana-demo-postgres stop +spoc-container stop sahana-postgres # Register application -vmmgr register-app sahana-demo sahana-demo "${SAHANADEMO_ADMIN_USER}" "${SAHANADEMO_ADMIN_PWD}" +#vmmgr register-app sahana-demo sahana-demo "${SAHANADEMO_ADMIN_USER}" "${SAHANADEMO_ADMIN_PWD}" diff --git a/lxc-apps/sahana/image b/lxc-apps/sahana/image index 27b3add..c2397b6 100644 --- a/lxc-apps/sahana/image +++ b/lxc-apps/sahana/image @@ -3,14 +3,14 @@ FROM alpine3.11-python3.8_3.8.1-200207 RUN EOF # Install runtime dependencies - apk --no-cache add geos nginx py3-gdal py3-dateutil py3-lxml py3-numpy py3-pillow py3-psycopg2 py3-requests uwsgi-python3 + apk --no-cache add geos nginx py3-gdal py3-dateutil py3-lxml py3-numpy py3-pillow py3-psycopg2 py3-requests py3-sgmllib3k uwsgi-python3 # Install build dependencies - apk --no-cache add --virtual .deps build-base git freetype-dev libpng-dev py3-numpy-dev py3-pip python3-dev ttf-dejavu + apk --no-cache add --virtual .deps build-base freetype-dev git py3-numpy-dev py3-pip python3-dev ttf-dejavu # Install web2py git clone --recursive https://github.com/web2py/web2py.git /srv/web2py - git -C /srv/web2py checkout 6128d03 + git -C /srv/web2py checkout 59700b8 git -C /srv/web2py submodule update # Symlink WSGI handler @@ -36,15 +36,20 @@ COPY image.d RUN EOF # Create OS user - addgroup sahana - adduser -h /srv/web2py -s /bin/false -g sahana -G sahana sahana + addgroup -S sahana + adduser -S -h /srv/web2py -s /bin/false -g sahana -G sahana sahana chown -R sahana:sahana /srv/web2py - + + # Patch web2py for python 3.8 + cd /srv/web2py + patch -p0 0: +--- gluon/packages/dal/pydal/validators.py ++++ gluon/packages/dal/pydal/validators.py +@@ -148,7 +148,7 @@ + + + def validator_caller(func, value): +- if getattr(func, 'validate', None) is Validator.validate: ++ if getattr(func, 'validate', None) is not Validator.validate: + return func.validate(value) + value, error = func(value) + if error is not None: +@@ -3154,7 +3154,7 @@ + if not all_special.count(True) >= self.special: + failures.append(self.translator("Must include at least %s of the following: %s") + % (self.special, self.specials)) +- elif self.special is 0: ++ elif self.special == 0 and self.special is not False: + if len(all_special) > 0: + failures.append(self.translator("May not contain any of the following: %s") + % self.specials) +@@ -3169,7 +3169,7 @@ + if not len(all_upper) >= self.upper: + failures.append(self.translator("Must include at least %s uppercase") + % str(self.upper)) +- elif self.upper is 0: ++ elif self.upper == 0 and self.upper is not False: + if len(all_upper) > 0: + failures.append( + self.translator("May not include any uppercase letters")) +@@ -3179,7 +3179,7 @@ + if not len(all_lower) >= self.lower: + failures.append(self.translator("Must include at least %s lowercase") + % str(self.lower)) +- elif self.lower is 0: ++ elif self.lower == 0 and self.lower is not False: + if len(all_lower) > 0: + failures.append( + self.translator("May not include any lowercase letters")) +@@ -3192,7 +3192,7 @@ + if not len(all_number) >= self.number: + failures.append(self.translator("Must include at least %s %s") + % (str(self.number), numbers)) +- elif self.number is 0: ++ elif self.number == 0 and self.number is not False: + if len(all_number) > 0: + failures.append(self.translator("May not include any numbers")) + if len(failures) == 0: diff --git a/lxc-apps/sahana/install.sh b/lxc-apps/sahana/install.sh index 1d8a28c..cc84991 100755 --- a/lxc-apps/sahana/install.sh +++ b/lxc-apps/sahana/install.sh @@ -1,54 +1,78 @@ #!/bin/sh set -ev +# Create containers +spoc-container create \ + -m sahana/postgres_data:var/lib/postgresql \ + sahana-postgres postgis_3.0.0-200207 +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 -mkdir -p /srv/sahana/postgres_data -chown -R 105432:105432 /srv/sahana/postgres_data -chmod 700 /srv/sahana/postgres_data -lxc-execute -n sahana-postgres -- initdb -D /var/lib/postgresql +mkdir -p ${VOLUME_DIR}/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 # Configure Postgres -cp postgres_data/postgresql.conf /srv/sahana/postgres_data/postgresql.conf -cp postgres_data/pg_hba.conf /srv/sahana/postgres_data/pg_hba.conf +cp postgres_data/postgresql.conf ${VOLUME_DIR}/postgres_data/postgresql.conf +cp postgres_data/pg_hba.conf ${VOLUME_DIR}/postgres_data/pg_hba.conf # Create PostgreSQL user and database export SAHANA_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=') -service lxc-sahana-postgres start -envsubst /srv/sahana/sahana_conf/000_config.py -envsubst /srv/sahana/sahana_data/Spotter/masterUsers.csv -cp sahana_conf/00_settings.py /srv/sahana/sahana_conf/00_settings.py -chown -R 108080:108080 /srv/sahana/sahana_conf /srv/sahana/sahana_data +envsubst ${VOLUME_DIR}/sahana_conf/000_config.py +envsubst ${VOLUME_DIR}/sahana_data/Spotter/masterUsers.csv +cp sahana_conf/00_settings.py ${VOLUME_DIR}/sahana_conf/00_settings.py +chown -R ${SAHANA_NSUID}:${SAHANA_NSGID} ${VOLUME_DIR}/sahana_conf ${VOLUME_DIR}/sahana_data # Populate database -lxc-execute -u 8080 -g 8080 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 if [ ${DEBUG:-0} -eq 0 ]; then - sed -i 's/settings.base.migrate = True/settings.base.migrate = False/' /srv/sahana/sahana_conf/000_config.py - sed -i 's/settings.base.debug = True/settings.base.debug = False/' /srv/sahana/sahana_conf/000_config.py - sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' /srv/sahana/sahana_conf/000_config.py + sed -i 's/settings.base.migrate = True/settings.base.migrate = False/' ${VOLUME_DIR}/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.prepopulate = 0/settings.base.prepopulate = 0/' ${VOLUME_DIR}/sahana_conf/000_config.py fi # Install config update script -cp update-conf.sh /srv/sahana/update-conf.sh +cp update-conf.sh ${VOLUME_DIR}/update-conf.sh # Stop services required for setup -service lxc-sahana-postgres stop +spoc-container stop sahana-postgres # Register application -vmmgr register-app sahana sahana "${SAHANA_ADMIN_USER}" "${SAHANA_ADMIN_PWD}" +#vmmgr register-app sahana sahana "${SAHANA_ADMIN_USER}" "${SAHANA_ADMIN_PWD}"