简体   繁体   English

PG::ConnectionBad on Github Actions for Rails

[英]PG::ConnectionBad on Github Actions for Rails

I'm in a problem right now and don't know how to solve this in Github Actions context.我现在遇到了问题,不知道如何在 Github Actions 上下文中解决这个问题。

Side context: I'm following a tutorial on setting up Rails-Postgres with GH actions for CI.侧面背景:我正在学习关于使用 GH 操作为 CI 设置 Rails-Postgres 的教程

Normally when I run into this problem in dev environment, I'd delete a postmaster.pid file.通常当我在开发环境中遇到这个问题时,我会删除一个postmaster.pid文件。 But here, because I'm in a test environment in GH actions, I'm not sure how to solve it.但在这里,因为我在 GH 动作的测试环境中,我不确定如何解决它。 I tried already doing how I would do it in dev env, it unfortunately did not work.我已经尝试过如何在 dev env 中执行此操作,但不幸的是它不起作用。

The solutions I've tried:我尝试过的解决方案:

  • rm /usr/local/var/postgres/postmaster.pid

  • Changing the ports within postgres entry in the workflow更改工作流中 postgres 条目中的ports

My GH Actions Workflow:我的 GH 行动工作流程:

name: Test

on: [pull_request]

jobs:
  build:
    runs-on: ubuntu-latest

    services:
      postgres:
        image: postgres:12.1
        ports:
          - 6543:6543
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Install Ruby version specified in `.ruby-version`
        uses: eregon/use-ruby-action@master

      - name: Install required apt packages
        run: |
          sudo apt-get -y install libpq-dev

      - name: Setup cache key and directory for gems cache
        uses: actions/cache@v1
        with:
          path: vendor/bundle
          key: ${{ runner.os }}-gem-use-ruby-${{ hashFiles('**/Gemfile.lock') }}

      - name: Read Node.js version to install from `.nvmrc`
        run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
        id: nvm

      - name: Install required Node.js version
        uses: actions/setup-node@v1
        with:
          node-version: "${{ steps.nvm.outputs.NVMRC }}"

      - name: Get Yarn cache directory path
        id: yarn-cache
        run: echo "::set-output name=dir::$(yarn cache dir)"

      - name: Setup cache key and directory for node_modules cache
        uses: actions/cache@v1
        with:
          path: ${{ steps.yarn-cache.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}

      - name: Bundle install
        run: |
          gem install bundler -v2.1.4
          bundle config path vendor/bundle
          bundle install --jobs 4 --retry 3

      - name: Yarn install
        run: yarn --frozen-lockfile

      - name: Run RSpec // ERRORS HERE
        run: |
          RUBYOPT='-W:no-deprecated -W:no-experimental' bundle exec rails db:prepare
          RUBYOPT='-W:no-deprecated -W:no-experimental' bundle exec rspec

It breaks on the Run RSpec task.它中断了Run RSpec任务。

Error message:错误信息:

PG::ConnectionBad: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

Thanks for your help everyone😁谢谢大家的帮助😁

Found a fix!找到了解决办法!

I needed to add the host , username , and password entry in config/database.yml for the test DB我需要在config/database.yml为测试数据库添加hostusernamepassword条目

Because you specified the port for 6543, so PostgreSQL cannot find its default port 5432.因为你指定的端口是 6543,所以 PostgreSQL 找不到它的默认端口 5432。

To fix this, specify the port under要解决此问题,请在下面指定端口

services:
  postgres:
    ports:
      - 5432/tcp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails Postgres Github 操作错误:PG::ConnectionBad:fe_sendauth:未提供密码 - Rails Postgres Github Actions error: PG::ConnectionBad: fe_sendauth: no password supplied PG :: ConnectionBad与rails和pgbouncer - PG::ConnectionBad with rails and pgbouncer Ruby on Rails PG :: ConnectionBad - Ruby on Rails PG::ConnectionBad Github 操作工作流 PG::ConnectionBad: 无法连接到服务器:运行 bundle exec rake 时没有这样的文件或目录 - Github actions workflow PG::ConnectionBad: could not connect to server: No such file or directory when running bundle exec rake Postgresql PG :: ConnectionBad +使用Github项目 - Postgresql PG::ConnectionBad + working with Github project 为什么docker化的Rails应用会引发“ PG :: ConnectionBad”? - Why is dockerized Rails app raising “PG::ConnectionBad”? 使用Postgresql盯着Rails应用-PG :: ConnectionBad - Staring Rails App With Postgresql - PG::ConnectionBad 开发MacOS上的PG :: ConnectionBad Rails和PostgreSQL - PG::ConnectionBad Rails and PostgreSQL on development MacOS Rails / PostgreSQL问题:PG :: ConnectionBad:fe_sendauth:未提供密码 - Rails/PostgreSQL problem: PG::ConnectionBad: fe_sendauth: no password supplied Rails-Postgres-无法连接到服务器:连接被拒绝(PG :: ConnectionBad) - Rails - Postgres - could not connect to server: Connection refused (PG::ConnectionBad)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM