GitLab CI Django 和 Postgres [英] GitLab CI Django and Postgres

查看:19
本文介绍了GitLab CI Django 和 Postgres的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am having an issue getting GitLab's CI to work with my Django project. I am using a postgres server and it appears I have set something up wrong. Any help would be much appreciated!

错误:

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 文件:

My .gitlab-ci.yml file:

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 设置文件中:

In my django settings file:

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

    }
}

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

I am currently trying to utilize GitLab's shared runners. I am hoping someone has successfully gotten a Django project with postgres to work on GitLab's CI.

谢谢!

推荐答案

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

Finally figured out the problem. Specifying the host and port in my Django project's settings file resolved the issue!

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

    }
}

这篇关于GitLab CI Django 和 Postgres的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆