Search code examples
cachinglibreofficecircleci

CircleCI - how to download dependency only if not cached


in brief

When using circleci to run unittest, I have to download & install LibreOffice. How can we do the download only if not cached?

p.s. Also posted on circleci support here

details

LibreOffice download & install often takes 30+ seconds to complete.

So I intend to cache it using save_cache feature here

My google search leads me to when steps here, though the guide there is not clear about how to check if a cache key exists.

I put the marker HOW_TO in the .circleci/config.yml below snippet

      - restore_cache:
          key: cache-libreoffice

      - when:
          condition: <<HOW_TO check if cache key exists >>
          steps:
            - run:
                name: install atlas Pipfile
                command: |
                  mkdir -p /tmp/libreoffice
                  cd /tmp/libreoffice
                    wget https://download.documentfoundation.org/libreoffice/stable/6.3.3/deb/x86_64/LibreOffice_6.3.3_Linux_x86-64_deb.tar.gz

      - save_cache:
          key: cache-libreoffice
          paths:  # the paths to save to cache entry
            - /tmp/libreoffice

Solution

  • As circleci official support seems to give less helpful hints for the question, my workaround is to use custom docker image and have those dependencies installed there.