Search code examples
firebaseyamlfirebase-hostingcirclecifirebase-cli

CircleCI permission denied opening firebase-tools.json for Firebase deployment


I'm using Firebase to host my personal website and wanted to integrate CircleCI for faster integration. However I receive this error on the step for deployment:

Note Adding sudo before the deploy command causes the build to fail also

/home/circleci/project/node_modules/configstore/index.js:52
          throw error;
          ^

Error: EACCES: permission denied, open '/home/circleci/.config/configstore/firebase-tools.json'
You don't have access to this file.

Below is my project's yaml configuration:

---
commands:
  restore_cache_cmd:
    description: "Restore cached npm install"
    steps:
      - restore_cache:
          key: 'dependency-cache-{{checksum "package.json"}}'
  save_cache_cmd:
    description: "Saving npm install"
    steps:
      - save_cache:
          key: 'dependency-cache-{{ checksum "package.json"}}'
          paths:
            - "./node_modules"
  update:
    description: "Installing project's dependencies"
    steps:
      - checkout
      - restore_cache_cmd
      - run: sudo npm i -g npm@latest
      - run: sudo npm i
      - save_cache_cmd
  build_deploy:
    description: "Building project"
    steps:
      - run:
          name: Build
          command: sudo npm run build
      - run:
          name: Deploy
          command: ./node_modules/.bin/firebase deploy --token=$FIREBASE_DEPLOY_TOKEN -- only hosting
executors:
  docker-executor:
    docker:
      - image: "cimg/node:12.14.1"
jobs:
  build_site:
    executor: docker-executor
    working_directory: ~/Darryls-Personal-Site
    steps:
      - update
      - build_deploy
version: 2.1
workflows:
  build_site:
    jobs:
      - build_site:
          filters:
            branches:
              only: master

Steps that I have already completed from other questions:

  • Used firebase login:ci to obtain refresh token and placed into an environment variable within my CircleCI project environment
  • Used npm install --save-dev firebase-tools

Solution

  • I think the problem is that you run all your npm commands with sudo except the firebase deploy command. You should definitely run everything with the current user and not the superuser. You will see in official tutorials that nothing is run with sudo except for very specific cases.

    Also, instead of doing this ./node_modules/.bin/firebase deploy you could use npx run firebase deploy which first look in the local node_modules then in the global ones.