Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to read env variables of docker-compose file and package.json file from github action?

from my docker-compose file I have to read an env variable. locally, I can read that variable like this: ENV_FILE=.env docker-compose -f docker-compose.dev.prisma.yml up --build but as .env file is in .gitignore, GitHub action can't get that file. how can I read them?

almost same issue in my package.json file. I have need some env variables to be read from npm scripts:

"start:backend": "wait-port $API_HOST:API_PORT && yarn start"

what I have tried is added those variables in secrets of github, but it didn't get those variables. though expect those 2 files, envs are read perfectly from github action.

like image 400
Ashik Avatar asked Sep 05 '25 04:09

Ashik


1 Answers

Try creating your env file manually as a step in your workflow and pass in your repository secrets. Your docker-compose and package.json should be able to read your environment variables:

    - name: create env file
      run: |
        touch .env
        echo VARIABLE=${{ secrets.VARIABLE }} >> .env
like image 147
kachow6 Avatar answered Sep 07 '25 17:09

kachow6