GCP Python_Flask搭建与使用
Contents
[NOTE] Updated April 24, 2022. This article may have outdated content or subject matter.
GCP Python 文檔
Installing the gcloud CLI
Download
#x86_64
curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-382.0.0-linux-x86_64.tar.gz
#arm64
curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-382.0.0-linux-arm.tar.gz
#x86
curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-382.0.0-linux-x86.tar.gz
tar -xf google-cloud-*.tar.gz
./google-cloud-sdk/install.sh
Initialize the gcloud CLI
Run gcloud init:
gcloud init
If you are in a remote terminal session, you can use the –console-only flag to prevent the command from launching a browser-based authorization flow, if required:
gcloud init --console-only
Demo
Deploy
gcloud app deploy
main.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello World!'
if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080, debug=True)
requirements.txt
Flask==2.1.0
app.yaml
runtime: python39
My Project
Author w0x7ce
LastMod 2022-04-24