Deploy Angular on GCP Cloud Run – Cloud Build | Artifact Registry Image Version | Custom Domain
If you have built an Angular application and now want to deploy it to Google Cloud Platform (GCP) using Cloud Run, Cloud Build, Artifact Registry Image Version, and a custom domain, you’re in the right place. In this article, we will walk through the steps to deploy an Angular application on GCP using these services.
Setting Up Cloud Build
First, you need to set up Cloud Build to automate the deployment process. Create a cloudbuild.yaml file in the root of your Angular project with the following configuration:
steps:
- name: 'gcr.io/cloud-builders/npm'
args: ['install']
- name: 'gcr.io/cloud-builders/npm'
args: ['run', 'build']
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/your-project-id/your-image-name:$SHORT_SHA', '.']
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/your-project-id/your-image-name:$SHORT_SHA']
Deploying to Cloud Run
Now that we have our Angular application built and the Docker image pushed to Container Registry, we can deploy it to Cloud Run. Run the following command in the Cloud Shell:
gcloud run deploy --image gcr.io/your-project-id/your-image-name:$SHORT_SHA --platform managed --region your-region --allow-unauthenticated
Using Artifact Registry
Instead of using Container Registry, you can also push the Docker image to Artifact Registry and deploy it from there. This can be done using similar commands as above, but replacing “gcr.io” with “us-central1-docker.pkg.dev” and using appropriate registry settings.
Custom Domain
To use a custom domain with your Cloud Run service, you need to first verify ownership of the domain using Google Search Console. Then, you can map the custom domain to your Cloud Run service using the gcloud command-line tool or the GCP Console.
Conclusion
By following these steps, you can deploy your Angular application on GCP using Cloud Run, Cloud Build, Artifact Registry Image Version, and a custom domain. This will make your application accessible to users on the internet with a secure and scalable infrastructure.