Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在GitLab CI中设置PostgreSQL_Postgresql_Gitlab Ci - Fatal编程技术网

在GitLab CI中设置PostgreSQL

在GitLab CI中设置PostgreSQL,postgresql,gitlab-ci,Postgresql,Gitlab Ci,我正试图在GitLab.com上设置一个CI运行程序,我想用它来运行需要PostgreSQL数据库连接的测试。CI+PostgreSQL的文档似乎过于简单,似乎说明一旦提供了连接信息,数据库设置就完成了。我可能误解了文档,因为我无法创建数据库。我的gitlab ci.yml如下所示 image: node:latest services: - postgres:latest variables: POSTGRES_DB: rx_reactive_test POSTGRES_USE

我正试图在GitLab.com上设置一个CI运行程序,我想用它来运行需要PostgreSQL数据库连接的测试。CI+PostgreSQL的文档似乎过于简单,似乎说明一旦提供了连接信息,数据库设置就完成了。我可能误解了文档,因为我无法创建数据库。我的
gitlab ci.yml
如下所示

image: node:latest

services:
  - postgres:latest

variables:
  POSTGRES_DB: rx_reactive_test
  POSTGRES_USER: rx_reactive_tester
  POSTGRES_PASSWORD: "1esdf3143"

cache:
  paths:
  - node_modules/

postgresql:
  script:
   - yarn install
   - npm test
通过运行命令npmtest`,它将运行一些测试来建立与数据库的连接。但这些测试失败并显示错误消息

pg-reactive
  ✓ should build connection with the test database.
  1) should run a query returning one row.


1 passing (23ms)
1 failing

1) pg-reactive should run a query returning one row.:
   Uncaught Error: connect ECONNREFUSED 127.0.0.1:5432
    at Object.exports._errnoException (util.js:1033:11)
    at exports._exceptionWithHostPort (util.js:1056:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1099:14)

这些测试在本地测试数据库中运行良好,因此我的CI设置肯定有问题。我将感谢您对我的问题提供的任何帮助:-)

在GitLab CI中,您的作业正在docker容器中运行。因此,Postgres不是在本地主机上运行,而是在“Postgres”上可访问的主机上运行(服务名称是解析为可用于访问DB的IP的服务器名称)


看起来CI设置了一个名为“CI”的环境变量,这样,如果您在GitLab CI环境中运行,您就可以将CI中测试的DB连接从“localhost:5432”切换到“postgres:5432”。

嘿,谢谢您的回答,但它仍然有点模糊,所以应该使用以下连接设置<代码>连接:{host:'postgres',user:'user',password:'test',端口:5432,数据库:'withlove_test'}?除非您在Kubernetes executor上运行,否则在这种情况下,服务在
本地主机上公开,而不是通过主机别名公开。