Member-only story
How to Deploy a Web Application to Cloud Run Automatically
Apply CI/CD to your web applications

Using some web Python web frameworks like Flask, Django, or FastAPI, you can develop your APIs or web applications easily in Python. As a Python developer, these frameworks are native and easy to get started because you don’t need to learn a whole new front-end language like JavaScript plus its frameworks such as React, Angular, Vue, etc.
This article is not about how to develop APIs or web applications with a Python framework. However, it’s focused on how to deploy a web application to Cloud Run continuously. The Flask framework is chosen because it’s simple to use and has a large community. The procedures introduced in this post are applicable to all Python frameworks.
Install Flask locally
Before deploying our code to the Cloud in a production environment, we need to develop it locally and get everything ready.
The first step is to install the framework on your computer. It’s recommended to install Flask in a virtual environment so it won’t interfere with system libraries. Besides, you can install different versions of Flask in different virtual environments.
We can use the Python native venv
library to manage your virtual environments. Alternatively, you can use conda because you can install different versions of Python with conda conveniently. Besides, you can activate your virtual environments from anywhere and don’t need to worry about the metadata for the virtual environment.
(base)$ conda create --name flask python=3.10
(base)$ conda activate flask
(flask)$ pip install Flask==2.1.1
Besides Flask, several dependencies required by Flask are installed automatically. Now we can start to create a Flask application locally.
Prepare the Flask application locally
We will create a super simple “Hello World!” Flask application because the focus is the configurations for continuous deployment (CD) as will be introduced soon.
Create a folder called my_app
, and navigate into it. Then create a file named app.py
. You can give it any name you like, but it’s common to name it app.py
…