Codebuild custom cache is emptied mysteriously

0

I am running CodeBuild for building rust binaries and caching Cargo packages for faster build times using the custom cache feature. Buildspec yaml below. I am running into a problem where the build cache resets approximately every second build.

version: 0.2

phases:
  build:
    commands:
       - PATH=$PATH:$HOME/.cargo/bin && ls $HOME/.cargo/registry/cache/ && PKG_CONFIG_ALLOW_CROSS=1 cargo build -j 8 --target=armv7-unknown-linux-gnueabihf --release && s3cmd put ./target/armv7-unknown-linux-gnueabihf/release/example_* s3://example-product-builds/ --acl-public
cache:
  paths:
     - /root/.cargo/registry/cache/
     - /root/.cargo/registry/index/
     - /root/.cargo/registry/src/
     - ./target/

The cache works, but not on every build. For some reason approximately every second build the cached folders are empty. I have checked this by running ls on the cache directories during the build. Also, there is a significant impact on build time so it is obvious if the cache works or not. For example, the last 10 builds have been 4 minutes without cache and 30 seconds with cache. I have also verified that the build time does not depend on the source code by building the same source multiple times in a row.

I have also tried the /**/* syntax and it has the same problem

cache:
  paths:
     - /root/.cargo/registry/**/*
     - ./target/**/*

Edited by: devaj on Nov 18, 2019 5:20 AM

devaj
질문됨 4년 전412회 조회
1개 답변
0
수락된 답변

Hi,

As I can find on the documentation https://docs.aws.amazon.com/codebuild/latest/userguide/build-caching.html, local caching stores a cache locally on a build host that is available to that build host only. If your second build starts while your first build is still running, you will not be able to hit the cache because your second build will use a new host which doesn't have cache stored.

Regards,
Kaixiang

답변함 4년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠