LoginSignup
17
13

More than 3 years have passed since last update.

Firebase デプロイに Cloud Build を使う

Last updated at Posted at 2019-09-04

Firebase Hosting や Functions に CI 通じてデプロイしたくなったので、GCP の Cloud Build を使って設定をしてみます。公式ドキュメントや他の方が試された記事だと FIREBASE_TOKEN が必要と書いてありますが、実は GCP の Google Application Default Credentials でトークン設定なしにデプロイが可能です。

教えていただいた @iwata@github さん感謝。

なお Cloud Build を有効にすると、自動的に Firebase のプランが Spark (無料) から Blaze になるので注意してください。

Firebase コンテナの用意

まず firebase コマンドを実行可能なコンテナを用意します。

git clone https://github.com/GoogleCloudPlatform/cloud-builders-community.git
cd cloud-builders-community/firebase
gcloud builds submit --project <project name> --config cloudbuild.yaml .

Cloud Build 設定ファイル

Firebase にデプロイするアプリケーションの Cloud Build 設定をします。今回の例は next.js のアプリケーションなので最初に node npm 関係のビルドをしています。重要なのは一番最後のステップです。ここで Firebase へデプロイをします。 FIREBASE_TOKEN の指定は必要ありません。

cloudbuild.yaml
steps:
  - id: 'Install npm packages'
    name: 'node:12.9-buster'
    args: ['npm', 'install']
  - id: 'Build App'
    name: 'node:12.9-buster'
    args: ['npm', 'run', 'build-app']
  - id: "Deploy to Firebase"
    name: 'gcr.io/$PROJECT_ID/firebase'
    args: ['deploy']

Cloud Build ADC 設定

Cloud Build から Firebase Hosting / Functions へデプロイするために権限を付与します。コンソール画面から設定します。

スクリーンショット_2019-09-04_15_38_50.png

デプロイ

あとはデプロイできるか試してみます。

gcloud builds submit --project <project name> --config cloudbuild.yaml .

正常にデプロイされたらトリガーを設定して終了です。簡単になりましたね。

(… functions を個別にデプロイさせるにはトリガーを細かく作りわけないと駄目なのがちょっと面倒くさいけど)

17
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
13