continuous-integration - CircleCI 缓存键不匹配
问题描述
当我运行我的构建时,它会在处理捆绑器缓存时显示此输出:
恢复缓存:
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。运行 bundler 后,锁定文件会发生变化,因此它会获得一个新的哈希(已经存在)。因为我从来没有在本地运行过 bundler,所以它从来没有更新我的本地 gemfile.lock 所以它从来没有被推送到 repo。
推荐阅读
- f# - Fable 中的“this”属性是如何使用的?
- javascript - Discord.js 速率限制延迟
- java - Spring Boot Mongo Data - 如何设置命名策略
- regex - VBS 正则表达式将插入字符替换为许多相似的短语
- html - 如何使用 TWIG 删除部分 HTML 代码?
- groovy - JMeter Groovy - 响应代码为 500 的 WebDriver 采样器动态名称
- discord.js - 如何获得 3 次用户提及?- 不和谐-js
- interface - 在 F# 中,如何将接口添加到部分类(来自另一个项目)
- javascript - 如何在 Jest 中测试内部商店更新?
- html - 如何用xml和xsl显示img