Getting started — GCP’s Cloud run

sujayyendhiren rs
2 min readMar 14, 2021

Host a super basic webapp onto GCP’s managed service — ‘cloud run’. Please note that steps outlined in this article is intended for a newbie to get started and see a naive flask application in action.

Introduction

Cloud run is a pretty cool managed service offered by google cloud. This article hand holds a newbie with all the ingredients to try out a super basic flask app locally on your mac and then subsequently host the same container image onto google’s cloud run.

Prerequisites

  • For specifics of why and what of ‘cloud run’, kindly check google cloud docs which are quite simple and easy to understand.
  • Installation of docker on local machine is not covered here.
  • Installation of glcloud package is not covered here as well.

Files to create for your super basic flask app

3 basic files to get started

Dockerfile

Very basic Dockerfile

Flask entrypoint file — testapp.py

Basic flask entry point

requirements.txt

Create a text file named requirements.txt and add the following two python modules into it.

.dockerignore [optional]

Create this file to ignore any local file/directory to be packaged into the container image. As a start may put the following directory into the file.

__pycache__

Build and test container on your personal computer

cd <project-directory>

docker build -t gcr.io/<gcp-project-id>/flaskapp:v1 .

docker run — rm — name=testapp -p 8080:8080 gcr.io/<gcp-project-id>/flaskapp:v1

After running the basic web application check if the website if viewable from browser. http://<hostname-of-your-machine>:8080/

Push on to GCP’s ‘cloud run’ service

docker push gcr.io/<gcp-project-id>/flaskapp:v1

Create service on ‘cloud run’

gcloud run deploy smrithillustration — image gcr.io/<gcp-project-id>/flaskapp:v1 — region <preferred-region> — platform managed — memory 128Mi

Check a list of available regions

--

--