Configuring PostgreSQL in GitLab CI

I am trying to configure a CI runner on GitLab.com and I would like to use it to run tests that require a PostgreSQL database connection. The CI + PostgreSQL documentation seems too simple and seems to say that after providing the connection information, the database is set up. I probably misunderstand the documentation as I cannot create the database. My gitlab-ci.ymllooks like this

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

By running the npm test` command, it will conduct several tests that will build a connection to the database. But these tests fail with the error message

pg-reactiveshould 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)

These tests work well with my local test database, so there should be a problem with my CI setup. I would appreciate any help on my issue :-)

+4
1

GitLab CI . Postgres , , "postgres" ( - , IP-, ).

, CI ENV "CI", DB CI "localhost: 5432" "postgres: 5432", CI GitLab.

+3

Source: https://habr.com/ru/post/1672971/


All Articles