はじめに

Cloud Run: コンテナを秒単位で本番環境にデプロイ | Google Cloud
コンテナを自動的にスケールするフルマネージド型のコンピューティング プラットフォーム。お好みの言語でアプリケーションを構築し、それを数秒でデプロイできます。

Cloud Build: サーバーレス CI / CD プラットフォーム | Google Cloud
継続的インテグレーション、デリバリー、デプロイのためのフルマネージド プラットフォーム。高速かつ一貫性のある信頼性の高い自動ビルドが行われます。コーディングに集中していただけます。
試したチュートリアル

システム パッケージのチュートリアルを使用する | Cloud Run のドキュメント | Google Cloud
Cloud Build + Container Registry + Cloud Runへのデプロイ
ソースファイルの準備
### Git インストール
# yum install git
### サンプルプロジェクトのクローン
# git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
### ソースフォルダへ移動
# cd python-docs-samples/run/system-package/
### ソースファイルの確認
# ls -1
Dockerfile
e2e_test.py
main.py
main_test.py
noxfile_config.py
README.md
requirements-test.txt
requirements.txt
主要なファイルは以下。
ファイル名 | 内容 |
Dockerfile | 環境構成の定義ファイル |
main.py | ・受信リクエストを処理する ・dotコマンドで図を生成する |
Cloud Buildでのデプロイ
まずはgcloudコマンドの初期設定
### gcloudコマンドの初期設定
# gcloud init
### ログインアカウントの選択
Choose the account you would like to use to perform operations for
this configuration:
[1] xxxxxxxx@developer.gserviceaccount.com
[2] Log in with a new account
Please enter your numeric choice: 2
### 認証コードの取得
Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?(省略)
Enter verification code: xxxxx
### デフォルトプロジェクトの選択
Pick cloud project to use:
[1] xxxx
[2] test-project-304205
[3] Create a new project
Please enter numeric choice or text value (must exactly match list
item): 2
### デフォルトリージョン・ゾーンの選択
Do you want to configure a default Compute Region and Zone? (Y/n)?
…
[32] asia-northeast1-b
[33] asia-northeast1-c
[34] asia-northeast1-a
[35] asia-south1-c
[36] asia-south1-b
…
Please enter numeric choice or text value (must exactly match list
item): 34
### 設定の確認
# gcloud config list
[compute]
region = asia-northeast1
zone = asia-northeast1-a
[core]
account = xxxx
disable_usage_reporting = True
project = test-project-304205
Your active configuration is: [default]
gcloudコマンドでCode Build
※ Dockerfile が格納されているディレクトリから次のコマンドを実行します。
# gcloud builds submit --tag gcr.io/test-project-304205/graphviz

Container Registryにイメージが保管されたことを確認したので、Cloud Runにデプロイする。
# gcloud run deploy graphviz-web --image gcr.io/test-project-304205/graphviz
Please choose a target platform:
[1] Cloud Run (fully managed)
[2] Cloud Run for Anthos deployed on Google Cloud
[3] Cloud Run for Anthos deployed on VMware
[4] cancel
Please enter your numeric choice: 1
Please specify a region:
[1] asia-east1
[2] asia-east2
[3] asia-northeast1
[4] asia-northeast2
[5] asia-northeast3
[6] asia-south1
…
Please enter your numeric choice: 3
Allow unauthenticated invocations to [graphviz-web] (y/N)? y
Deploying container to Cloud Run service [graphviz-web] in
project [test-project-304205] region [asia-northeast1]
✓ Deploying new service... Done.
✓ Creating Revision...
✓ Routing traffic...
✓ Setting IAM Policy...
Done.

Cloud Run の動作確認
サービスドメインはURLに記載されている部分

https://graphviz-web-iwns2ji2la-an.a.run.app/diagram.png?dot=digraph Run { rankdir=LR Code -> Build -> Deploy -> Run }

コメント