【问题标题】:GitLab CI Django and PostgresGitLab CI Django 和 Postgres
【发布时间】:2018-06-02 12:02:24
【问题描述】:

我在让 GitLab 的 CI 与我的 Django 项目一起工作时遇到问题。我正在使用 postgres 服务器,看来我设置了错误。任何帮助将不胜感激!

错误:

django.db.utils.OperationalError: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

我的 .gitlab-ci.yml 文件:

image: python:3.6.1

services:
    - postgres:9.3

variables:
  POSTGRES_DB: project_ci_test
  POSTGRES_USER: postgres
  POSTGRES_PASSWORD: ""

test:
    script:
    - export DATABASE_URL=postgres://postgres:@postgres:5432/project_ci_test
    - apt-get update -qy
    - apt-get install -y python-dev python-pip
    - pip install -r requirements.txt
    - python manage.py makemigrations
    - python manage.py migrate
    - python manage.py test Project

在我的 django 设置文件中:

DATABASES = {
    'default': {
        'ENGINE' : 'django.db.backends.postgresql_psycopg2',
        'NAME' : 'project_ci_test',
        'USER' : 'postgres',
        'PASSWORD': '',

    }
}

我目前正在尝试利用 GitLab 的共享跑步者。我希望有人成功地获得了一个带有 postgres 的 Django 项目,以便在 GitLab 的 CI 上工作。

谢谢!

【问题讨论】:

  • 你好@TylerBell。我也有类似的困境,我对缺乏使用数据库的示例感到有些失望。您的基本原理是在“服务”中“启动”postgres 图像,然后启动它并将其分配到测试的“导出”行中的端口?

标签: django postgresql gitlab gitlab-ci gitlab-ci-runner


【解决方案1】:

终于找到问题所在了。在我的 Django 项目的设置文件中指定主机和端口解决了这个问题!

DATABASES = {
    'default': {
        'ENGINE' : 'django.db.backends.postgresql_psycopg2',
        'NAME' : 'project_ci_test',
        'USER' : 'postgres',
        'PASSWORD': '',
        'HOST' : 'postgres'
        'PORT' : '5432'

    }
}

【讨论】:

    猜你喜欢
    • 2021-09-15
    • 2019-07-08
    • 1970-01-01
    • 1970-01-01
    • 2021-02-27
    • 1970-01-01
    • 1970-01-01
    • 2017-04-08
    • 2020-07-29
    相关资源
    最近更新 更多