LoginSignup
17
10

More than 1 year has passed since last update.

CircleCiとFireBaseを連携させるのに4時間かかった

Last updated at Posted at 2018-11-17

CircleCiとFireBaseの連携に4時間かかったのでまとめ( ;∀;)

結果は下記の.circleci/config.yml

やったこと

Firebaseデプロイ用トークンの発行

以下のサイトを参考にさせていただきました。
https://qiita.com/ottijp/items/974e092a87fbffc3f191

Firebaseデプロイ用ID

2018-11-18.png

赤押して、緑押せば、プロジェクト ID が表示されているはずです。それです。

デプロイするにはCI環境下で、Firebase のデプロイをしたいので、firebase-toolsをインストールする必要がある

以下のサイトを参考にさせていただきました。
https://qiita.com/samuraikun/items/a7de51dab70ab853b9ff

デプロイコマンドが実行されない

今まで見てきたサイトを参考にすると、

command: >- 
              ln -s ./node_modules/firebase-tools/bin/firebase . &&
              ./firebase deploy --only hosting --project "$FIREBASE_PROJECT_ID" --token "$FIREBASE_TOKEN"

か、

commands:
      - firebase deploy --project "$FIREBASE_PJ" --token "$FIREBASE_TOKEN"

といったコマンドをじっこうすればよいと考えられます。

しかし、自分の環境ではうまくいきませんでした。

node_modules/firebase-tools/binにある、firebaseを実行すればよいものだとおもい、パスを調べるためにyml内に

find `pwd` -maxdepth 1

上記コマンドを仕込み、/home/circleci/repo/node_modules/firebase内のfirebaseに対して、コマンドを実行したりして、みたのですが、うまくいかず

/bin/bash: repo/node_modules/firebase-tools/bin/firebase: No such file or directory
Exited with code 1

このエラーを30回くらいみました。

解決

https://blog-tech.xyz/2018/08/31/hexo-on-circleci-and-firebase/
https://discuss.circleci.com/t/deploy-to-firebase-not-working/22887/3

上記サイトを参考にしたところ、

〇 node_modules/.bin/firebase
× node_modules/firebase-tools/bin/firebase

だということが判明しました。確かに、正しいほうのフォルダ内を見ると、firebaseや、firebase.cmdといった、それっぽいファイルがあります。

ということで、最終的には、

config.yml
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
jobs:
  build:
    docker:
      - image: circleci/node:8

    working_directory: ~/repo

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
          - v1-dependencies-{{ checksum "package.json" }}
          # fallback to using the latest cache if no exact match is found
          - v1-dependencies-

      - run: npm install

      - run:
          name: 'Install Dependecies'
          command: npm install --save-dev firebase-tools

      - save_cache:
          paths:
            - node_modules
          key: v1-dependencies-{{ checksum "package.json" }}

      - run:
          name: 'Build Client Code(react-scripts によるビルド実行)'
          command: npm run build

      - attach_workspace:
          at: .

      - run:
          name: 'Deploy to Hosting'
          command: node_modules/.bin/firebase deploy --only hosting --project "$FIREBASE_PJ" --token "$FIREBASE_TOKEN"

となりました。

参考にさせていただきました。助かりました。

https://blog-tech.xyz/2018/08/31/hexo-on-circleci-and-firebase/
https://discuss.circleci.com/t/deploy-to-firebase-not-working/22887/3
https://qiita.com/samuraikun/items/a7de51dab70ab853b9ff
https://qiita.com/ottijp/items/974e092a87fbffc3f191

17
10
1

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
10