From b1ff00e36bcaef93d7904d336129817944d05be2 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Mon, 4 May 2020 11:04:29 +0200 Subject: [PATCH] Make Sahana Setup module compatible with Alpine containers, closes #311 --- lxc-apps/safire/app | 4 +- lxc-apps/safire/install.sh | 2 +- lxc-apps/sahana-demo/app | 4 +- lxc-apps/sahana-demo/install.sh | 2 +- lxc-apps/sahana/app | 4 +- lxc-apps/sahana/image | 16 +- .../image.d/etc/services.d/.s6-svscan/finish | 1 + .../sahana/image.d/etc/services.d/atd/run | 3 + lxc-apps/sahana/image.d/etc/sudoers.d/sahana | 1 + lxc-apps/sahana/image.d/tmp/compat.patch | 156 ------------------ lxc-apps/sahana/image.d/usr/local/bin/migrate | 13 ++ lxc-apps/sahana/install.sh | 2 +- lxc-apps/sambro/app | 4 +- lxc-apps/sambro/install.sh | 2 +- lxc-apps/share/app | 4 +- lxc-apps/share/install.sh | 2 +- 16 files changed, 42 insertions(+), 178 deletions(-) create mode 100755 lxc-apps/sahana/image.d/etc/services.d/atd/run create mode 100644 lxc-apps/sahana/image.d/etc/sudoers.d/sahana delete mode 100644 lxc-apps/sahana/image.d/tmp/compat.patch create mode 100755 lxc-apps/sahana/image.d/usr/local/bin/migrate diff --git a/lxc-apps/safire/app b/lxc-apps/safire/app index 4afef19..a44797c 100644 --- a/lxc-apps/safire/app +++ b/lxc-apps/safire/app @@ -1,5 +1,5 @@ { - "version": "0.0.1-200426", + "version": "1.0.3-200504", "meta": { "title": "Sahana Eden - SAFIRE", "desc-cs": "Řízení humanítární činnosti - Řešení nouzových událostí", @@ -8,7 +8,7 @@ }, "containers": { "safire": { - "image": "sahana_0.0.1-200426", + "image": "sahana_1.0.3-200504", "depends": [ "safire-postgres" ], diff --git a/lxc-apps/safire/install.sh b/lxc-apps/safire/install.sh index 3d5c543..1d9b0e9 100755 --- a/lxc-apps/safire/install.sh +++ b/lxc-apps/safire/install.sh @@ -5,7 +5,7 @@ set -ev POSTGRES_DATA="${VOLUMES_DIR}/safire/postgres_data" SAHANA_DATA="${VOLUMES_DIR}/safire/sahana_data" SAHANA_CONF="${VOLUMES_DIR}/safire/sahana_conf" -SAHANA_LAYER="${LAYERS_DIR}/sahana_0.0.1-200426" +SAHANA_LAYER="${LAYERS_DIR}/sahana_1.0.3-200504" # Create Postgres instance install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA} diff --git a/lxc-apps/sahana-demo/app b/lxc-apps/sahana-demo/app index 4ac2ea9..d4012e6 100644 --- a/lxc-apps/sahana-demo/app +++ b/lxc-apps/sahana-demo/app @@ -1,5 +1,5 @@ { - "version": "0.0.1-200426", + "version": "1.0.3-200504", "meta": { "title": "Sahana Eden - Demo", "desc-cs": "Řízení humanítární činnosti - Demo instance", @@ -8,7 +8,7 @@ }, "containers": { "sahana-demo": { - "image": "sahana_0.0.1-200426", + "image": "sahana_1.0.3-200504", "depends": [ "sahana-demo-postgres" ], diff --git a/lxc-apps/sahana-demo/install.sh b/lxc-apps/sahana-demo/install.sh index 03fa0cd..98a79c7 100755 --- a/lxc-apps/sahana-demo/install.sh +++ b/lxc-apps/sahana-demo/install.sh @@ -5,7 +5,7 @@ set -ev POSTGRES_DATA="${VOLUMES_DIR}/sahana-demo/postgres_data" SAHANA_DATA="${VOLUMES_DIR}/sahana-demo/sahana_data" SAHANA_CONF="${VOLUMES_DIR}/sahana-demo/sahana_conf" -SAHANA_LAYER="${LAYERS_DIR}/sahana_0.0.1-200426" +SAHANA_LAYER="${LAYERS_DIR}/sahana_1.0.3-200504" # Create Postgres instance install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA} diff --git a/lxc-apps/sahana/app b/lxc-apps/sahana/app index 476dc00..47215e9 100644 --- a/lxc-apps/sahana/app +++ b/lxc-apps/sahana/app @@ -1,5 +1,5 @@ { - "version": "0.0.1-200426", + "version": "1.0.3-200504", "meta": { "title": "Sahana Eden", "desc-cs": "Řízení humanítární činnosti", @@ -8,7 +8,7 @@ }, "containers": { "sahana": { - "image": "sahana_0.0.1-200426", + "image": "sahana_1.0.3-200504", "depends": [ "sahana-postgres" ], diff --git a/lxc-apps/sahana/image b/lxc-apps/sahana/image index 3c374cd..ea1116b 100644 --- a/lxc-apps/sahana/image +++ b/lxc-apps/sahana/image @@ -1,9 +1,9 @@ -IMAGE sahana_0.0.1-200426 +IMAGE sahana_1.0.3-200504 FROM alpine3.11-python3.8_3.8.2-200403 RUN EOF # Install runtime dependencies - apk --no-cache add geos nginx py3-dateutil py3-gdal py3-lxml py3-numpy py3-pillow py3-psycopg2 py3-requests py3-sgmllib3k uwsgi-python3 + apk --no-cache add ansible at geos nginx py3-dateutil py3-gdal py3-lxml py3-numpy py3-pillow py3-psycopg2 py3-requests py3-sgmllib3k py3-yaml uwsgi-python3 sudo # Install build dependencies apk --no-cache add --virtual .deps build-base freetype-dev git py3-numpy-dev py3-pip python3-dev ttf-dejavu @@ -17,18 +17,19 @@ RUN EOF ln -s handlers/wsgihandler.py /srv/web2py/wsgihandler.py # Install Sahana - git clone --depth 1 https://github.com/sahana/eden.git /srv/web2py/applications/eden + git clone --recursive --depth 1 https://github.com/sahana/eden.git /srv/web2py/applications/eden # Install python dependencies, exclude old or unnecessary ones sed -i 's/^Pillow/#Pillow/' /srv/web2py/applications/eden/optional_requirements.txt # We have 6.2.1, Sahana requires 6.2.2 - sed -i 's/^ansible/#ansible/' /srv/web2py/applications/eden/optional_requirements.txt # Needed for setup sed -i 's/^boto/#boto/' /srv/web2py/applications/eden/optional_requirements.txt # Needed for setup on AWS sed -i 's/^PyRTF/#PyRTF/' /srv/web2py/applications/eden/optional_requirements.txt # Ceased to exist - sed -i 's/^PyYAML/#PyYAML/' /srv/web2py/applications/eden/optional_requirements.txt # Needed for setup sed -i 's/^openst/#openst/' /srv/web2py/applications/eden/optional_requirements.txt # Needed for setup on OpenStack pip3 install -r /srv/web2py/applications/eden/optional_requirements.txt pip3 install translate-toolkit + # Hackfix paths for ansible and other modules with hardcoded paths + ln -s /srv/web2py /home/prod + # Copy fonts with Czech glyphs cp /usr/share/fonts/ttf-dejavu/DejaVuSerif-Bold.ttf /srv/web2py/applications/eden/static/fonts/Helvetica-Bold.ttf cp /usr/share/fonts/ttf-dejavu/DejaVuSerif.ttf /srv/web2py/applications/eden/static/fonts/Helvetica.ttf @@ -44,13 +45,14 @@ RUN EOF # 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/image.d/usr/local/bin/migrate b/lxc-apps/sahana/image.d/usr/local/bin/migrate new file mode 100755 index 0000000..0aa881f --- /dev/null +++ b/lxc-apps/sahana/image.d/usr/local/bin/migrate @@ -0,0 +1,13 @@ +#!/bin/sh + +# This is a compatible rewrite of https://github.com/sahana/eden_deploy/blob/master/roles/common/files/migrate specific for Alpine s6-based container + +# Migrate database +cd /srv/web2py +sed -i 's/settings.base.migrate = False/settings.base.migrate = True/g' applications/eden/models/000_config.py +rm -rf applications/eden/compiled +sudo -u sahana -- ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py +sed -i 's/settings.base.migrate = True/settings.base.migrate = False/g' applications/eden/models/000_config.py + +# Restart uwsgi +s6-svc -t /etc/services.d/uwsgi diff --git a/lxc-apps/sahana/install.sh b/lxc-apps/sahana/install.sh index f1efd67..bd7d33c 100755 --- a/lxc-apps/sahana/install.sh +++ b/lxc-apps/sahana/install.sh @@ -5,7 +5,7 @@ set -ev POSTGRES_DATA="${VOLUMES_DIR}/sahana/postgres_data" SAHANA_DATA="${VOLUMES_DIR}/sahana/sahana_data" SAHANA_CONF="${VOLUMES_DIR}/sahana/sahana_conf" -SAHANA_LAYER="${LAYERS_DIR}/sahana_0.0.1-200426" +SAHANA_LAYER="${LAYERS_DIR}/sahana_1.0.3-200504" # Create Postgres instance install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA} diff --git a/lxc-apps/sambro/app b/lxc-apps/sambro/app index 134f9df..aa7160e 100644 --- a/lxc-apps/sambro/app +++ b/lxc-apps/sambro/app @@ -1,5 +1,5 @@ { - "version": "0.0.1-200426", + "version": "1.0.3-200504", "meta": { "title": "Sahana Eden - SAMBRO", "desc-cs": "Řízení humanítární činnosti - Centrum hlášení a výstrah", @@ -8,7 +8,7 @@ }, "containers": { "sambro": { - "image": "sahana_0.0.1-200426", + "image": "sahana_1.0.3-200504", "depends": [ "sambro-postgres" ], diff --git a/lxc-apps/sambro/install.sh b/lxc-apps/sambro/install.sh index 77791d5..31cac60 100755 --- a/lxc-apps/sambro/install.sh +++ b/lxc-apps/sambro/install.sh @@ -5,7 +5,7 @@ set -ev POSTGRES_DATA="${VOLUMES_DIR}/sambro/postgres_data" SAHANA_DATA="${VOLUMES_DIR}/sambro/sahana_data" SAHANA_CONF="${VOLUMES_DIR}/sambro/sahana_conf" -SAHANA_LAYER="${LAYERS_DIR}/sahana_0.0.1-200426" +SAHANA_LAYER="${LAYERS_DIR}/sahana_1.0.3-200504" # Create Postgres instance install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA} diff --git a/lxc-apps/share/app b/lxc-apps/share/app index eff3467..5da5942 100644 --- a/lxc-apps/share/app +++ b/lxc-apps/share/app @@ -1,5 +1,5 @@ { - "version": "0.0.1-200426", + "version": "1.0.3-200504", "meta": { "title": "Sahana Eden - SHARE", "desc-cs": "Řízení humanítární činnosti - Úleva a rehabilitace", @@ -8,7 +8,7 @@ }, "containers": { "share": { - "image": "sahana_0.0.1-200426", + "image": "sahana_1.0.3-200504", "depends": [ "share-postgres" ], diff --git a/lxc-apps/share/install.sh b/lxc-apps/share/install.sh index f9bfb0d..5763bf4 100755 --- a/lxc-apps/share/install.sh +++ b/lxc-apps/share/install.sh @@ -5,7 +5,7 @@ set -ev POSTGRES_DATA="${VOLUMES_DIR}/share/postgres_data" SAHANA_DATA="${VOLUMES_DIR}/share/sahana_data" SAHANA_CONF="${VOLUMES_DIR}/share/sahana_conf" -SAHANA_LAYER="${LAYERS_DIR}/sahana_0.0.1-200426" +SAHANA_LAYER="${LAYERS_DIR}/sahana_1.0.3-200504" # Create Postgres instance install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA}