gpt4 book ai didi

node.js - 在 Github 操作中获取错误 : connect ECONNREFUSED 127. 0.0.1:5432

转载 作者:行者123 更新时间:2023-12-05 08:03:37 25 4
gpt4 key购买 nike

我正在尝试在 github 操作中使用 docker 连接到 Postgres。这是我的 github 操作文件:

    name: Carbon Link backend server CI

on:
push:
branches: [ 'develop', 'PC-3-setup-github-actions-on-pr-request' ]
pull_request:
branches: [ 'develop', 'PC-3-setup-github-actions-on-pr-request' ]
jobs:
# label of the container job
postgres-test:
runs-on: ubuntu-latest
container: node:latest

services:
postgres:
image: postgres:latest
# `POSTGRES_HOST` is `postgres`
env:
POSTGRES_DB: carbonlink
POSTGRES_PASSWORD: password
# optional (defaults to `5432`)
POSTGRES_PORT: 5432
# optional (defaults to `postgres`)
POSTGRES_USER: postgres
ports:
- 5432:5432
# set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
NODE_ENV: test
DATABASE_URL: postgresql://postgres:password@localhost:5432/carbonlink
steps:
# Downloads a copy of the code in your repository before running CI tests
- name: Check out repository code
uses: actions/checkout@v2
- name: Disable husky preparation
run: npm set-script prepare ''
- name: Install dependencies
run: npm install
- name: Migrate
run: npm run db:migrate
- name: Run tests
run: npm test

一切都按照这个命令进行

Run npm run db:migrate

我在其中得到了这个回复:

express-sequel-passport@1.0.0 db:migrate./node_modules/.bin/sequelize db:migrate

Sequelize CLI [ Node :17.9.0,CLI:6.4.1,ORM:6.3.5]

已加载配置文件“config/config.js”。使用环境“测试”。

错误:连接 ECONNREFUSED 127.0.0.1:5432

这是我的 config.js 文件

require('dotenv').config();

module.exports = {
"development": {
"username": process.env.POSTGRES_USER,
"password": process.env.POSTGRES_PASSWORD,
"database": process.env.POSTGRES_DB,
"host": process.env.POSTGRES_HOST,
"dialect": process.env.POSTGRES_DIALECT
},
"test": {
"url": "postgresql://postgres:password@localhost:5432/carbonlink",
"dialect": 'postgres'
},
"production": {
"username": process.env.POSTGRES_USER,
"password": process.env.POSTGRES_PASSWORD,
"database": process.env.POSTGRES_DB,
"host": process.env.POSTGRES_HOST,
"dialect": process.env.POSTGRES_DIALECT
}
}

这里是 docker-compose 文件供引用:

version: '3'
services:
postgres:
container_name: pgDocker
image: postgres:latest
environment:
- POSTGRES_USERNAME
- POSTGRES_PASSWORD
- POSTGRES_DB
- POSTGRES_TEST_DB
ports:
- 5432:5432
volumes:
- ./data/:/var/lib/postgresql/data
- ./create_test_db.sh:/docker-entrypoint-initdb.d/create_test_db.sh
pgadmin:
container_name: pgadminDocker
image: dpage/pgadmin4
environment:
- PGADMIN_DEFAULT_EMAIL
- PGADMIN_DEFAULT_PASSWORD
ports:
- 5555:80
depends_on:
- postgres
volumes:
- ./setup/servers.json:/pgadmin4/servers.json

我在本地连接的方式是执行 docker-compose up,它将使用 postgres 启动容器。

我不明白为什么我仍然没有连接到 postgres。我应该做另一个步骤吗?谢谢!

最佳答案

你也可以试试从 localhost127.0.0.1 的连接字符串吗?我在 github 操作上成功使用了你的 yml 配置。唯一的区别是 localhost127.0.0.1

关于node.js - 在 Github 操作中获取错误 : connect ECONNREFUSED 127. 0.0.1:5432,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71943315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com