pass Github secrets to a docker github action

3.5k views Asked by At

Hi my devoted and beloved developers!

Today I face trouble trying to transmit GitHub secrets to a docker GitHub action in order to use this variable in the container. I already have defined for the project the secret what_a_secret for the key CHUT.

Here is what I currently have:

name: Continious Delivery
on: [push]
jobs:
  myjob:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Docker Run Action
        uses: addnab/docker-run-action@v3
        env:
          CHUT: ${{ secrets.CHUT }}
        with:
          image: amazon/aws-glue-libs:glue_libs_1.0.0_image_01
          options:
            --env CHUT=$CHUT
            -v ${{ github.workspace }}:/workspace
          run:
            echo CHUT=$CHUT

This just print CHUT=$CHUT instead of CHUT=what_a_secret.

I also tried to do something like this:

            --env CHUT=${{ secrets.CHUT }}

And this:

          run:
            echo CHUT=${{ secrets.CHUT }}

But the lasts solution returns nothing at all.

Your help would be warmly welcomed

EDIT: the documentation "Configure GitHub Actions" do not work to pass environment variables to a container.

1

There are 1 answers

1
Jérémy On BEST ANSWER

The final anwswer is: I made my code cleaner and did this :

name: Continious Delivery
on: [push]
jobs:
  myjob:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Docker Run Action
        uses: addnab/docker-run-action@v3
        with:
          image: amazon/aws-glue-libs:glue_libs_1.0.0_image_01
          options:
            --e CHUT=${{ secrets.CHUT }}
            -v ${{ github.workspace }}:/workspace
          run:
            echo "CHUT=$CHUT"

output is CHUT=*** because Github is smart enough to not print a secret in the terminal. But the docker read the secret correctly.