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

Опубликовано: 31 Октябрь 2024
на канале: Federico Tartarini
12,275
251

This video shows you all the steps on how to package a full Flask application into a container image and then deploy the container image to Cloud Run. We are going to deploy the application using Cloud Shell.

✅ 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!

⚠️ Join my channel to get access to perks:    / @federicotartarini  
🙏 Support my channel on Patreon at   / federicotartarini  
☕ Support my channel by buying me a coffee - https://www.buymeacoffee.com/FedericoT

🎥 Playlists you may find useful:
➜ Beamer LaTeX course:
   • LaTeX Beamer  
➜ Full LaTeX course:
   • LaTeX  
➜ PyCharm course:
   • PyCharm  
➜ Building a documentation website with Docusaurus:
   • Docusaurus  

🎥 Videos you may find useful:
➜ Build and deploy a documentation website using Docusaurus 2:    • Build and deploy a documentation webs...  
➜ Add a glossary to your document containing terms and acronyms:    • Add a glossary to your document conta...  
➜ Write a paper using the Elsevier template:    • How to Get Started and Write a Paper ...  
➜ Overleaf and GitHub integration:    • Overleaf and GitHub integration - syn...  
➜ Review a document in Overleaf:    • Review a document in Overleaf  
➜ Export citations from Mendeley into LaTeX:    • Export citations from Mendeley into L...  
➜ Pandas DataFrame to LaTeX table:    • Pandas DataFrame to LaTeX table - LaT...  
➜ How to use git and GitHub with PyCharm:    • How to use git and GitHub with PyChar...  
➜ Use Grammarly in Overleaf ✍️:    • Use Grammarly in Overleaf ✍️  
➜ TeXiFy - PyCharm IntelliJ LaTeX plug-in:    • TeXiFy - PyCharm IntelliJ LaTeX plug-...  
➜ Nomenclature in LaTeX document:    • Nomenclature in LaTeX document - all ...  
➜ Why you should start using LaTeX now!!:    • 10 Reasons Why You Should Start Using...  

✅ Let's connect:
🌍 My website - https://federicotartarini.github.io/
💻 GitHub - https://github.com/FedericoTartarini
Twitter -   / federicotartar1  
LinkedIn –   / federico-tartarini  

📝 Useful notes:
Google's official guide: https://cloud.google.com/run/docs/qui...
Python versions supported by Docker: https://hub.docker.com/_/python

👨‍💻 Source code:
Copy the following code in Dockerfile
```

Use the official lightweight Python image.
https://hub.docker.com/_/python
FROM python:3

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 -r requirements.txt
RUN pip install 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 comfort:app
```

🎥 Content of this video:
00:00 - What you will learn
02:15 - Overview of the Flask application
03:40 - Run Flask application locally
04:45 - Dockerfile file
10:00 - .dockerginore file
12:00 - Push changes to GitHub
15:41 - Clone code in Google Cloud Shell
19:05 - Deploy Flask app to Google Cloud Run
22:20 - Update the Flask application

🔣 Keywords:
#Python #CloudRun #Docker #Flask #WebDevelopment #WebApplication #GoogleCLoudConsole