'CodeBuild file caching not making a difference in build times
Problem
CodeBuild does not appear to be properly caching directories
What I expect
I expect to cache directories and decrease build times
Description
I have a CodeBuild project that has been building a Node project consisting of two Sources at ~2minutes per build. I'm trying to reduce the time between builds as much as possible but nothing I've tried as far as caching goes has changed the build times.
I've looked through several posts from AWS, as well as several here on SO but unfortunately, my build times are not changing.
I've set up Local caching in my CodeBuilds "Artifacts" section to use both "Source Cache" and "Custom Cache" which I've specified in my buildspec.yml "cache" property.
Am I expecting something that just isn't going to happen or am I doing something wrong?
buildspec.yml
version: 0.2
phases:
install:
runtime-versions:
nodejs: 12
pre_build:
commands:
- 'curl -d "{\"state\":\"pending\", \"target_url\":\"http://abc123.s3-website-us-east-1.amazonaws.com/${CODEBUILD_WEBHOOK_TRIGGER}/\", \"description\":\"Generating Preview Site\", \"context\":\"ci/preview\"}" -H "Content-Type: application/json" -H "Authorization: token ${GH_AUTH_TOKEN}" -X POST https://api.github.com/repos/abc/123/statuses/${CODEBUILD_RESOLVED_SOURCE_VERSION}'
build:
commands:
- cd ../main-website/hugo # switch from Primary Source to Secondary
- mv ../../main-website-content . # Move Primary Source into Secondary
- rm -rf hugo/static/admin # Remove Admin page
- cd ../
- yarn
- yarn cache dir # /usr/local/share/.cache/yarn/v6
- yarn build
post_build:
commands:
- aws s3 cp --recursive dist/ s3://abc123/${CODEBUILD_WEBHOOK_TRIGGER} --region us-east-1
- 'curl -d "{\"state\":\"success\", \"target_url\":\"http://abc123.s3-website-us-east-1.amazonaws.com/${CODEBUILD_WEBHOOK_TRIGGER}/\", \"description\":\"Generating Preview Site\", \"context\":\"ci/preview\"}" -H "Content-Type: application/json" -H "Authorization: token ${GH_AUTH_TOKEN}" -X POST https://api.github.com/repos/abc/123/statuses/${CODEBUILD_RESOLVED_SOURCE_VERSION}'
cache:
paths:
- '/usr/local/share/.cache/yarn/'
- '../emergency-website/node_modules/'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|