6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CircleCIで、Firebaseのコマンドを実行させる方法

Last updated at Posted at 2018-09-28

やりたいこと

  • リモートプッシュ時に Firebase のデプロイコマンドを実行したい

つまづいたこと

  • CircleCI環境下で、firebase のコマンド実行につまづいた

解決法

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

最初に、グローバルでインストールしようとしましたが、CircleCI環境下では、それが許可されていません。(そりゃそうか)

$ #!/bin/bash -eo pipefail
npm install -g firebase-tools
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!  { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!   stack: 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules' }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/circleci/.npm/_logs/2018-09-28T03_37_43_747Z-debug.log
Exited with code 243

公式ドキュメントに、Firebaseでのセットアップ方法が、ありました。
https://circleci.com/docs/2.0/deployment-integrations/#firebase

また、シンボリックリンクを作成して、実行する方法も、CircleCIのQAにあったので、これらを参考にして、以下のconfig.ymlで実行
https://discuss.circleci.com/t/firebase-cant-finde-npm-package/20126/3

# 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
      - run:
          name: 'Deploy to Hosting'
          command: >- 
              ln -s ./node_modules/firebase-tools/bin/firebase . &&
              ./firebase deploy --only hosting --project "$FIREBASE_PROJECT_ID" --token "$FIREBASE_TOKEN"

Firebase は、CI環境用に用意されたコマンドから、トークンを取得できるので、CircleCIにそれぞれFIREBASE_PROJECT_IDFIREBASE_TOKENを設定し、CIを走らせて、完了!

6
2
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
6
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?