GitHub Actions - Sequelize Migration Error: password authentication failed for user 'runner'

167 views Asked by At

This is my workflow:

name: Run Tests on Pull Request

on:
  pull_request:
    branches:
      - develop
      - staging
      - production

jobs:
  test:
    runs-on: ubuntu-latest

    services:
      postgres:
        image: postgres:15
        env:
          POSTGRES_USER: user
          POSTGRES_PASSWORD: password
          POSTGRES_DB: testdb
        ports:
          - 5432:5432
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    env:
      DB_HOST: localhost
      DB_USER: user
      DB_PASS: password
      DB_NAME: testdb
      DB_PORT: 5432
      DATABASE_URL: postgres://user:password@localhost:5432/testdb

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

      - name: Set up Node.js
        uses: actions/setup-node@v2
        with:
          node-version: 18

      - name: Cache node modules
        uses: actions/cache@v2
        with:
          path: ~/.cache/yarn
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
          restore-keys: |
            ${{ runner.os }}-yarn-

      - name: Install dependencies
        run: yarn install --frozen-lockfile

      - name: Test PostgreSQL Connection
        run: psql postgres://user:password@localhost:5432/testdb -c '\l'
        
      - name: Print Env Variables
        run: |
          echo DB_USER=$DB_USER
          echo DB_PASS=$DB_PASS
          echo DB_HOST=$DB_HOST
          echo DB_PORT=$DB_PORT
          echo DB_NAME=$DB_NAME
        env:
          DB_USER: user
          DB_PASS: password
          DB_HOST: localhost
          DB_PORT: 5432
          DB_NAME: testdb

      - name: Setup Database
        run: yarn db:migrate 
        env:
          DB_USER: user
          DB_PASS: password
          DB_HOST: localhost
          DB_PORT: 5432
          DB_NAME: testdb

      - name: Run tests
        run: yarn test

The job fails with this output

Run psql ***localhost:5432/testdb -c '\l'
                             List of databases
   Name    | Owner | Encoding |  Collate   |   Ctype    | Access privileges 
-----------+-------+----------+------------+------------+-------------------
 postgres  | user  | UTF8     | en_US.utf8 | en_US.utf8 | 
 template0 | user  | UTF8     | en_US.utf8 | en_US.utf8 | =c/user          +
           |       |          |            |            | user=CTc/user
 template1 | user  | UTF8     | en_US.utf8 | en_US.utf8 | =c/user          +
           |       |          |            |            | user=CTc/user
 testdb    | user  | UTF8     | en_US.utf8 | en_US.utf8 | 
(4 rows)

0s
Run echo DB_USER=$DB_USER
DB_USER=user
DB_PASS=password
DB_HOST=localhost
DB_PORT=5432
DB_NAME=testdb
0s
Run yarn db:migrate
yarn run v1.22.19
$ sequelize-cli db:migrate

Sequelize CLI [Node: 18.18.2, CLI: 6.6.1, ORM: 6.33.0]

Database Config: {
  host: 'localhost',
  user: 'user',
  password: 'password',
  name: 'testdb',
  port: 5432,
  dialect: 'postgres',
  max: 30
}
Loaded configuration file "src/server/config/db.cjs".
ERROR: password authentication failed for user "runner"


error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Process completed with exit code 1.

I have no idea where's its getting the user runner from. I've been iterating on this workflow yaml file alot for debugging. My db.cjs is :

const config = {
  host: process.env.GITHUB_ACTIONS ? 'localhost' : process.env.DB_HOST || "localhost",
  user: process.env.GITHUB_ACTIONS ? 'user' : process.env.DB_USER || "root",
  password: process.env.GITHUB_ACTIONS ? 'password' : process.env.DB_PASS || "root",
  name: process.env.GITHUB_ACTIONS ? 'testdb' : process.env.DB_NAME || "devdb",
  port: 5432,
  dialect: "postgres",
  max: 30,
};
console.log('Database Config:', config);
module.exports = config;

my sequelizerc is

const path = require('path');

module.exports = {
  'config': path.resolve('src', 'server', 'config', 'db.cjs'),
  'models-path': path.resolve('src', 'server', 'database', 'models'),
  'seeders-path': path.resolve('src', 'server', 'database', 'seeders'),
  'migrations-path': path.resolve('src', 'server', 'database', 'migrations')
};

my package.json is

{
  "name": "myreponame",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "dev-node": "tsx watch src/server/",
    "build": "tsc && vite build",
    "start": "concurrently \"yarn dev\" \"yarn dev-node\"",
    "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
    "go": "yarn install && yarn start",
    "go:local": "NODE_ENV=local && yarn go",
    "test": "jest",
    "db:migrate": "sequelize-cli db:migrate",
    "preview": "vite preview"
  },
  "dependencies": {
    "@emotion/react": "^11.11.1",
    "@emotion/styled": "^11.11.0",
    "@fontsource/roboto": "^5.0.8",
    "@mui/icons-material": "^5.14.12",
    "@mui/material": "^5.14.12",
    "@reduxjs/toolkit": "^1.9.7",
    "@types/express": "^4.17.18",
    "bcryptjs": "^2.4.3",
    "concurrently": "^8.2.1",
    "cookie-parser": "^1.4.6",
    "cors": "^2.8.5",
    "date-fns": "^2.30.0",
    "dotenv": "^16.3.1",
    "express": "^4.18.2",
    "facebook-nodejs-business-sdk": "^18.0.1",
    "jsonwebtoken": "^9.0.2",
    "pg-promise": "^11.5.4",
    "prettier": "^3.0.3",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-redux": "^8.1.3",
    "reselect": "^4.1.8",
    "sequelize": "^6.33.0",
    "tsx": "^3.13.0",
    "uuid": "^9.0.1",
    "winston": "^3.11.0"
  },
  "devDependencies": {
    "@testing-library/react": "^14.0.0",
    "@types/bcryptjs": "^2.4.4",
    "@types/cookie-parser": "^1.4.4",
    "@types/cors": "^2.8.14",
    "@types/jsonwebtoken": "^9.0.3",
    "@types/react": "^18.2.15",
    "@types/react-dom": "^18.2.7",
    "@types/uuid": "^9.0.5",
    "@typescript-eslint/eslint-plugin": "^6.0.0",
    "@typescript-eslint/parser": "^6.7.4",
    "@vitejs/plugin-react": "^4.0.3",
    "eslint": "^8.51.0",
    "eslint-plugin-react-hooks": "^4.6.0",
    "eslint-plugin-react-refresh": "^0.4.3",
    "jest": "^29.7.0",
    "jest-environment-jsdom": "^29.7.0",
    "sequelize-cli": "^6.6.1",
    "ts-jest": "^29.1.1",
    "ts-node": "^10.9.1",
    "typescript": "^5.0.2",
    "vite": "^4.4.5"
  }
}

I'm completely and utterly stumped. Is the problem the postgres version I'm using?

I'm completely and utterly stumped. I've been looking to see if somehow I've been setting the user to runner accidentally, but I can't find anything. This just doesn't make sense. The printouts I've included show the environment variables are being set.

0

There are 0 answers