GCPを使ってみる(3)Google App Engine で簡単なWebアプリ作成

GCP Cloud Console にログインした後、右上にあるアイコンの「>_」とある部分をクリックすると、シェルが実行可能になる

Welcome to Cloud Shell! Type “help” to get started.
Your Cloud Platform project in this session is set to ****-project.
Use “gcloud config set project [PROJECT_ID]” to change to a different project.

【1.初期確認】
・内容確認
$ ls -l
total 8
drwxr-xr-x 3 **** **** 4096 May 11 07:29 cloud-console-sample-build
-rw-r–r– 1 **** **** 913 May 16 05:44 README-cloudshell.txt

・容量確認
$ df
Filesystem 1K-blocks Used Available Use% Mounted on
overlay 62742040 46493984 16231672 75% /
tmpfs 65536 0 65536 0% /dev
tmpfs 4074188 0 4074188 0% /sys/fs/cgroup
/dev/sda1 62742040 46493984 16231672 75% /root
/dev/disk/by-id/google-home-part1 5028480 10496 4739508 1% /home
/dev/root 2003760 1070072 933688 54% /usr/lib/modules
shm 65536 0 65536 0% /dev/shm
tmpfs 1629676 1004 1628672 1% /google/host/var/run

【2.作業用ディレクトリ作成】
$ mkdir -p work/hello_world && cd work/hello_world

【3.Flask用サンプルファイル作成】
$ echo “runtime: python37” > app.yaml
$ cd work/hello_world
:~/work/hello_world (****-project)$ echo “runtime: python37” > app.yaml
:~/work/hello_world (****-project)$ echo “Flask==1.0.2” > requirements.txt
:~/work/hello_world (****-project)$ vi main.py
$ cat main.py
from flask import Flask
app = Flask(__name__)

@app.route(‘/’)
def hello():
return ‘Hello World!’

:~/work/hello_world (****-project)$ vi main.py
:~/work/hello_world (****-project)$ ls
app.yaml main.py requirements.txt
:~/work/hello_world (****-project)$ gcloud app deploy
Services to deploy:

descriptor: [/home/****/work/hello_world/app.yaml]
source: [/home/****/work/hello_world]
target project: [****-project]
target service: [default]
target version: [20220516t055244]
target url:
https://****-project.an.r.appspot.com

target service account: [App Engine default service account]

Do you want to continue (Y/n)? Y

Beginning deployment of service [default]…
Created .gcloudignore file. See `gcloud topic gcloudignore` for details.
Uploading 3 files to Google Cloud Storage
33%
67%
100%
100%
File upload done.
Updating service [default]…done.
Setting traffic split for service [default]…done.
Deployed service [default] to
https://****-project.an.r.appspot.com

You can stream logs from the command line by running:
$ gcloud app logs tail -s default

To view your application in the web browser run:
$ gcloud app browse

 

タイトルとURLをコピーしました