5

Whenever my job run, they always take around 40s to download and install libreoffice. I'm gonna to store this into cache and restore cache to reuse it in next job.

      - restore_cache:
          key: cache-libre-6.3-b             # Restore libreoffice
      - run:
          name: install libreoffice 6.3
          command: |
            if [[ ! -d /opt/libreoffice6.3/ ]]; then
                # download & install the .deb
                mkdir -p /tmp/libreoffice
                l=download.tar.gz
                cd /tmp/libreoffice
                  wget -O $l https://download.documentfoundation.org/libreoffice/stable/6.3.3/deb/x86_64/LibreOffice_6.3.3_Linux_x86-64_deb.tar.gz
                  tar -xvf $l
                  d=`ls -td */ | head -n1`
                  cd $d/DEBS/
                  sudo dpkg -i *.deb
                cd -

                # install dependencies required when run :soffice binary  ref. https://github.com/microsoft/vscode/issues/13089
                sudo apt update
                sudo apt install -y libxinerama1 libgtk2.0-0 libxss-dev libgconf-2-4 libasound2

            fi
            # make :libreoffice softlink to libreoffice binary 6.3
            sudo ln -s /opt/libreoffice6.3/program/soffice /usr/bin/libreoffice
            sudo chmod -R 777 /opt/libreoffice6.3/
      - save_cache:
          key: cache-libre-6.3-b
          paths:
            # Save cache libreoffice
            - /opt/libreoffice6.3/
            - /home/circleci/cache-libre

When I rerun the job again, I can not restore cache. I got some permission denied below:

Found a cache from build 7593 at cache-libre-6.3-b
Size: 271 MB
Cached paths:
  * /opt/libreoffice6.3
  * /home/circleci/cache-libre

Downloading cache archive...
Validating cache...

Unarchiving cache...

Failed to unarchive cache

Error untarring cache: Error extracting tarball /tmp/cache785237819 : tar: opt/libreoffice6.3: Cannot mkdir: Permission denied tar: opt/libreoffice6.3: Cannot mkdir: Permission denied tar: opt/libreoffice6.3/CREDITS.fodt: Cannot open: No such file or directory tar: opt/libreoffice6.3: Cannot mkdir: Permission denied tar: opt/libreoffice6.3/LICENSE: Cannot open: No such file or directory tar: opt/libreoffice6.3: Cannot mkdir: Permission denied tar: opt/libreoffice6.3/LICENSE.html: Cannot open: No such file or directory tar: opt/libreoffice6.3: Cannot mkdir: Permission denied tar: opt/libreoffice6.3/NOTICE: Cannot open: No such file or directory tar: opt/libreoffice6.3: Cannot mkdir: Permission denied tar: opt/libreoffice6.3/help: Cannot mkdir: No such file or directory tar: opt/libreoffice6.3: Cannot mkdir: Permission denied tar: opt/libreoffice6.3/help/a11y-toggle.js: Cannot open: No such file or directory tar: opt/libreoffice6.3: Cannot mkdir: Permission denied tar: opt/libreoffice6.3/help/default.css: Cannot open: No such file or directory tar: opt/libreoffice6.3: Cannot mkdi: exit status 2

How can I solve this.

bxdoan
  • 1,349
  • 8
  • 22

1 Answers1

5

This happened to me recently also. Given that I had many builds saving and restoring that cache using that key before it might have been intermittent and it's unlikely this was a direct cause; however, I would mention this just in case it happens to help people.

I had previously been playing with the working_directory command in attempt to use the persist-to-workspace and attach_workspace and think this could have caused the issue.

Sequence that might have caused error:

  • Build A:

    1. set working directory working_directory: ~/tmp
    2. save cache with key X
  • Build B:

    1. default working directory (did not use working_directory command)
    2. attempt to restore cache with same key X (but different working directory)
    3. Error untarring cache: Error extracting tarball

Solution that fixed it was simply changing the cache key. Such as from v1 prefix to v2. This avoids attempting to restore cache that was made for working directory tmp to be attempted to be restored to different working directory. It now uses a fresh one.

Matt Mazzola
  • 4,593
  • 4
  • 22
  • 28