DEV Community

Thierry Njike for Zenika

Posted on • Edited on

2 1

Fix Cloud run resource locations constraint error (Error 412)

Image description

You have a project that you would like to deploy on Google Cloud using Cloud run, but due to some organisation's restrictions, you get an error like below:

ERROR: (gcloud.run.deploy) HTTPError 412: '$region' violates constraint 'constraints/gcpresourceLocations'

This error could come from the fact that you should use a low carbon region, and not all Google Cloud regions satisfy this condition.
Even if you pass the region as an argument, you have some steps of the deployment process that you don't manage because they are automated. So, you have to do it another way.
In this article, I will explain step by step how to solve that problem.

**

1 - Create the repository yourself

**

If we use the default gcloud run command, It will create a repository in the artifact registry, and use it to create the image to deploy.
That image is by default multiregion and it includes prohibited regions. So, you have to build the image yourself manually and specify it as an argument in the command. To do so, you have to create a repository in the Artifact Registry as shown below:

Image description

When creating the repository, make sure to select a low carbon region. Once the repository is created, open it and copy its path.

Image description

**

2 - Let's build the image

**

At this step, you should have created a repository. Now, let's build the image. Paste the command below in your cloud shell at the same level with your Dockerfile:



gcloud builds submit --region=$region --gcs-source-staging-dir=$path_to_the_cloud_storage_bucket --tag $path_to_the_repo/image_name:version



Enter fullscreen mode Exit fullscreen mode

Image description

The image was successfully built! Copy the image URL, you will need it at the next step.

**

3 - Deploy your image

**
Now your image is created, let's deploy it on Cloud Run. Paste the command below in your cloud shell



gcloud run deploy $service_name --image $image_url:tag


Enter fullscreen mode Exit fullscreen mode

Now you should have your app link in your cloud shell!

Hope this article will help 🚀

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

AWS GenAI Live!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️