Home > Software engineering >  Github Actions: Build docker image with a secret json file and env file
Github Actions: Build docker image with a secret json file and env file

Time:04-29

I made a discord bot in python and inside that project there is a key.json file that I need because of firebase. I also have a .env file with different types of tokens mentioned trough out the code.

I tried to build a docker image using github actions but I couldn't figure out how I 'transfer' this key.json and .env file with my docker image without directly uploading these to the repo.

The important part is that the code needs a key.json file and .env file with the correct values because I use those values trough out the code!

CodePudding user response:

You can use Secrets for that. But if you really need them in a file just echo them from secret context into a file.

steps:
  - name: Echo secrets
    run: |
      echo -e '${{ secrets.key }}' >> key.json
      echo 'TOKEN1=${{ secrets.token1 }}' >> .env
      echo 'TOKEN2=${{ secrets.token2 }}' >> .env

A secret can be multi-line value, so you should be able to store structured value such as json.

  • Related