Make Sahana Setup module compatible with Alpine containers, closes #311

This commit is contained in:
Disassembler 2020-05-04 11:04:29 +02:00
parent 04c9795586
commit b1ff00e36b
Signed by: Disassembler
GPG Key ID: 524BD33A0EE29499
16 changed files with 42 additions and 178 deletions

View File

@ -1,5 +1,5 @@
{ {
"version": "0.0.1-200426", "version": "1.0.3-200504",
"meta": { "meta": {
"title": "Sahana Eden - SAFIRE", "title": "Sahana Eden - SAFIRE",
"desc-cs": "Řízení humanítární činnosti - Řešení nouzových událostí", "desc-cs": "Řízení humanítární činnosti - Řešení nouzových událostí",
@ -8,7 +8,7 @@
}, },
"containers": { "containers": {
"safire": { "safire": {
"image": "sahana_0.0.1-200426", "image": "sahana_1.0.3-200504",
"depends": [ "depends": [
"safire-postgres" "safire-postgres"
], ],

View File

@ -5,7 +5,7 @@ set -ev
POSTGRES_DATA="${VOLUMES_DIR}/safire/postgres_data" POSTGRES_DATA="${VOLUMES_DIR}/safire/postgres_data"
SAHANA_DATA="${VOLUMES_DIR}/safire/sahana_data" SAHANA_DATA="${VOLUMES_DIR}/safire/sahana_data"
SAHANA_CONF="${VOLUMES_DIR}/safire/sahana_conf" 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 # Create Postgres instance
install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA} install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA}

View File

@ -1,5 +1,5 @@
{ {
"version": "0.0.1-200426", "version": "1.0.3-200504",
"meta": { "meta": {
"title": "Sahana Eden - Demo", "title": "Sahana Eden - Demo",
"desc-cs": "Řízení humanítární činnosti - Demo instance", "desc-cs": "Řízení humanítární činnosti - Demo instance",
@ -8,7 +8,7 @@
}, },
"containers": { "containers": {
"sahana-demo": { "sahana-demo": {
"image": "sahana_0.0.1-200426", "image": "sahana_1.0.3-200504",
"depends": [ "depends": [
"sahana-demo-postgres" "sahana-demo-postgres"
], ],

View File

@ -5,7 +5,7 @@ set -ev
POSTGRES_DATA="${VOLUMES_DIR}/sahana-demo/postgres_data" POSTGRES_DATA="${VOLUMES_DIR}/sahana-demo/postgres_data"
SAHANA_DATA="${VOLUMES_DIR}/sahana-demo/sahana_data" SAHANA_DATA="${VOLUMES_DIR}/sahana-demo/sahana_data"
SAHANA_CONF="${VOLUMES_DIR}/sahana-demo/sahana_conf" 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 # Create Postgres instance
install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA} install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA}

View File

@ -1,5 +1,5 @@
{ {
"version": "0.0.1-200426", "version": "1.0.3-200504",
"meta": { "meta": {
"title": "Sahana Eden", "title": "Sahana Eden",
"desc-cs": "Řízení humanítární činnosti", "desc-cs": "Řízení humanítární činnosti",
@ -8,7 +8,7 @@
}, },
"containers": { "containers": {
"sahana": { "sahana": {
"image": "sahana_0.0.1-200426", "image": "sahana_1.0.3-200504",
"depends": [ "depends": [
"sahana-postgres" "sahana-postgres"
], ],

View File

@ -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 FROM alpine3.11-python3.8_3.8.2-200403
RUN EOF RUN EOF
# Install runtime dependencies # 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 # Install build dependencies
apk --no-cache add --virtual .deps build-base freetype-dev git 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
@ -17,18 +17,19 @@ RUN EOF
ln -s handlers/wsgihandler.py /srv/web2py/wsgihandler.py ln -s handlers/wsgihandler.py /srv/web2py/wsgihandler.py
# Install Sahana # 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 # 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/^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/^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/^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 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 -r /srv/web2py/applications/eden/optional_requirements.txt
pip3 install translate-toolkit 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 # 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-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 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 # Patch web2py for python 3.8
cd /srv/web2py cd /srv/web2py
patch -p0 </tmp/compat.patch patch -p0 </srv/web2py/applications/eden/private/eden_deploy/roles/common/files/_compat.patch
cd /srv/web2py/gluon
patch -p0 </srv/web2py/applications/eden/private/eden_deploy/roles/common/files/scheduler.diff
# 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 /root/.cache rm -r /root/.cache
rm /tmp/compat.patch
EOF EOF
CMD /bin/s6-svscan /etc/services.d CMD /bin/s6-svscan /etc/services.d

View File

@ -1,4 +1,5 @@
#!/bin/execlineb -P #!/bin/execlineb -P
foreground { s6-svwait -d -t 3000 atd }
foreground { s6-svwait -d -t 3000 nginx } foreground { s6-svwait -d -t 3000 nginx }
foreground { s6-svwait -d -t 3000 uwsgi } foreground { s6-svwait -d -t 3000 uwsgi }

View File

@ -0,0 +1,3 @@
#!/bin/execlineb -P
atd -f

View File

@ -0,0 +1 @@
sahana ALL=(ALL) NOPASSWD:ALL

View File

@ -1,156 +0,0 @@
--- gluon/compileapp.py
+++ gluon/compileapp.py
@@ -61,7 +61,7 @@
TEST_CODE = \
r"""
def _TEST():
- import doctest, sys, cStringIO, types, cgi, gluon.fileutils
+ import doctest, sys, cStringIO, types, gluon.fileutils
if not gluon.fileutils.check_credentials(request):
raise HTTP(401, web2py_error='invalid credentials')
stdout = sys.stdout
--- gluon/globals.py
+++ gluon/globals.py
@@ -241,7 +241,15 @@
# parse POST variables on POST, PUT, BOTH only in post_vars
if body and not is_json and env.request_method in ('POST', 'PUT', 'DELETE', 'BOTH'):
query_string = env.pop('QUERY_STRING', None)
- dpost = cgi.FieldStorage(fp=body, environ=env, keep_blank_values=1)
+ content_disposition = env.get('HTTP_CONTENT_DISPOSITION')
+ if content_disposition:
+ headers = {'content-disposition': content_disposition,
+ 'content-type': env['CONTENT_TYPE'],
+ 'content-length': env['CONTENT_LENGTH'],
+ }
+ else:
+ headers = None
+ dpost = cgi.FieldStorage(fp=body, environ=env, headers=headers, keep_blank_values=1)
try:
post_vars.update(dpost)
except:
--- gluon/languages.py
+++ gluon/languages.py
@@ -16,7 +16,6 @@
import sys
import pkgutil
import logging
-from cgi import escape
from threading import RLock
from pydal._compat import copyreg, PY2, maketrans, iterkeys, unicodeT, to_unicode, to_bytes, iteritems, to_native, pjoin
--- gluon/packages/dal/pydal/_compat.py
+++ gluon/packages/dal/pydal/_compat.py
@@ -32,7 +32,6 @@
from urllib2 import urlopen
from string import maketrans
from types import ClassType
- import cgi
import cookielib
from xmlrpclib import ProtocolError
BytesIO = StringIO
--- gluon/packages/dal/pydal/adapters/oracle.py
+++ gluon/packages/dal/pydal/adapters/oracle.py
@@ -96,7 +96,7 @@
return self.dialect.quote(tablename)
def _build_value_for_insert(self, field, value, r_values):
- if field.type is 'text':
+ if field.type == 'text':
r_values[':' + field._rname] = self.expand(value, field.type)
return ':' + field._rname
return self.expand(value, field.type)
--- gluon/packages/dal/pydal/contrib/portalocker.py
+++ gluon/packages/dal/pydal/contrib/portalocker.py
@@ -193,6 +193,9 @@
def read(self, size=None):
return self.file.read() if size is None else self.file.read(size)
+ def readinto(self, b):
+ b[:] = self.file.read()
+
def readline(self):
return self.file.readline()
--- gluon/packages/dal/pydal/dialects/postgre.py
+++ gluon/packages/dal/pydal/dialects/postgre.py
@@ -130,8 +130,8 @@
return rv
def st_asgeojson(self, first, second, query_env={}):
- return 'ST_AsGeoJSON(%s,%s,%s,%s)' % (
- second['version'], self.expand(first, query_env=query_env),
+ return 'ST_AsGeoJSON(%s,%s,%s)' % (
+ self.expand(first, query_env=query_env),
second['precision'], second['options'])
def st_astext(self, first, query_env={}):
@@ -258,8 +258,8 @@
return 'ST_AsText(%s)' % self.expand(first, query_env=query_env)
def st_asgeojson(self, first, second, query_env={}):
- return 'ST_AsGeoJSON(%s,%s,%s,%s)' % (
- second['version'], self.expand(first, query_env=query_env),
+ return 'ST_AsGeoJSON(%s,%s,%s)' % (
+ self.expand(first, query_env=query_env),
second['precision'], second['options'])
def json_key(self, first, key, query_env=None):
--- gluon/packages/dal/pydal/helpers/classes.py
+++ gluon/packages/dal/pydal/helpers/classes.py
@@ -532,6 +532,9 @@
self.p += len(data)
return data
+ def readinto(self, bytes):
+ return self.read(bytes)
+
def readline(self):
i = self.data.find('\n', self.p)+1
if i > 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:

View File

@ -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

View File

@ -5,7 +5,7 @@ set -ev
POSTGRES_DATA="${VOLUMES_DIR}/sahana/postgres_data" POSTGRES_DATA="${VOLUMES_DIR}/sahana/postgres_data"
SAHANA_DATA="${VOLUMES_DIR}/sahana/sahana_data" SAHANA_DATA="${VOLUMES_DIR}/sahana/sahana_data"
SAHANA_CONF="${VOLUMES_DIR}/sahana/sahana_conf" 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 # Create Postgres instance
install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA} install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA}

View File

@ -1,5 +1,5 @@
{ {
"version": "0.0.1-200426", "version": "1.0.3-200504",
"meta": { "meta": {
"title": "Sahana Eden - SAMBRO", "title": "Sahana Eden - SAMBRO",
"desc-cs": "Řízení humanítární činnosti - Centrum hlášení a výstrah", "desc-cs": "Řízení humanítární činnosti - Centrum hlášení a výstrah",
@ -8,7 +8,7 @@
}, },
"containers": { "containers": {
"sambro": { "sambro": {
"image": "sahana_0.0.1-200426", "image": "sahana_1.0.3-200504",
"depends": [ "depends": [
"sambro-postgres" "sambro-postgres"
], ],

View File

@ -5,7 +5,7 @@ set -ev
POSTGRES_DATA="${VOLUMES_DIR}/sambro/postgres_data" POSTGRES_DATA="${VOLUMES_DIR}/sambro/postgres_data"
SAHANA_DATA="${VOLUMES_DIR}/sambro/sahana_data" SAHANA_DATA="${VOLUMES_DIR}/sambro/sahana_data"
SAHANA_CONF="${VOLUMES_DIR}/sambro/sahana_conf" 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 # Create Postgres instance
install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA} install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA}

View File

@ -1,5 +1,5 @@
{ {
"version": "0.0.1-200426", "version": "1.0.3-200504",
"meta": { "meta": {
"title": "Sahana Eden - SHARE", "title": "Sahana Eden - SHARE",
"desc-cs": "Řízení humanítární činnosti - Úleva a rehabilitace", "desc-cs": "Řízení humanítární činnosti - Úleva a rehabilitace",
@ -8,7 +8,7 @@
}, },
"containers": { "containers": {
"share": { "share": {
"image": "sahana_0.0.1-200426", "image": "sahana_1.0.3-200504",
"depends": [ "depends": [
"share-postgres" "share-postgres"
], ],

View File

@ -5,7 +5,7 @@ set -ev
POSTGRES_DATA="${VOLUMES_DIR}/share/postgres_data" POSTGRES_DATA="${VOLUMES_DIR}/share/postgres_data"
SAHANA_DATA="${VOLUMES_DIR}/share/sahana_data" SAHANA_DATA="${VOLUMES_DIR}/share/sahana_data"
SAHANA_CONF="${VOLUMES_DIR}/share/sahana_conf" 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 # Create Postgres instance
install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA} install -o 105432 -g 105432 -m 700 -d ${POSTGRES_DATA}