Run your web app in Google Cloud Run
This post we will look into how to deploy a web app application to Google cloud Run.
Google has 10-year-old server less offering (Google App Engine ), This help builds and deploys on Google infrastructure. However, as a developer, we would fell locked in on programming language and binary.
Recently Google releases Cloud Run (Bringing serverless to a container), Cloud run gives developer freedom to deploy any programming language and binary and simple deploy and run do not worry about infrastructure.
Let’s follow simple 3 steps to deploy into cloud run
- Create images of your web application
- Upload your image to Google cloud registry
- Deploy the image to Google Cloud Run.
We have a simple hello world web app build using Java programming language and Tomcat web server. I have added the complete code to GitHub feel free to use the same.
https://github.com/pravanjan/cloudrun_webapp_example.git
Creating images of your application
Make sure you have docker install and running. You don't need any prior docker knowledge, Yes that's all you don't have to worry about anything else.
Here we have used Gradle as build management tools and adder docker plugin to build our image.
We have two Gradle task one to create Docker file and another to build Docker image.
In fact, buildImage task is depended on createDocker file so once you type
$gradle buildImage task it does take care of everything for you.
run command $docker images to view the image which we have build
At this point, you can run the image in your local machine.
$ docker run -p 8080:8080 gcr.io/validprojectid/cloudrun:latest
Visit your’s locally deployed container by opening the URL in a web browser.
http://localhost:8080/cloudrun_webapp_example/testcloudrun
Upload your image to Google cloud registry
This step you have to make sure to replace the Google project id (you can create a free tier account to test, it has $300 credit and one year free)
Note — Enable Google Container Registry. ( It stores your docker image)
If you look into the image name gcr.io/{projectId}/cloudrun:latest
We have named the image such which can be deployed to (Google container Registry gcr.io).
Run $docker push gcr.io/{projectId}/cloudrun:latest
This command will push your docker image to Google container registry under your configured projectId.
Deploy the image to Google Cloud Run. g
Two way we can deploy to cloud run using gcloud command and Google console user interface.
Let’s do it through google console UI
Enable Google cloud Run and Create your service
Go inside service you would see Deploy new revision, click on it.
Select your image from Google Container Registry
Final step click deploy :
That's all one random URL with your service name will appear.
My container is deployed here.
https://tomcatjava-vz2ybgf7yq-uc.a.run.app/cloudrun_webapp_example/testcloudrun
Source code URL: https://github.com/pravanjan/cloudrun_webapp_example.git