ERROR: connect ECONNREFUSED 127.0.0.1:5432 on Gitlab CI

Viewed 1458

I am currently working on a project, and i have a big problem about CI with Gitlab. There is two container build with docker-compose, one is an API and the other one is PostgreSQL database.

Here is my gitlab-ci.yml :

image: node:lastest

variables:
  POSTGRES_DB: test
  POSTGRES_USER: user
  POSTGRES_PASSWORD: pass
  POSTGRES_HOST: postgres
  POSTGRES_PORT: 5432
  POSTGRES_HOST_AUTH_METHOD: trust
  NODE_ENV: test

services:
  - postgres:12.2-alpine


stages:
   - test

eslint:
  stage: test
  image: node:12.18.2-alpine3.9
  before_script:
    - npm install
  script:
    - npm run linter
  except:
    - develop

audit:
  stage: test
  image: node:12.18.2-alpine3.9
  before_script:
    - npm install
    - npm install -g sequelize-cli
    - npx sequelize-cli db:create
  script:
    - npm test
  allow_failure: false
  except:
    - develop

So, i got this error :

$ npx sequelize-cli db:create
Sequelize CLI [Node: 12.18.2, CLI: 6.2.0, ORM: 6.3.5]
Loaded configuration file "config/database.js".
Using environment "development".
ERROR: connect ECONNREFUSED 127.0.0.1:5432
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 1

What am I missing?

Thanks !

2 Answers

The main problem should be in your config/database.js file.

Check if the host in this file is postgres instead of 127.0.0.1

It seems like your npm command does not use the POSTGRES_HOST in variables section. Instead it uses 127.0.0.1 when connecting to postgres and fails because your service is not running locally. Fix that and it should be available at postgres.

Related