![](/img/trans.png)
[英]My first .gitlab-ci.yml file: How to run existing files in CI/CD
[英]How to add postgis extension to postgresql database in gitlab-ci.yml
我正在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 管道錯誤響應:
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'),
...
]
您可以使用已有 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.