Newsletter
TechAnV Blog
Get updates on security engineering, Rust, eBPF, and DevSecOps. No spam, unsubscribe anytime.
Check your inbox and click the confirmation link to complete your subscription.
Workaround for google-github-actions/setup-gcloud errors#
I used the google-github-actions/setup-gcloud action in all of my GitHub Actions workflows that deploy applications to Cloud Run.
The pattern I used to use looked like this:
1 - name: Set up Python2 uses: actions/setup-python@v43 with:4 python-version: '3.10'5 - name: Set up Cloud Run6 uses: google-github-actions/setup-gcloud@v07 with:8 version: '275.0.0'9 service_account_email: ${{ secrets.GCP_SA_EMAIL }}10 service_account_key: ${{ secrets.GCP_SA_KEY }}11 - name: Deploy to Cloud Run12 run: |-13 gcloud config set run/region us-central114 gcloud config set project datasette-22232015 datasette publish cloudrun content.db --service my-serviceAt some point around the 30th November 2022 this pattern started to fail with errors that looked like this:
1Error: google-github-actions/setup-gcloud failed with: failed to execute command `gcloud --quiet auth activate-service-account *** --key-file -`: /opt/hostedtoolcache/gcloud/275.0.0/x64/lib/googlecloudsdk/core/console/console_io.py:544: SyntaxWarning: "is" with a literal. Did you mean "=="?2 if answer is None or (answer is '' and default is not None):3ERROR: gcloud failed to load: module 'collections' has no attribute 'MutableMapping'4 gcloud_main = _import_gcloud_main()5 import googlecloudsdk.gcloud_main6 from googlecloudsdk.api_lib.iamcredentials import util as iamcred_util7 from googlecloudsdk.api_lib.util import exceptions8 from googlecloudsdk.core.resource import resource_printer9 from googlecloudsdk.core.resource import config_printer10 from googlecloudsdk.core.resource import resource_printer_base11 from googlecloudsdk.core.resource import resource_projector12 from google.protobuf import json_format as protobuf_encoding13 from google.protobuf import symbol_database14 from google.protobuf import message_factory15 from google.protobuf import reflection16 from google.protobuf.internal import python_message as message_impl17 from google.protobuf.internal import containers18 MutableMapping = collections.MutableMapping19
20This usually indicates corruption in your gcloud installation or problems with your Python interpreter.21
22Please verify that the following is the path to a working Python 2.7 executable:23 /opt/hostedtoolcache/Python/3.10.8/x64/bin/python24
25If it is not, please set the CLOUDSDK_PYTHON environment variable to point to a working Python 2.7 executable.26
27If you are still experiencing problems, please reinstall the Cloud SDK using the instructions here:28 https://cloud.google.com/sdk/After some frustrating trial-and-error, I found that a workaround which is currently effective for some reason (on 1st December 2022) is to downgrade the Python version to 3.9 and increase the version field to 318.0.0.
So now I use:
1 - name: Set up Python2 uses: actions/setup-python@v43 with:4 python-version: '3.9'5 - name: Set up Cloud Run6 uses: google-github-actions/setup-gcloud@v07 with:8 version: '318.0.0'9 service_account_email: ${{ secrets.GCP_SA_EMAIL }}10 service_account_key: ${{ secrets.GCP_SA_KEY }}Maybe upgrade to google-github-actions/setup-gcloud@v1 ?#
In writing this up I noticed that I’m still using v0 of the action, but v1 is now available.
It looks like v1 works with Python 3.11! And doesn’t need that version: '275.0.0' bit either.
This may be a good solution for you.
It doesn’t work for me yet though. I tried upgrading that instead, but got this error when running my datasette publish cloudrun script:
1Updated property [run/region].2Updated property [core/project].3ERROR: (gcloud.builds.submit) You do not currently have an active account selected.4Please run:5
6 $ gcloud auth login7
8to obtain new credentials.So I’m sticking with v0 until I have time to figure that problem out too.