Django和postgis使用openshift v3进行postgres

时间:2017-05-30 11:33:55

标签: django openshift postgis

我是openshift v3的新手,我正在尝试部署使用postgres后端的django应用程序。我使用示例https://github.com/openshift/django-ex作为起点,其中我删除了示例应用并添加了我自己的应用和代码。我正在使用模板django-postgresql-persistent.json的编辑版本从私人仓库部署应用程序。

当我尝试部署时,django容器崩溃而postres容器已部署,尽管存在一些问题。

该应用使用地理搜索,我遇到了我认为的三个问题:

问题#1。我不认为Postgis是作为postgres db的扩展而安装和启用的。我尝试了下面的内容:

postgres=# SELECT PostGIS_full_version();                                                                                             
ERROR:  function postgis_full_version() does not exist                                                                                
LINE 1: SELECT PostGIS_full_version();                                                                                                
               ^                                                                                                                      
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.                              
postgres=# SELECT version();                                                                                                          

-------------------------------------------------------------------------------------------------------------                         
 PostgreSQL 9.5.4 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9), 64-bit                          
(1 row)                                                                                                                               

postgres=# SELECT PostGIS_version();                                                                                                  
ERROR:  function postgis_version() does not exist                                                                                     
LINE 1: SELECT PostGIS_version();                                                                                                     
               ^                                                                                                                      
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.                              
postgres=# CREATE EXTENSION postgis;                                                                                                  
ERROR:  could not open extension control file "/opt/rh/rh-postgresql95/root/usr/share/pgsql/extension/postgis.control": No such file o
r directory

问题:如何安装PostGIS?我似乎没有sudo权限或能够使用yum?

问题2:django容器上的部署日志如下所示。它似乎缺少GEOS lib。这并不是我本地虚拟环境的问题。如何安装这些库/依赖项?可以使用requirements.txt完成吗? django.core.exceptions.ImproperlyConfigured:GEOS是必需的,尚未被检测到。你确定它已安装吗?

问题3:如果有人打算提供静态文件。那么如何处理警告呢? 谢谢。

> ---> Installing application source ...
> ---> Installing dependencies ... Collecting appdirs==1.4.3 (from -r requirements.txt (line 1)) Downloading
> appdirs-1.4.3-py2.py3-none-any.whl Collecting Django==1.8.6 (from -r
> requirements.txt (line 2)) Downloading
> Django-1.8.6-py2.py3-none-any.whl (6.2MB) Collecting
> django-cors-headers==2.0.2 (from -r requirements.txt (line 3))
> Downloading django_cors_headers-2.0.2-py2.py3-none-any.whl Collecting
> django-debug-toolbar==1.5 (from -r requirements.txt (line 4))
> Downloading django_debug_toolbar-1.5-py2.py3-none-any.whl (204kB)
> Collecting gunicorn==19.4.5 (from -r requirements.txt (line 5))
> Downloading gunicorn-19.4.5-py2.py3-none-any.whl (112kB) Collecting
> olefile==0.44 (from -r requirements.txt (line 6)) Downloading
> olefile-0.44.zip (74kB) Collecting packaging==16.8 (from -r
> requirements.txt (line 7)) Downloading
> packaging-16.8-py2.py3-none-any.whl Collecting Pillow==4.1.1 (from -r
> requirements.txt (line 8)) Downloading Pillow-4.1.1.tar.gz (11.3MB)
> Collecting psycopg2==2.6.1 (from -r requirements.txt (line 9))
> Downloading psycopg2-2.6.1.tar.gz (371kB) Collecting pyparsing==2.2.0
> (from -r requirements.txt (line 10)) Downloading
> pyparsing-2.2.0-py2.py3-none-any.whl (56kB) Collecting six==1.10.0
> (from -r requirements.txt (line 11)) Downloading
> six-1.10.0-py2.py3-none-any.whl Collecting sqlparse==0.2.3 (from -r
> requirements.txt (line 12)) Downloading
> sqlparse-0.2.3-py2.py3-none-any.whl Collecting whitenoise==3.0 (from
> -r requirements.txt (line 13)) Downloading whitenoise-3.0-py2.py3-none-any.whl Installing collected packages:
> appdirs, Django, django-cors-headers, sqlparse, django-debug-toolbar,
> gunicorn, olefile, six, pyparsing, packaging, Pillow, psycopg2,
> whitenoise Running setup.py install for olefile Running setup.py
> install for Pillow Running setup.py install for psycopg2 Successfully
> installed Django-1.8.6 Pillow-4.1.1 appdirs-1.4.3
> django-cors-headers-2.0.2 django-debug-toolbar-1.5 gunicorn-19.4.5
> olefile-0.44 packaging-16.8 psycopg2-2.6.1 pyparsing-2.2.0 six-1.10.0
> sqlparse-0.2.3 whitenoise-3.0 You are using pip version 7.1.2, however
> version 9.0.1 is available. You should consider upgrading via the 'pip
> install --upgrade pip' command.
> ---> Collecting Django static files ... WARNING: could not run 'manage.py collectstatic'. To debug, run: $ python ./manage.py
> collectstatic --noinput Ignore this warning if you're not serving
> static files with Django. chgrp: changing group of
> ‘/opt/app-root/include/python3.5m’: Operation not permitted chgrp:
> changing group of ‘/opt/app-root/lib/python3.5/copy.py’: Operation not
> permitted chgrp: changing group of
> ‘/opt/app-root/lib/python3.5/token.py’: Operation not permitted ... 
> ... chgrp: changing group of
> ‘/opt/app-root/lib/python3.5/sre_compile.py’: Operation not permitted
> chgrp: changing group of ‘/opt/app-root/lib/python3.5/keyword.py’:
> Operation not permitted chgrp: changing group of
> ‘/opt/app-root/lib/python3.5/tempfile.py’: Operation not permitted
> chgrp: changing group of ‘/opt/app-root/lib/python3.5/base64.py’:
> Operation not permitted ... chgrp: changing group of
> ‘/opt/app-root/lib64/python3.5/functools.py’: Operation not permitted
> chgrp: changing group of ‘/opt/app-root/lib64/python3.5/config-3.5m’:
> Operation not permitted ... chmod: changing permissions of
> ‘/opt/app-root/lib/python3.5/abc.py’: Operation not permitted chmod:
> changing permissions of ‘/opt/app-root/lib/python3.5/heapq.py’:
> Operation not permitted chmod: changing permissions of
> ‘/opt/app-root/lib64/python3.5/_collections_abc.py’: Operation not
> permitted chmod: changing permissions of
> ‘/opt/app-root/lib64/python3.5/warnings.py’: Operation not permitted
> chmod: changing permissions of
> ‘/opt/app-root/lib64/python3.5/lib-dynload’: Operation not permitted
> chmod: changing permissions of
> ‘/opt/app-root/lib64/python3.5/plat-linux’: Operation not permitted
> Running post commit hook ... sh: cannot set terminal process group
> (-1): Inappropriate ioctl for device sh: no job control in this shell
> Traceback (most recent call last):   File "./manage.py", line 10, in
> <module>
>     execute_from_command_line(sys.argv)   File "/opt/app-root/lib/python3.5/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
>     utility.execute()   File "/opt/app-root/lib/python3.5/site-packages/django/core/management/__init__.py", line 328, in execute
>     django.setup()   File "/opt/app-root/lib/python3.5/site-packages/django/__init__.py", line
> 18, in setup
>     apps.populate(settings.INSTALLED_APPS)   File "/opt/app-root/lib/python3.5/site-packages/django/apps/registry.py",
> line 108, in populate
>     app_config.import_models(all_models)   File "/opt/app-root/lib/python3.5/site-packages/django/apps/config.py",
> line 198, in import_models
>     self.models_module = import_module(models_module_name)   File "/opt/app-root/lib64/python3.5/importlib/__init__.py", line 126, in
> import_module
>     return _bootstrap._gcd_import(name[level:], package, level)   File "<frozen importlib._bootstrap>", line 986, in _gcd_import   File
> "<frozen importlib._bootstrap>", line 969, in _find_and_load   File
> "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked 
> File "<frozen importlib._bootstrap>", line 673, in _load_unlocked  
> File "<frozen importlib._bootstrap_external>", line 662, in
> exec_module   File "<frozen importlib._bootstrap>", line 222, in
> _call_with_frames_removed   File "/opt/app-root/lib/python3.5/site-packages/django/contrib/auth/models.py",
> line 41, in <module>
>     class Permission(models.Model):   File "/opt/app-root/lib/python3.5/site-packages/django/db/models/base.py",
> line 139, in __new__
>     new_class.add_to_class('_meta', Options(meta, **kwargs))   File "/opt/app-root/lib/python3.5/site-packages/django/db/models/base.py",
> line 324, in add_to_class
>     value.contribute_to_class(cls, name)   File "/opt/app-root/lib/python3.5/site-packages/django/db/models/options.py",
> line 250, in contribute_to_class
>     self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())   File
> "/opt/app-root/lib/python3.5/site-packages/django/db/__init__.py",
> line 36, in __getattr__
>     return getattr(connections[DEFAULT_DB_ALIAS], item)   File "/opt/app-root/lib/python3.5/site-packages/django/db/utils.py", line
> 241, in __getitem__
>     backend = load_backend(db['ENGINE'])   File "/opt/app-root/lib/python3.5/site-packages/django/db/utils.py", line
> 112, in load_backend
>     return import_module('%s.base' % backend_name)   File "/opt/app-root/lib64/python3.5/importlib/__init__.py", line 126, in
> import_module
>     return _bootstrap._gcd_import(name[level:], package, level)   File "<frozen importlib._bootstrap>", line 986, in _gcd_import   File
> "<frozen importlib._bootstrap>", line 969, in _find_and_load   File
> "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked 
> File "<frozen importlib._bootstrap>", line 673, in _load_unlocked  
> File "<frozen importlib._bootstrap_external>", line 662, in
> exec_module   File "<frozen importlib._bootstrap>", line 222, in
> _call_with_frames_removed   File "/opt/app-root/lib/python3.5/site-packages/django/contrib/gis/db/backends/postgis/base.py",
> line 8, in <module>
>     from .features import DatabaseFeatures   File "/opt/app-root/lib/python3.5/site-packages/django/contrib/gis/db/backends/postgis/features.py", line 1, in <module>
>     from django.contrib.gis.db.backends.base.features import BaseSpatialFeatures   File
> "/opt/app-root/lib/python3.5/site-packages/django/contrib/gis/db/backends/base/features.py",
> line 3, in <module>
>     from django.contrib.gis.db.models import aggregates   File "/opt/app-root/lib/python3.5/site-packages/django/contrib/gis/db/models/__init__.py",
> line 12, in <module>
>     django.core.exceptions.ImproperlyConfigured: GEOS is required and has not been detected. Are you sure it is installed? See also
> https://docs.djangoproject.com/en/1.8/ref/contrib/gis/install/geolibs/
> error: build error: container
> "openshift_s2i-build_django-psql-persistent-2_second-deploy_post-commit_0a7f4e7f"
> returned non-zero exit code: 1

0 个答案:

没有答案