簡體   English   中英

帶有Postgres的GitLab CI錯誤:連接ECONNREFUSED 127.0.0.1:5432

[英]GitLab CI with Postgres ERROR: connect ECONNREFUSED 127.0.0.1:5432

我有一個用於測試,構建和部署代碼的Gitlab CI pipeline 該代碼基本上是一個nodejs api,數據庫是使用Sequelize ORM管理的。 最近,我使用Postgres Database嘗試了管道。

這是gitlab-ci.yml文件:

image: trion/ng-cli-karma

variables:
  POSTGRES_DB: test
  POSTGRES_USER: postgres
  POSTGRES_PASSWORD: password
  NODE_ENV: test

cache:
  paths:
  - wiki-quotes-client/node_modules/
  - wiki-quotes-server/node_modules/

stages:
    - test
    - build
    - deploy

test_server:
  services:
   - postgres:latest
  script:
   - cd wiki-quotes-server
   - npm install
   - npm install -g sequelize-cli
   - sequelize db:migrate
   - sequelize db:seed:all
   - npm run test

test_client:
    script:
        -  cd wiki-quotes-client
        -  npm install
        -  ng test --watch=false

build_angular:
  only:
    - master
  stage: build
  script:
    - npm install
    - cd wiki-quotes-client
    - ng build --prod
  artifacts:
    paths:
      - wiki-quotes-client/dist/wiki-quotes-client/.

deploy:
  only:
    - master
  stage: deploy
  dependencies:
    - build_angular
  script:
    - ls -all
    - apt-get update -qq
    - apt-get install -qq git
    - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
    - eval $(ssh-agent -s)
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - echo "$SSH_KEY" | tr -d '\r' | ssh-add - > /dev/null
    - ls ~/.ssh/
    - '[[ -f /.dockerenv ]] && echo -e "Host *\n\t StrictHostKeyChecking no \n\n" > ~/.ssh/config'
    - ssh-keyscan 159.65.156.240 >> ~/.ssh/known_hosts
    - chmod 644 ~/.ssh/known_hosts
    - ssh goutambseervi@159.65.156.240 'cd ~/wikiquotesapp; git checkout master; git pull;  cd wiki-quotes-server; npm install; npm start:prod'

現在它向我顯示此錯誤:

錯誤:連接ECONNREFUSED 127.0.0.1:5432

另外,我還有一個問題是...

使用Sequelize在數據庫中部署api時,遵循的理想路徑是什么?

我想確保我的遷移能夠進行,同時我的數據庫應該在每次部署時都播種,並且我不希望數據庫具有冗余數據。

在Gitlab CI中使用服務的工作方式基本上與運行不同的Docker容器(在docker-compose中命名為服務)的方式相同,這些容器可用於運行特定作業的容器。

因此,根據您的錯誤消息,我假設您的代碼嘗試訪問localhost上的postgres數據庫,當您在開發人員計算機上同時運行這兩個數據庫時,它們就可以正常工作。 在Gitlab CI中,這是兩個“都有自己的localhost ”的容器,必須使用諸如postgres類的dns名稱連接到另一個容器。 因此,當您使用名為postgres的映像時,Gitlab也會這樣命名服務。

請在節點進程中嘗試使用主機名postgres代替localhost進行數據庫連接,並且訪問應該有效。 根據您定義的其他變量,僅添加一個POSTGRES_HOST: postgres variable問題POSTGRES_HOST: postgres (或類似的方法-我對sequelize配置不熟悉)

對於Gitlab CI上服務的詳細信息請查看的文檔 ,即使對於訪問的具體使用情況提供了一個樣本postgres服務和一些澄清這個具體問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM