问题描述
运行构建时,在处理捆绑程序缓存时会显示以下输出:
还原缓存:
No cache is found for key: gems-E2sY+gLiTCg0YwHjev8ZrCqAW_U9vUHKPA_FZnRiAPc=-circleci-project-setup
No cache is found for key: gems-E2sY+gLiTCg0YwHjev8ZrCqAW_U9vUHKPA_FZnRiAPc=
保存缓存
Creating cache archive...
Uploading cache archive...
Stored Cache to gems-wV_lhNyGV+evee5LBWbzjy7uuCEgZRgX8PlgbJreAv4=-circleci-project-setup
* /home/circleci/project/vendor/bundle
,但用于保存的密钥与用于获取的密钥不匹配。因此,下一次构建时会出现另一个缓存未命中
圈子文件:
version: 2.1 # Use 2.1 to enable using orbs and other features.
# Declare the orbs that we'll use in our config.
# read more about orbs: https://circleci.com/docs/2.0/using-orbs/
orbs:
ruby: circleci/ruby@1.0
node: circleci/node@2
jobs:
build:
docker:
- image: cimg/ruby:2.7-node # use a tailored CircleCI docker image.
steps:
- checkout
- ruby/install-deps: # use the ruby orb to install dependencies
key: "gems"
# use the node orb to install our packages
# specifying that we use `yarn` and to cache dependencies with `yarn.lock`
# learn more: https://circleci.com/docs/2.0/caching/
- node/install-packages:
pkg-manager: yarn
cache-key: "yarn.lock"
test:
# we run "parallel job containers" to enable speeding up our tests;
# this splits our tests across multiple containers.
# !! No we don't,we only have a single node in the free plan
parallelism: 1
# here we set TWO docker images.
docker:
- image: cimg/ruby:2.7-node # this is our primary docker image,where step commands run.
- image: circleci/postgres:9.5-alpine
environment: # add POSTGRES environment variables.
POSTGRES_USER: xxx
POSTGRES_DB: xxx_test
POSTGRES_PASSWORD: xxx
# environment variables specific to Ruby/Rails,applied to the primary container.
environment:
BUNDLE_JOBS: "3"
BUNDLE_RETRY: "3"
DB_HOST: 127.0.0.1
db_password: xxx
RAILS_ENV: test
# A series of steps to run,some are similar to those in "build".
steps:
- checkout
- ruby/install-deps:
key: "gems"
- node/install-packages:
pkg-manager: yarn
cache-key: "yarn.lock"
# Here we make sure that the secondary container boots
# up before we run operations on the database.
- run:
name: Wait for DB
command: dockerize -wait tcp://localhost:5432 -timeout 1m
- run:
name: Database setup
command: bundle exec rails db:schema:load --trace
# Run tests
- run:
name: Tests
command: bundle exec rails test
# We use workflows to orchestrate the jobs that we declared above.
workflows:
version: 2
build_and_test: # The name of our workflow is "build_and_test"
jobs: # The list of jobs we run as part of this workflow.
- build # Run build first.
- test: # Then run test,requires: # Test requires that build passes for it to run.
- build # Finally,run the build job.
我将如何解决此问题,以便正确存储缓存
解决方法
我想我找到了问题。
在构建项目时,我从未推送过Gemfile.lock
文件。我认为gemfile.lock文件经过哈希处理以生成密钥,因为存储库包含一个旧的gemfile,哈希值不匹配。运行捆绑程序后,锁文件会更改,因此它会获得一个新的哈希(已经存在)。由于我从未在本地运行捆绑程序,因此从未更新过本地的gemfile.lock,因此从未将其推送到存储库中。