dockergithubworkflowgithub-actionscicd

How to pass a Github Secret as Environment Variable to Docker?


I'm getting started with CI/CD and Docker and i wanted to pass a connection string to docker in my workflow file.

deploy:
    runs-on: ubuntu-latest
    needs: publish
    steps:
    - name: deploy to server
      uses: appleboy/ssh-action@master
      env: 
        CONN_STRING: ${{ secrets.CONN_STRING }}
      with:
        host: ${{ secrets.SECRET_IP }}
        username: ${{ secrets.SERVER_USERNAME }}
        key: ${{ secrets.SERVER_KEY }}
        port: 22
        script: docker stop *** && docker rm **** && docker pull **** && docker run --env CONN_STRING=$CONN_STRING -d --name ******

As you can see i made an env called "CONN_STRING" which gets the connection string out of my github secrets. After that i want to pass it into the dockerscript by "CONN_STRING=$CONN_STRING". However my docker keeps crashing since I've added this. Anyone knows what I'm doing wrong? The **** are merely names of my project, which i'd like to keep private.


Solution

  • Turns out you can just skip the environment variable in yml and use

    CONN_STRING=${{ secrets.CONN_STRING }}