CodeBuild - Extremely long build times/caching

1

My project is a large JS/Yarn monorepo (using workspaces) that is contributed to dozens of times a day, by multiple devs. Every time a PR is opened, we build, lint, and test the project, which requires running yarn install before anything else. Once a merge occurs to the main branch, any open PRs must merge with the new main branch, and the PR checker needs to be run again before that branch is merged. As you can imagine, there can be a pretty large backlog of open PRs when we're in crunch time.

I have successfully used (both s3 & local) caching before in smaller projects, however I can't seem to get local caching working with our monorepo (this is a large project, so s3 is much too slow for us, as far as I can tell).

When we try using local caching, our build fails with "EEXIST: file already exists, mkdir '/codebuild/output/src11111111/src/github.com/OUR_ORG/OUR_PROJECT/node_modules/@OUR_PACKAGE/common'"..

This behavior is documented across the web:

Some of the remedies include using s3, but as mentioned this is a large project and we update packages at least once every two weeks (some weeks , multiple times), and our initial upload more than doubles our time to 40min. Downloading doesn't save us much time either.

  • Are there any reasonable steps we can take to cache our node_modules directories so we don't have to pull from yarn every time?
  • Are there any other solutions to speed up these build times (we're currently ~14min. After optimizing other parts of the build process)?
  • Do you have any example (large) mono repos you can point to as a template?
  • Any other tips to speed up our build times?
JH-Wapo
已提問 2 年前檢視次數 2056 次
1 個回答
0

I would think you should be able to check for the presence of the directory during your build, and only call yarn install if the directory is not present. For example:

if [ ! -d "/codebuild/output/src11111111/src/github.com/OUR_ORG/OUR_PROJECT/node_modules/@OUR_PACKAGE/common" ]; then
  yarn install
fi

This would only run yarn install if the directory does not exist, avoiding this error when the package cache exists due to local caching.

That said, S3 caching does tend to be faster than installing packages, since the files can be pulled without leaving the AWS network, and there is also less processing involved with the cache than there is with any package manager, so this option is worth exploring if the above doesn't work for you.

As for speeding up the build times, there aren't many general suggestions I can make, although if a significant portion of your build is in the PROVISIONING state, you may find better performance by ensuring you are on the latest release of the CodeBuild image, as the docker image for this is cached, whereas the older versions may not be.

Unfortunately, I wouldn't have any examples I can offer for large repos using CodeBuild, however you are certainly free to open a case if you'd like us to take a closer look at your environment!

AWS
支援工程師
Wayne_G
已回答 2 年前
profile picture
專家
已審閱 1 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南