设置与 django 3、postgres 和 gitlab CI 的持续集成

时间:2021-06-15 10:18:42

标签: django postgresql gitlab-ci django-3.2

我正在设置与 Django 3 和 Gitlab CI 的持续集成。

以前用 Django 2 完成过,但现在我正在努力用 Django 3 完成。 显示此警告,我想知道是否是原因:

<块引用>

/usr/local/lib/python3.8/site-packages/django/db/backends/postgresql/base.py:304: RuntimeWarning: 通常 Django 将使用到 'postgres' 数据库的连接来避免运行初始化在不需要时(例如,在运行测试时)对生产数据库进行查询。 Django 无法创建到“postgres”数据库的连接,而是使用第一个 PostgreSQL 数据库。

最后出现这个错误:

<块引用>

django.db.utils.OperationalError:无法将主机名“postgres”转换为地址:名称或服务未知

这是我的配置:

    image: python:3.8
    
    services:
      - postgres:10.17

    variables:
      POSTGRES_DB : db_test
      POSTGRES_USER : postgres
      POSTGRES_PASSWORD : ""
      POSTGRES_HOST : postgres
      POSTGRES_PORT : 5432

    stages:
      - tests

    cache:
      paths:
      - ~/.cache/pip/

    before_script:
      - python -V
      - apt-get update && apt install -y -qq python3-pip
      - pip install -r requirements.txt

    test:
      stage: tests
      variables:
        DATABASE_URL: "postgres://postgres:postgres@postgres:5432/$POSTGRES_DB"
      script:
      - coverage run manage.py test
      - coverage report
      coverage: "/TOTAL.+ ([0-9]{1,3}%)/"

如果有人能帮我解决这个问题,我将不胜感激。

0 个答案:

没有答案