简体   繁体   English

如何在 gitlab-ci.yml 中将 postgis 扩展添加到 postgresql 数据库

[英]How to add postgis extension to postgresql database in gitlab-ci.yml

I'm setting up test stage in gitlab-ci.yml file and I have error, when config postgis extension for postgresql databese.我正在gitlab-ci.yml文件中设置测试阶段,但在为 postgresql 数据库配置 postgis 扩展时出现错误。

I need DATABASE_URL, like postgis://... for my Django env我需要 DATABASE_URL,例如postgis://...用于我的 Django 环境

My latest version of gitlab-ci.yml :我的最新版本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 error response: Gitlab 管道错误响应:

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

Try to use alternative option from django documentation :尝试使用django 文档中的替代选项:

from django.contrib.postgres.operations import CreateExtension
from django.db import migrations

class Migration(migrations.Migration):

    operations = [
        CreateExtension('postgis'),
        ...
    ]

You can use a service that already has postgis and install the binary files, like this:您可以使用已有 postgis 的服务并安装二进制文件,如下所示:

services:
  - mdillon/postgis:9.4

variables:
  POSTGRES_DB: "db_name"
  POSTGRES_USER: "db_user"
  POSTGRES_PASSWORD: "db_pwd"
  POSTGRES_HOST: "db"
  POSTGRES_PORT: "5432"
  DATABASE_URL: 
  "postgres://db_user:db_pwd@mdillon__postgis/db_name"

before_script:
  - apt-get update -qy
  - apt-get -y install binutils libproj-dev gdal-bin
  - python -V
  - pip3 install -r requirements.txt

References: - https://www.hackzine.org/postgis-on-gitlab-ci.html参考资料: - https://www.hackzine.org/postgis-on-gitlab-ci.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的 first.gitlab-ci.yml 文件:如何在 CI/CD 中运行现有文件 - My first .gitlab-ci.yml file: How to run existing files in CI/CD 如何在 Gitlab 中为简单的 hello world 程序配置 gitlab-ci.yml - How do I configure gitlab-ci.yml for a simple hello world program in Gitlab 在Gitlab中配置.gitlab-ci.yml文件以测试python代码 - Configuring .gitlab-ci.yml file in Gitlab to test python Codes 如何避免在.gitlab-ci.yml的每个阶段之前安装requirements.txt? - How to avoid installing requirements.txt before every stage in .gitlab-ci.yml? 如何解析我有权访问的所有存储库中的所有.gitlab-ci.yml 文件? - How to parse all the .gitlab-ci.yml files from all the repositories that i have access to? 如何从 .gitlab-ci.yml 文件中提取单个管道名称? - How to extract individual Pipeline names from .gitlab-ci.yml file? gitlab-ci.yml:“脚本:-pytest”命令无法识别 - gitlab-ci.yml: 'script: -pytest' command is not recognized gitlab-ci.yml python -c'多行cmd'失败 - gitlab-ci.yml python -c 'multiple line cmd' failed 使用 pyyaml 的 Load.gitlab-ci.yml 失败,无法确定构造函数 - Load .gitlab-ci.yml with pyyaml fails with could not determine constructor Gitlabci 管道失败:gitlab-ci.yml 中规则中的语法错误 - Gitlabci pipline failes with: syntax error in rules in gitlab-ci.yml
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM