Build and deploy a simple Flask application on Google Cloud Run - Part 1 - Deploy a Python service

preview_player
Показать описание
In this tutorial, we'll show you how to deploy a simple Flask application on Google Cloud Run. Google Cloud Run is a serverless platform that allows you to run containerized applications quickly and easily.

We'll start by creating a simple Flask application and testing it locally. We are going to deploy the application using Cloud Shell.

By the end of this tutorial, you'll have a solid understanding of how to deploy a Flask application on Google Cloud Run and take advantage of its scalability, flexibility, and affordability.

So if you're ready to deploy your Flask application on Google Cloud Run, be sure to check out our tutorial. Don't forget to subscribe to our channel for more tutorials on Flask, Google Cloud, and other tools and technologies.

Keywords: Flask, Google Cloud Run, Docker, Containerization, Google Container Registry, Google Cloud SDK, gcloud, Deployment, Serverless, Scalability, Flexibility, Affordability

Hashtags: #Flask #GoogleCloudRun #Docker #Containerization #GoogleContainerRegistry #GoogleCloudSDK #gcloud #Deployment #Serverless #Scalability #Flexibility #Affordability

✅ Subscribe for more videos like this one
🔔 Click on the bell icon to be notified when I release a new video
👍 Please like my video!

✅ Let's connect:

📝 Useful notes:

👨‍💻 Source code:
```
import os

from flask import Flask

app = Flask(__name__)

def hello_world():
return "Hello {}!".format(name)

if __name__ == "__main__":
```

Copy the following code in Dockerfile
```

# Use the official lightweight Python image.
FROM python:3.9-slim

# Allow statements and log messages to immediately appear in the Knative logs
ENV PYTHONUNBUFFERED True

# Copy local code to the container image.
ENV APP_HOME /app
WORKDIR $APP_HOME
COPY . ./

# Install production dependencies.
RUN pip install Flask gunicorn

# Run the web service on container startup. Here we use the gunicorn
# webserver, with one worker process and 8 threads.
# For environments with multiple CPU cores, increase the number of workers
# to be equal to the cores available.
# Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling.
CMD exec gunicorn --bind :$PORT --workers 1 --threads 8 --timeout 0 main:app
```

Add the following code in .dockerignore
```
Dockerfile
README.md
*.pyc
*.pyo
*.pyd
__pycache__
.pytest_cache
```

🎥 Content of this video:
00:00 - What you will learn
02:55 - Create a new Project
04:33 - Create a new Flask web application
10:30 - Run the Flask app on the local emulator
14:00 - Deploy to Cloud Run
Рекомендации по теме
Комментарии
Автор

Best tutorial on deploying a web app with GCP!

Jojo-lfcw
Автор

Complimenti Fede! This video has taught me a lot. I'm now one step closer to being a data engineer thanks to you.

Alebobb
Автор

Thank you for your sharing, is the best video

jamirhuaman
Автор

This is just lit and helped me a lot to meet a deadline, you are doing great work 🤩🤩

mohdsarique
Автор

Excelent!! Nice shot!! One issue!! The code in the description have a typo.. "if _name_ " is surrounded by simple underlines!! Thankssss

inteligenciamilgrau
Автор

thank you for your sharing, it means a lot for me,

wildananugrah
Автор

If you are getting a deployment failed error. Try to remove "exec" command from your last line in docker file.

SuvimalYashraj
Автор

Amazing tutorial, Frederico!!! Tks for sharing!!

adrianorcampos
Автор

So interesting - Thank you so much & keep going ^^

adnanedriouche
Автор

This is just fire info. Thank you man.

ВадимАкимов-йх
Автор

Thank you Fede! Do youhave some examples with a flask application using a sql db? That's my issue:(

פבלודובצינסקי
Автор

i am too lazy to open my journey book to remeber what i have learned because tomorrow is my exam day so i just wacth your video and i hope it's can help me to face that exam tomorrow.

nazwaunimal
Автор

Hey Federico, I getting error message after I try to run on cloud run emulator "status check failed" Deploy failed Update failed with error code DEPLOY_UNKNOWN 1/1 deployment(s) failed Skaffold exited with code 1. any suggestions?

YuvalElimelech-tu
Автор

Thank you for great video, but didn't understand docker

sachinbhagat
Автор

Complimenti Federico, ottimo tutorial. Non riesco però a capire i costi di questo servizio Google, potresti spiegarmi brevemente? Grazie! Iscritto e video piaciuto ✌🏻

tommasoseneca
Автор

I just get this when I get to the Cloud run emulator step? Any advice?

(The minikube profile 'cloud-run-dev-internal' has been scheduled to stop automatically after exiting Cloud Code. To disable this on future deployments, set autoStop to false in your launch configuration
flag needs an argument: --status-check
See 'skaffold dev --help' for usage.
Exited with code 127.
Cleaning up...
Finished clean up.)

joncrosby
Автор

Hi Federico! Thank you very much for your tutorial. You have a great way of explaining. However, my editor does not load, at the video on 10:17. I looked around the console on Chrome and Firefox and binged Stack Overflow. My WebSocket connection fails. I think it does with a lot of people. Probably an issue with CORS policy.

It says, "blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource." Now, I am a bit afraid of giving full access with "Access-Control-Allow-Origin", "*". That would probably be a security risk. Any advice? Thank you, once again for this great tutorial!

manomancan
Автор

when doing the run emulator it just says loading web app forever?

mattytripps
Автор

Don't worry too mucha about this-a.

noeldacosta
Автор

thanks you for your video. Can I ask - does the python flask app automatically get closed by Google Run ? If 100 url request are made at once does Google Run spin up 100 instances of the app then close them all ?

warperone
welcome to shbcf.ru