GitLab CI Django 和 Postgres

GitLab CI Django and Postgres

我在让 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.

上工作

谢谢!

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

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

    }
}