python - 如何修复 Unix 域套接字“/var/run/postgresql/.s.PGSQL.5432”上的连接?运行 bitbucket 管道时出错
问题描述
我正在尝试使用 bitbucket 管道运行测试,但不幸的是,我无法连接到 postgresql。
所以我尝试添加rm -rf /tmp/.s.PGSQL.5432/
到我的 bitbucket-pipeline.yml 但运行测试时没有任何改变
这是我得到的错误
+ 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
设置.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'db_name',
'USER': 'user_name',
'PASSWORD': 'db_password',
}
}
我希望 bitbucket 管道能够毫无问题地运行测试,尤其是数据库连接问题
解决方案
您将需要使用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
推荐阅读
- c++ - 是否有可能使模板函数成为一堆类似类的朋友?
- python - Python Google Cloud Function 中的 Paho-MQTT 连接失败
- entity-framework - 错误后如何重置实体框架数据上下文
- mongodb - 在数据库上构建社交网络:图与关系......还是两者兼而有之?
- python - django 上的 Tf 异议检测 API 部署
- mysql - 检索表中每条记录的外部表中记录的运行总数
- typeorm - TypeOrm - 自定义多对多不提取关系数据
- oracle - SAML 断言 ID
- reactjs - 如何使用 useState 设置数组的状态?
- flutter - 如何在滚动时隐藏底部导航栏