CircleCI 2.0 caching


#1

Hello,

I’ve started using CircleCI 2.0. Thanks for the great tool whatsoever.
I am a bit confused regarding the caching.

  1. My build contains of some OS dependencies, like FreeTDS which I need to install before I run my bundle install with tiny_tds gem. How can I cache it since it does not change almost ever?
  2. My Gemfile.lock doesn’t change and cache is found, but bundle install is executed everytime the build runs. What’s wrong with my config.yml file?

.circleci/config.yml

defaults: &defaults
  working_directory: ~/app
  parallelism: 1
  docker:
    - image: circleci/ruby:2.4.1-node
      environment:
        RAILS_ENV: test
        BUNDLE_PATH: vendor/bundle
    - image: circleci/mysql:5.7
      environment:
        MYSQL_USER: user
        MYSQL_DB: app_test
        MYSQL_PASSWORD: password
    - image: redis:3.2

version: 2
jobs:
  build:
    <<: *defaults
    steps:
      - restore_cache:
          keys:
            - v1-app-repo-{{ .Environment.CIRCLE_SHA1 }}
      - checkout
      - save_cache:
          key: v1-app-repo-{{ .Environment.CIRCLE_SHA1 }}
          paths:
            - ~/app

      # system dependencies
      - run:
          name: Install system dependencies
          command: |
            sudo apt-get update
            sudo apt-get install build-essential libc6-dev wget
            wget http://www.freetds.org/files/stable/freetds-1.00.80.tar.gz
            tar -xzf freetds-1.00.80.tar.gz
            cd freetds-1.00.80
            ./configure --prefix=/usr/local --with-tdsver=7.3
            sudo make
            sudo make install
            sudo apt-get install cmake

      # Which version of bundler?
      - run:
          name: Which bundler?
          command: bundle -v

      # bundle install
      - restore_cache:
          keys:
            - v1-app-bundle-{{ checksum "Gemfile.lock" }}
            - v1-app-bundle-
      - run: bundle check || bundle install
      - save_cache:
          key: v1-app-bundle-{{ checksum "Gemfile.lock" }}
          paths:
            - /vendor/bundle

      # install yarn
      - restore_cache:
          keys:
            - v1-app-yarn-{{ checksum "yarn.lock" }}
            - v1-app-yarn-
      - run:
          name: Yarn Install
          command: yarn install --cache-folder ~/.cache/yarn
      - save_cache:
          key: v1-app-yarn-{{ checksum "yarn.lock" }}
          paths:
            - ~/.cache/yarn

      # prepare database
      - run:
          name: Wait for DB
          command: dockerize -wait tcp://localhost:3306 -timeout 1m
      - run:
          name: Setup the env and database files
          command: |
            cd config/
            cp {env.example,env}.yml
            cp {database.example,database}.yml
      - run:
          name: Database setup
          command: bin/rails db:create && bin/rails db:schema:load --trace

      # Run Specs
      - type: shell
        name: "Run Punisher"
        command: |
          bundle exec rspec --profile 10 \
                            --format RspecJunitFormatter \
                            --out tmp/rspec.xml \
                            --format progress \
                            $(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)

      - store_test_results:
          path: tmp

      - type: shell
        name: Run pronto
        command: |
          git fetch && git merge-base origin/master HEAD
          bundle exec pronto run -c origin/master --exit-code

Output:

Restoring Cache
Found a cache from build 166 at v1-app-bundle-387dsdoSRtq9MxmmCaM5ASWaMaX_jZy9iQket7ZgeIU=
Size: 32 B
Cached paths:
  * /vendor/bundle

Downloading cache archive...
Validating cache...

Unarchiving cache...
bundle check || bundle install
Exit code: 0
#!/bin/bash -eo pipefail
bundle check || bundle install
The following gems are missing
 * rake (12.3.0)

#2

Seems like I had issues with cache path which has been changed.
The proper cache path for bundle is ./vendor/bundle and not /vendor/bundle

Thanks to the support team.


#3

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.