[英]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
为测试数据库添加host
、 username
和password
条目
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.