python - 如何在 gitlab-ci.yml 中向 postgresql 数据库添加 postgis 扩展
问题描述
我正在文件中设置测试阶段gitlab-ci.yml
,但在为 postgresql 数据库配置 postgis 扩展时出现错误。
我需要 DATABASE_URL,就像postgis://...
我的 Django 环境一样
我的最新版本gitlab-ci.yml
:
image: python:3.6
services:
- postgres:9.6
variables:
POSTGRES_DB: test_db
POSTGRES_USER: test_user
POSTGRES_PASSWORD: test_pass
DATABASE_URL: "postgis://test_user:test_pass@postgres:5432/test_db"
stages:
- test
- build
test:
stage: test
script:
- apt-get update -qy
- apt-get -y install binutils libproj-dev gdal-bin postgis*
- pip3 install pipenv
- pipenv install --dev
- export DATABASE_URL=$DATABASE_URL
- pipenv run test
Gitlab Pipeline 错误响应:
Running with gitlab-runner 11.5.0 (3afdaba6)
on docker-auto-scale fa6cab46
Using Docker executor with image python:3.6 ...
Starting service postgres:9.6 ...
Pulling docker image postgres:9.6 ...
$ export DATABASE_URL=$DATABASE_URL
$ pipenv run test
/root/.local/share/virtualenvs/pixel-api-yo4gnz48/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
""")
Creating test database for alias 'default'...
Traceback (most recent call last):
File "/root/.local/share/virtualenvs/pixel-api-yo4gnz48/lib/python3.6/site-packages/django/db/backends/utils.py", line 83, in _execute
return self.cursor.execute(sql)
psycopg2.OperationalError: could not open extension control file "/usr/share/postgresql/9.6/extension/postgis.control": No such file or directory
django.db.utils.OperationalError: could not open extension control file "/usr/share/postgresql/9.6/extension/postgis.control": No such file or directory
解决方案
尝试使用django 文档中的替代选项:
from django.contrib.postgres.operations import CreateExtension
from django.db import migrations
class Migration(migrations.Migration):
operations = [
CreateExtension('postgis'),
...
]
推荐阅读
- javascript - 发生onblur时如何获取textarea的当前编辑值?
- python - 如何为小部件创建不同的字体大小但允许它们在 PySide2 中使用字体对话框进行缩放?
- python - Visual Studio Code - 缺少图标“在终端中运行 Pyrhon 文件”
- asp.net - 发布 Devexpress dll
- python-3.x - 使用 python 和 django 框架工作问题
- objective-c - Swift 代码不能使用继承自 Swift 类的 Obj-C 类?
- css - 如何保持与图像的比例?
- c# - 如何通过 C# 应用程序在文件级别授予 Windows 权限?
- ruby-on-rails - 根据格式路由到不同的操作
- javascript - 字符串化一些 obj 并使浏览器崩溃