как исправить соединения на сокете домена Unix "/var/run/postgresql/.s.PGSQL.5432"? ошибка при запуске конвейеров bitbucket - PullRequest
0 голосов
/ 09 июля 2019

Я пытаюсь запустить тесты с использованием конвейеров bitbucket, но, к сожалению, я не могу соединиться с postgresql.

Поэтому я попытался добавить rm -rf /tmp/.s.PGSQL.5432/ в свой bitbucket-pipeline.yml, но ничего не изменилось при запуске моегоtest

Это ошибка, которую я получаю

+ python manage.py test
/usr/local/lib/python3.7/site-packages/django/db/backends/postgresql/base.py:265: RuntimeWarning: Normally Django will use a connection to the 'postgres' database to avoid running initialization queries against the production database when it's not needed (for example, when running tests). Django was unable to create a connection to the 'postgres' database and will use the first PostgreSQL database instead.
  RuntimeWarning
nosetests --with-coverage --cover-package=accounts,rest_v1, property --verbosity=1
Creating test database for alias 'default'...
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
    self.connect()
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/base.py", line 194, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/local/lib/python3.7/site-packages/django/db/backends/postgresql/base.py", line 174, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/usr/local/lib/python3.7/site-packages/psycopg2/__init__.py", line 130, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.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"?

bitbucket-pipelines.yml

image: python:3.6.2
pipelines:
  default:
    - step:
        script:
          - pip install -r requirements.txt
          - python manage.py test

  branches:
    develop:
    - step:
        caches:
        - node
        script:
        - pip install -r requirements.txt
        - python manage.py test

setting.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'db_name',
        'USER': 'user_name',
        'PASSWORD': 'db_password',
    }
}

Iожидаем, что конвейеры с битовой корзиной выполнят тест без проблем, особенно проблем с подключением к БД

1 Ответ

0 голосов
/ 09 июля 2019

Вы захотите использовать клавишу services и сделать то же самое, что и в definition службы.

pipelines:
    default:
        - step:
            image: node
            script:
              - npm install
              - npm test
            services:
              - postgres

definitions:
  services:
    postgres:
      image: postgres
      environment:
        POSTGRES_DB: pipelines
        POSTGRES_USER: test_user
        POSTGRES_PASSWORD: test_user_password

Источник: https://community.atlassian.com/t5/Bitbucket-questions/How-do-I-use-Postgres-in-Bitbucket-Pipelines/qaq-p/461910

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...