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

Unable to parse JSON key #30

Closed hawkyre closed 2 years ago

hawkyre commented 2 years ago

I am trying to use this but I get an error:

Run RafikFarhad/push-to-gcr-github-action@v4.1
  with:
    gcloud_service_key: ***

    registry: gcr.io
    project_id: gd-demonprogression
    image_name: gddp-discord-bot
    dockerfile: ./Dockerfile
    image_tag: latest
    context: .
    push_only: false
/usr/bin/docker run --name a9be6aa44559ce74cdc8d5fa8805[2](https://github.com/hawkyre/gddp/runs/8299861926?check_suite_focus=true#step:4:2)4e7517_[3](https://github.com/hawkyre/gddp/runs/8299861926?check_suite_focus=true#step:4:3)b6c80 --label 786a9b --workdir /github/workspace --rm -e "INPUT_GCLOUD_SERVICE_KEY" -e "INPUT_REGISTRY" -e "INPUT_PROJECT_ID" -e "INPUT_IMAGE_NAME" -e "INPUT_DOCKERFILE" -e "INPUT_IMAGE_TAG" -e "INPUT_CONTEXT" -e "INPUT_TARGET" -e "INPUT_BUILD_ARGS" -e "INPUT_PUSH_ONLY" -e "HOME" -e "GITHUB_JOB" -e "GITHUB_REF" -e "GITHUB_SHA" -e "GITHUB_REPOSITORY" -e "GITHUB_REPOSITORY_OWNER" -e "GITHUB_RUN_ID" -e "GITHUB_RUN_NUMBER" -e "GITHUB_RETENTION_DAYS" -e "GITHUB_RUN_ATTEMPT" -e "GITHUB_ACTOR" -e "GITHUB_TRIGGERING_ACTOR" -e "GITHUB_WORKFLOW" -e "GITHUB_HEAD_REF" -e "GITHUB_BASE_REF" -e "GITHUB_EVENT_NAME" -e "GITHUB_SERVER_URL" -e "GITHUB_API_URL" -e "GITHUB_GRAPHQL_URL" -e "GITHUB_REF_NAME" -e "GITHUB_REF_PROTECTED" -e "GITHUB_REF_TYPE" -e "GITHUB_WORKSPACE" -e "GITHUB_ACTION" -e "GITHUB_EVENT_PATH" -e "GITHUB_ACTION_REPOSITORY" -e "GITHUB_ACTION_REF" -e "GITHUB_PATH" -e "GITHUB_ENV" -e "GITHUB_STEP_SUMMARY" -e "RUNNER_OS" -e "RUNNER_ARCH" -e "RUNNER_NAME" -e "RUNNER_TOOL_CACHE" -e "RUNNER_TEMP" -e "RUNNER_WORKSPACE" -e "ACTIONS_RUNTIME_URL" -e "ACTIONS_RUNTIME_TOKEN" -e "ACTIONS_CACHE_URL" -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/gddp/gddp":"/github/workspace" 786a9b:e6aa[4](https://github.com/hawkyre/gddp/runs/8299861926?check_suite_focus=true#step:4:4)4[5](https://github.com/hawkyre/gddp/runs/8299861926?check_suite_focus=true#step:4:5)59ce74cdc8d5fa880524e7517
Authenticating docker to gcloud ...
Successfully decoded from base[6](https://github.com/hawkyre/gddp/runs/8299861926?check_suite_focus=true#step:4:6)4
Error response from daemon: Get "https://gcr.io/v2/": unknown: Unable to parse json key.
Docker login failed. Exiting ...

These are my steps:

    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v3

      # Runs a single command using the runners shell
      - name: Push to GCR GitHub Action
        # You may pin to the exact commit or the version.
        # uses: RafikFarhad/push-to-gcr-github-action@241707854fb71f655ec4e2a98bb16505f218bcc2
        uses: RafikFarhad/push-to-gcr-github-action@v4.1
        with:
          gcloud_service_key: ${{ secrets.GCLOUD_SERVICE_KEY }} # can be base64 encoded or plain text
          registry: gcr.io
          project_id: gd-demonprogression
          image_name: gddp-discord-bot
          dockerfile: ./Dockerfile

I have a secret called GCLOUD_SERVICE_KEY where I copy-pasted the service account key straight from the file that was downloaded from GCP.

Anyone has any clue as to what's going on?

RafikFarhad commented 2 years ago

Hi @hawkyre, thanks for using the action.

As you are using plain text for the secret, the action should log This action is unable to decode INPUT_GCLOUD_SERVICE_KEY as base64. It assumes INPUT_GCLOUD_SERVICE_KEY as plain text. according to this line.

But it seems like this action is assuming your secret as BASE64 encoded string which can be occurred when the secret is an empty string. Could you please check the secrets.GCLOUD_SERVICE_KEY if it is empty? To unblock yourself quickly, could you please try adding a new secret by encoding the JSON to BASE64 representation?

hawkyre commented 2 years ago

I ended up going for another solution, sorry

RafikFarhad commented 2 years ago

No worries. I will try to replicate this with an empty secret. Thanks for the update.

RafikFarhad commented 2 years ago

This issue has been resolved in v5-beta.