Error on attaching workspace from Ramdisk

Hi, we are trying to speed up our build times and decided to use Ramdisk however we are getting an error on the second job that needs to read the output from the first job, here is the relevant jobs from our config:

  build:
    docker:
      - image: cimg/node:16.20.2
    resource_class: large
    working_directory: /mnt/ramdisk
    steps:
      - checkout
      - run:
          name: Configure NPM_REGISTRY_TOKEN
          command: |
            echo $NPM_REGISTRY_TOKEN
            sed -i.bak "s/\${NPM_REGISTRY_TOKEN}/${NPM_REGISTRY_TOKEN}/g"  .npmrc
      - node/install-packages
      - run:
          name: Build
          command: npm run build
      - persist_to_workspace:
          root: /mnt
          paths:
            - ramdisk

  test:
    docker:
      - image: cimg/node:16.20.2
    resource_class: xlarge
    parallelism: 7
    working_directory: /mnt/ramdisk
    steps:
      - attach_workspace:
          at: /mnt
      - run:
          name: Run unit tests
          command: |
            TEST=$(circleci tests glob "src/**/*.test.ts*")
            echo "$TEST" | circleci tests run --command="xargs npm run test:ci" --split-by=timings
          environment:
            JEST_JUNIT_OUTPUT_DIR: ./coverage/junit
      - store_test_results:
          path: ./coverage/junit
      - codecov/upload:
          file: ./coverage/lcov.info
      - persist_to_workspace:
          root: /mnt
          paths:
            - ramdisk

This is the error we get:


Error applying workspace layer for job 5295acdf-0e0c-4656-9025-120662cc977c: Error extracting tarball /tmp/workspace-layer-5295acdf-0e0c-4656-9025-120662cc977c739504217 : tar: ramdisk: Cannot utime: Operation not permitted tar: ramdisk: Cannot change mode to rwxr-xr-t: Operation not permitted tar: Exiting with failure status due to previous errors : exit status 2

It is likely that you will need to move/copy the files out of the ramdisk directory structure and then persist them in the build job and then reverse the process in the test job.

The reason for this is that tar is being used to do the persistence and when it tries to restore the directory to /mnt/ramdisk it is trying to call utime to change the last access time value on the directory but does not have the rights to do so as the directory owner is not the current user.

One thing that you could try is to create a subdirectory under /mnt/ramdisk rather than using /mnt/ramdisk this way you are using a directory you have created rather than a system directory.

Hi that worked, I actually just changed the attacht_at to be /mnt/ramdisk and that resolved it.