RafikFarhad / push-to-gcr-github-action

An action that build docker image and push to Google Cloud Registry and Google Artifact Registry.
MIT License
68 stars 37 forks source link

base64 encoding a key that is stored as json does not work #25

Closed pkaramol closed 2 years ago

pkaramol commented 2 years ago

My SA key is stored as json

However the following example fails

    - name: base64 encode the staging gcr sa
      id: base64-staging-gcr
      shell: bash
      run:
        echo "::set-output name=STAGING_GCR_SA_BASE64::$(echo '${{ secrets.STAGING_GCR_SA }}' | python -m base64 -e)"

    - name: build and push to staging gcr
      id: stg_img_build
      uses: RafikFarhad/push-to-gcr-github-action@v4
      with:
        gcloud_service_key: ${{ steps.base64-staging-gcr.outputs.STAGING_GCR_SA_BASE64 }}
        registry: gcr.io
        project_id: $STAGING_GCR_PROJECT
        image_name: ${{ github.event.inputs.image_name }}
        image_tag:  ${{ github.event.inputs.image_tag }}

as follows:

Error response from daemon: Get "https://gcr.io/v2/": unknown: Unable to parse json key.
RafikFarhad commented 2 years ago

Hi @pkaramol, thanks for using this action and reporting the issue. I think your encoding to base64 is fine but the extra ' is causing the issue. image Could you please check with changing echo '${{ secrets.STAGING_GCR_SA }}' | python -m base64 -e to echo ${{ secrets.STAGING_GCR_SA }} | python -m base64 -e?

Also if you use v4.1, you don't have to encode the JSON file anymore, the gcloud_service_key parameter now supports both base64 and plain text.

Feel free to re-open the issue if it is not solved yet.