Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Howto connect #4

Open
ovaris opened this issue Dec 18, 2019 · 6 comments
Open

Howto connect #4

ovaris opened this issue Dec 18, 2019 · 6 comments

Comments

@ovaris
Copy link

ovaris commented Dec 18, 2019

Hi, I was just wondering what hostname should I use to connect postgresql db in github envirnoment?

@elpapi42
Copy link

+1

@shirshak55
Copy link

it uses default port 5432 on localhost. You can change database by using keys below with:

          postgresql db: "bs_test"

@aruprakshit
Copy link

I have below job syntax:

name: Ruby

on: [push]

jobs:
  unit_tests:
    name: 'Run unit tests'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up Ruby 2.6
        uses: actions/setup-ruby@v1
        with:
          ruby-version: 2.6.x
      - uses: harmon758/postgresql-action@v1
        with:
          postgresql version: '11'
          postgresql db: 'surveymaster_test'
      - name: Build and test with Rake
        if: success()
        working-directory: backend/ruby
        run: |
          gem install bundler
          bundle install --jobs 4 --retry 3
          bundle exec rspec ./spec

But it seems the postgresql connection is not found and my test fails.

An error occurred while loading ./spec/controllers/admin/sessions_controller_spec.rb.
Failure/Error: ActiveRecord::Migration.maintain_test_schema!

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"?
# ./spec/rails_helper.rb:29:in `<top (required)>'
# ./spec/controllers/admin/sessions_controller_spec.rb:3:in `require'
# ./spec/controllers/admin/sessions_controller_spec.rb:3:in `<top (required)>'

@jay-snee
Copy link

@aruprakshit What does your connection string look like? I found I had to explicitly set a username/password in the job config when using a URL string:

database.yml

test:
  <<: *default
  url: postgres://test:password@localhost/test

my_action.yml

name: Run rspec tests

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Set up Ruby 2.6
      uses: actions/setup-ruby@v1
      with:
        ruby-version: 2.6.x
    - name: Set up PostgreSQL
      uses: Harmon758/postgresql-action@v1.0.0
      with:
        postgresql user: test
        postgresql password: password
    - name: Set up Redis
      uses: zhulik/redis-action@1.1.0
    - name: Build app
      run: |
        gem install bundler
        bundle install --jobs 4 --retry 3
        bundle exec rails db:setup RAILS_ENV=test
    - name: Run specs
      run: |
        bundle exec rspec

@JeffersonCarvalh0
Copy link

I'm using both user and password, and got this error:

error: password authentication failed for user "runner"
    at Connection.parseE (/home/runner/work/todo-app/todo-app/node_modules/pg/lib/connection.js:581:48)
    at Connection.parseMessage (/home/runner/work/todo-app/todo-app/node_modules/pg/lib/connection.js:380:19)
    at Socket.<anonymous> (/home/runner/work/todo-app/todo-app/node_modules/pg/lib/connection.js:116:22)
    at Socket.emit (events.js:196:13)
    at Socket.EventEmitter.emit (domain.js:471:20)
    at addChunk (_stream_readable.js:290:12)
    at readableAddChunk (_stream_readable.js:271:11)
    at Socket.Readable.push (_stream_readable.js:226:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:166:17) {
  name: 'error',
  length: 102,
  severity: 'FATAL',
  code: '28P01',
  detail: undefined,
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: undefined,
  table: undefined,
  column: undefined,
  dataType: undefined,
  constraint: undefined,
  file: 'auth.c',
  line: '336',
  routine: 'auth_failed'
}

Where is this runner user coming from? This is my workflow:

name: Development(Server)

on: 
  push:
    paths:
      - 'packages/server/**'
      - '.github/workflows/server-development.yml'
    branches-ignore:
      - master
      
jobs:
  build:
    name: Test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-node@v1
        with:
          node-version: '12.0.0'
      - uses: harmon758/postgresql-action@v1
        with:
          postgresql version: '12.2'
          postgresql db: todo-test
          postgresql user: typeorm
          postgresql password: password
      - run: yarn install
      - run: yarn lint:server
      - run: yarn test:server

It fails in the yarn test:server when it tries to connect to the database

@JeffersonCarvalh0
Copy link

Nevermind, I've just solved it. The problem was being caused by by the the NODE_ENV variable not being properly set, so the database's url wasn't been properly built in my config file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants