App can not find the env variables
zakst opened this issue ยท 5 comments
I am trying to create an .env
file as part of Github Action workflow as shown below.
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Install Node.js
uses: actions/setup-node@v1
with:
node-version: "10.x"
- name: Install npm dependencies
run: npm install
- name: Create the .env file
uses: SpicyPizza/create-envfile@v1
with:
envkey_QUERY_LIMIT: 20
envkey_GOOGLE_RECAPTCHA_SECRET_KEY: ${{ secrets.GOOGLE_RECAPTCHA_SECRET_KEY }}
file_name: .env
- name: Run build task
run: npm run build
The build job is successful but my app can not read the .env
after deployment, on the server that is.
Any ideas why?
What do you do with the artifacts of this Action? Do they get deployed somewhere? If you're just running npm run build
, then I'm not sure where the files go after that. It would seem that it should put the .env
file in the same directory as the rest of the files you checked out. I'd also recommend doing some debugging with another step that just runs ls
on the directory to see what's in there.
I added a debug step with ls -lisa
and another with cat .env
and verified that it is creating the .env
correctly i am starting to think its not a SpicyPizza
issue (side note: how do you make it spicy btw, chilli or hot salami?). Below is my workflow yml
for reference. might help someone sometime
name: "nest monorepo app"
on:
push:
branches: [ master ]
paths: apps/my-app/**
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Node.js
uses: actions/setup-node@v1
with:
node-version: '13.x'
- name: Installing dependencies
run: npm install
- name: Inferring .env from secrets
uses: SpicyPizza/create-envfile@v1
with:
envkey_QUERY_LIMIT: 20
envkey_GOOGLE_RECAPTCHA_SECRET_KEY: ${{ secrets.GOOGLE_RECAPTCHA_SECRET_KEY }}
file_name: .env
- name: Building my-app
run: npm run build my-app
- name: View the contents
run: cat .env
- name: sending artefact /dist/apps/my-app to server
uses: easingthemes/ssh-deploy@v2.1.5
env:
SOURCE: "dist/apps/my-app"
TARGET: "/var/www/html/dist/apps"
SSH_PRIVATE_KEY: ${{ secrets.STAGING_SUB_SERVER_SSH_KEY }}
REMOTE_HOST: ${{ secrets.STAGING_SUB_REMOTE_HOST }}
REMOTE_USER: ${{ secrets.STAGING_SUB_REMOTE_USER }}
- name: Restart the my-app
uses: garygrossgarten/github-action-ssh@v0.6.3
with:
command: pm2 stop my-app --silent && cd /var/www/html/dist/apps && pm2 start my-app/main.js --watch --name my-app
host: ${{ secrets.STAGING_SUB_REMOTE_HOST }}
username: ${{ secrets.STAGING_SUB_REMOTE_USER }}
privateKey: ${{ secrets.STAGING_SUB_SERVER_SSH_KEY }}
I had the same problem and noticed the .env file is created with root as the owner, I was able to fix it by adding a step to change the owner to current user.
- run: sudo chown -R $(id -u):$(id -g) .env
I had the same issue while deploying to Heroku using akhileshns/heroku-deploy
.
I figured out that if you put your .env
in .gitignore
, the file will be properly created during the workflow execution, but it will never make it to your Heroku app.
You might want to use a different name for your production .env
.
(side note: how do you make it spicy btw, chilli or hot salami?)
We have yet to conduct research into what we mean ๐
I had the same problem and noticed the .env file is created with root as the owner, I was able to fix it by adding a step to change the owner to current user.
Since it's being run in the Docker container, I'm unsure on how best to let the user be defined. Feel free to create a separate issue if this is important!
I think the items in this issue have been resolved, so I'll close it. Feel free to re-open it if they are still a problem.