Env var not detected and Knex.js migration not working from Github Action
I have GitHub action which deploys NodeJS app and does migrate using "migrate": "knex migrate:latest --env production" script. Script works perfectly if I run it manually from terminal but fails with authentication error for database when run from GitHub action. Is this because of environment variables? Does commands executed from GitHub action have access to environment variables or not? Is there a better way to do this?
here's my GitHub action:
name: Deploy
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: SSH and deploy node app
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
port: 22
script: |
cd ~/app/app
git pull origin master
npm install --production
npm run build
npm run migrate
pm2 restart app
Here's the error from GitHub action logs
out: > knex migrate:latest --env production
135
out:
136
out: Requiring external module ts-node/register
137
out: Using environment: production
138
err: error: password authentication failed for user "***"
139
err: at Parser.parseErrorMessage (/home/***/odin/odin/node_modules/pg-protocol/src/parser.ts:357:11)
140
err: at Parser.handlePacket (/home/***/odin/odin/node_modules/pg-protocol/src/parser.ts:186:21)
141
err: at Parser.parse (/home/***/odin/odin/node_modules/pg-protocol/src/parser.ts:101:30)
142
err: at Socket.<anonymous> (/home/***/odin/odin/node_modules/pg-protocol/src/index.ts:7:48)
143
err: at Socket.emit (events.js:315:20)
144
err: at addChunk (_stream_readable.js:295:12)
145
err: at readableAddChunk (_stream_readable.js:271:9)
146
err: at Socket.Readable.push (_stream_readable.js:212:10)
147
err: at TCP.onStreamRead (internal/stream_base_commons.js:186:23)
148
err: npm ERR! code ELIFECYCLE
149
err: npm ERR! errno 1
150
err: npm ERR! [email protected] migrate: `knex migrate:latest --env production`
Regards Pradosh Gaonkar
Solved with workaround of sourcing environment variables from file inside script
source /etc/profile.d/app-env.sh
If anyone could explain I would like to know the issue in more details.
Similar to #21
Yeah, same problem. Any idea why that happens? Environment variables are present on destination machines, so docker or no docker, ssh should be able to pick them up.
@pradosh987 I guess this is your issue.
Why would the user settings not load?