Getting Cannot open: Permission denied when trying to restore cache

I am trying to restore cache. I have a Node Container and when I install npm packages globally they are being put into /usr/local/bin (circle 2.0). In circle 1 they were in /opt/circleci/nodejs/v6.10.3/bin/

Now when I run a new job and try to restore the cache keys I get the following error:

Unarchiving cache…
tar: usr/local/bin/_mocha: Cannot open: Permission denied
tar: usr/local/bin/aws: Cannot open: File exists
tar: usr/local/bin/aws.cmd: Cannot open: Permission denied
tar: usr/local/bin/aws_bash_completer: Cannot open: Permission denied

I assume this is because the circleci user doesn’t have privileges but if that is the case how do I restore the cache?

As a side note, I have been playing with circle 2.0 for a while now. Its WAY faster but the documentation is greatly lacking. Example of this stuff would be immensely helpful.

Sincerely

Hi,

Can you provide snippets of your config file? Also, the NodeJS image that you are using.

version: 2

jobs:
  build:
    working_directory: ~/common-js
    resource_class: large
    docker:
      - image: circleci/node:6.10.3-browsers
    steps:
      - checkout
      - restore_cache:
          keys:
            # See if this exact revision was already built
            - dependency-cache-{{ .Branch }}-{{ .Revision }}
            # Else look for a previous build of this branch
            - dependency-cache-{{ .Branch }}
            # Else master
            - dependency-cache-master
      - run:
          name: install pip
          command: |
            sudo apt-get update
            sudo apt-get install -y python-dev python-pip
      - run:
          name: install aws cli (needed for deploys)
          command: sudo pip install awscli
      - run:
          name: setup npm dependencies
          command: |
            if [ ! -e /opt/circleci/nodejs/v6.10.3/bin/mocha ]; then sudo npm i -g jasmine-node mocha; fi
            if [ ! -e /opt/circleci/nodejs/v6.10.3/bin/eslint ]; then sudo npm i -g eslint@3.19.0; fi
            if [ ! -e /opt/circleci/nodejs/v6.10.3/lib/node_modules/eslint-plugin-mocha ]; then sudo npm i -g eslint-plugin-mocha; fi
- save_cache:
      key: dependency-cache-{{ .Branch }}-{{ .Revision }}
      paths:
        - /usr/local/lib
        - /usr/local/lib/node_modules

In circle 1 they were in /opt/local/but now they are in usr/local/bin and that cache cannot be restored due to permissions issues as stated above. Let me know if you need anymore info. I am blocked at the moment as a result of this.

Sincerely,

Two things I see here.

  1. save_cache isn’t properly indented. I assume that was just a copy & paste typo?

  2. Clearly there’s permission issues. Maybe setting more permissive permissions on those directories before restore would help. my recommendation however would be to not install everything globally. The build environment gives you isolation and is throwaway. Installing locally within the user directory as much as possible would make things simpler. For example, here’s a post on Stack Overflow on using a local mocha binary instead of installing globally: https://stackoverflow.com/questions/9722407/how-do-you-install-and-run-mocha-the-node-js-testing-module-getting-mocha-co#24497202