0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Cloud Functions for Firebase のGitHub Actions CD

Last updated at Posted at 2025-10-22

主な機能

  • トリガー: develop ブランチへのpush時、または手動実行
  • 監視対象: firebase-functions/** と firestore/** の変更
  • デプロイ内容: Functions、Firestore Rules、Firestore Indexes
  • 環境: GitHub の dev environment を使用
firebase-functions-cd-dev.yml
name: Firebase Functions CD (Dev)

on:
  push:
    branches:
      - develop
    paths:
      - "firebase-functions/**"
      - "firestore/**"
      - ".github/workflows/firebase-functions-cd-dev.yml"
  workflow_dispatch:

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment:
      name: dev

    steps:
      - name: Checkout
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

      - name: Setup Node.js
        uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
        with:
          node-version: 20
          cache: "npm"
          cache-dependency-path: "firebase-functions/package-lock.json"

      - name: Install dependencies
        working-directory: ./firebase-functions
        run: npm ci

      - name: Install Firebase CLI
        run: npm install -g firebase-tools@14.5.0

      - name: Create SA Key File
        run: echo "${{ secrets.GCP_SERVICE_ACCOUNT_KEY_DEV }}" | base64 -d > ${{ github.workspace }}/gcloud-service-key.json

      - name: Deploy to Firebase
        env:
          GOOGLE_APPLICATION_CREDENTIALS: ${{ github.workspace }}/gcloud-service-key.json
        run: |
          firebase deploy --only functions,firestore:rules,firestore:indexes --project ${{ secrets.GCP_PROJECT_ID_DEV }} --non-interactive --force

      - name: Clean up SA Key File
        if: always()
        run: rm -f ${{ github.workspace }}/gcloud-service-key.json

必要なシークレット設定

  • GitHub リポジトリの Settings → Secrets and variables → Actions で以下を設定:

  • GCP_SERVICE_ACCOUNT_KEY_DEV - GCP サービスアカウントキー (base64エンコード済み)
    GCP_PROJECT_ID_DEV - GCP プロジェクトID

セキュリティのため、サービスアカウントキーファイルは使用後に自動的に削除されます。

サービスアカウントのロール

ロール名 (日本語) ロールID (英語) 理由
Cloud Functions 開発者 roles/cloudfunctions.developer Firebase Functionsのデプロイに必要です。
Firebase Rules 管理者 roles/firebase.rulesAdmin Firestoreのセキュリティルール (firestore.rules) のデプロイに必要です。
サービス アカウント ユーザー roles/iam.serviceAccountUser Functionsが実行時にサービスアカウントとして動作するために必要です。
Firebase Extensions 閲覧者 roles/firebaseextensions.viewer デプロイプロセス中にFirebase Extensionsの情報を参照するため、403 Permission Deniedエラーの回避に必要でした。
Secret Manager のシークレット アクセサー roles/secretmanager.secretAccessor FunctionsのコードがSecret Managerに保存されたシークレットの値を取得するために必要でした。
Cloud Scheduler 管理者 roles/cloudscheduler.admin Cloud Schedulerを更新する functions があるので
Cloud Storage for Firebase 管理者 roles/firebase.storageAdmin
Firebase Authentication 管理者 roles/firebaseauth.admin
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?