高木のブログ

【Cloud Functions】Functions Framework for Rubyを試す(ローカルからデプロイ編)

· 111 words · 1 minutes to read

前回書いた「【Cloud Functions】Functions Framework for Rubyを試す(ローカル編) 」の続きで、今回はCloud Functionsにデプロイしてみる

手順 🔗

Cloud Functions APIとCloud Build APIを有効化 🔗

$ gcloud services enable cloudfunctions.googleapis.com
$ gcloud services enable cloudbuild.googleapis.com

デプロイ 🔗

gcloud functions deploy [関数の登録名] --entry-point [ソースコード内の関数またはクラスの名前] --runtime [使用するランタイムの名前] [関数のトリガーの種類]
$ gcloud functions deploy hello_function --entry-point hello --runtime ruby27 --trigger-http

Ruby 2.7のランタイムに HTTP リクエストをトリガーする hello 関数を hello_function という登録名でデプロイする

新しい関数を登録する場合は確認がある 🔗

Allow unauthenticated invocations of new function [hello_function]?
(y/N)?

動作確認 🔗

$ curl https://us-central1-hogehoge-123456.cloudfunctions.net/hello_function
Hello, world!

再デプロイ 🔗

コードを修正して再デプロイする場合、--runtime--trigger-httpは変更が無ければ省略できる

$ gcloud functions deploy hello_function --entry-point hello
$ curl https://us-central1-hogehoge-123456.cloudfunctions.net/hello_function
Hello, world! (Take 2)

補足 🔗

–entry-pointは省略できる 🔗

ソースコードの関数名と登録名を同じにする場合は省略できる
むしろ、–entry-pointは異なる時に使用する為のフラグかも

例) ソースコードの関数名が hello でそのまま関数の登録名にする

$ gcloud functions deploy hello --runtime ruby27 --trigger-http

これだと再デプロイはシンプルになる

$ gcloud functions deploy hello

参考 🔗

ローカルマシンからのデプロイ | Google Cloud Functions に関するドキュメント

Categories


Tags