Better Programming

Advice for programmers.

Follow publication

Member-only story

How to Deploy a Web Application to Cloud Run Automatically

Lynn G. Kwong
Better Programming
Published in
8 min readApr 27, 2022

Image by kreatikar on Pixabay

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

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Lynn G. Kwong
Lynn G. Kwong

Written by Lynn G. Kwong

I’m a Software Developer (https://youtube.com/@kwonglynn) keen on sharing thoughts, tutorials, and solutions for the best practice of software development.

No responses yet

Write a response