1

I'm trying to use AWS Codebuild - Local Custom Cache. I'm failing to perform the simplest task of caching a file between builds. What's explained here: AWS CodeBuild local cache failing to actually cache? doesn't work for me.

This is my buildspec.yml

version: 0.2

phases:
  pre_build:
    commands:
      - CACHE_DIR='docker-img-cache'
      - CACHED_FILE='docker-img-cache/test.md'
  build:
    commands:
      - ls $CACHE_DIR
      - ls -sh $CACHED_FILE || true
      # If file exist, print its content and size
      - if [ -f $CACHED_FILE ]; then echo "File is in cache"; ls -sh $CACHED_FILE; fi
      # Else create file, print its size
      - if ! [ -f $CACHED_FILE ]; then echo "Hello cache world" > $CACHED_FILE; echo "File created"; ls -sh $CACHED_FILE; fi
      - ls $CACHE_DIR
cache:
  paths:
    - 'docker-img-cache'

Only the directory gets cached, but without the file inside. I've already tried with the '/* '/**/*' suffixes.

If you try it on your own, you will be able to see that file gets created on every build. However the directory exists.

reinier
  • 27
  • 6
  • Does this answer your question? [AWS CodeBuild local cache failing to actually cache?](https://stackoverflow.com/questions/58793704/aws-codebuild-local-cache-failing-to-actually-cache) – pawel Jun 03 '21 at 16:39

2 Answers2

0

Please validate if you have enabled custom cache mode

In the build project configuration, under Artifacts, expand Additional Configuration. For Cache type, choose Local.

mmansoor
  • 580
  • 5
  • 11
0

Appears to be a duplicate of AWS CodeBuild local cache failing to actually cache?, so flagged it.

To summarize the earlier question, there is no good solution in using a local cache with CodeBuild (see comment linking to another post that indicates that local cache is pretty unpredictable), so switch to an S3 cache.

pawel
  • 518
  • 7
  • 21