Run your web app in Google Cloud Run

pravanjan palai
3 min readApr 29, 2019

--

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

  1. Create images of your web application
  2. Upload your image to Google cloud registry
  3. 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.

createDockerfile -create docker file and build image would build an image for you

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

we have our docker image ready

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

Your container is running.

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)

replace with your projectId

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

New service click on create service

Go inside service you would see Deploy new revision, click on it.

I have deployed much time so you see that many revision

Select your image from Google Container Registry

Select Image and click continue.

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

--

--