-
-
Notifications
You must be signed in to change notification settings - Fork 0
Fixed and improved Docker build caching. #7988
Conversation
58f6be6
to
c2014ae
Compare
@@ -71,8 +71,8 @@ | |||
const buildErrors = fs.readFileSync(`${options.service}-build-error.txt`).toString() | |||
const builderRun = fs.readFileSync('builder-run.txt').toString() | |||
if (options.isDocker) { | |||
const hasError = /ERROR:/.test(buildErrors) | |||
if (hasError) { | |||
const cacheMissRegex = new RegExp(`${options.service}:latest_${process.env.RELEASE_NAME}: not found`) |
Check failure
Code scanning / CodeQL
Regular expression injection
Builder build process caching was not working because it was a multi-stage build. The default inline cache only caches the final stage of a multi-stage build, which almost always results in cache misses on the earlier stages. All builds in the builder were not being cached at all. Converted builds to explicitly use buildx. buildx build has support for automatically pushing tags, so separate steps for tagging and pushing images have been removed. In order to cache multi-stage builds, buildx has an option to cache everything. This has to be done with a cache target of something other than inline cache (which includes cache in the image). There is an option to use a Docker repository, but currently this is not supported by ECR. For now, using S3 as the cache target (another built-in option) for service images, and GH Actions cache for builder image. An issue has been opened to switch to the repo for the service images once it's supported. Commented out running npm install when each project is installed. This appeared to be causing issues where some packages, particularly semver, were not fully installed properly by the end, leading to errors when those packages were referenced. There is now a single npm install after installing all projects.
c2014ae
to
a58f421
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
- name: restore package.json | ||
run: mv package.jsonmoved package.json | ||
- name: Expose GitHub Runtime | ||
uses: crazy-max/ghaction-github-runtime@v2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
crazy-max/ghaction-github-runtime@v2
is used to access STORAGE_AWS_ACCESS_KEYs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually to access some GitHub Actions environment variables used for caching Docker cache within GH Actions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually to access some GitHub Actions environment variables used for caching Docker cache within GH Actions.
Summary
Builder build process caching was not working because it was a multi-stage build.
The default inline cache only caches the final stage of a multi-stage build, which
almost always results in cache misses on the earlier stages. All builds in the builder
were not being cached at all.
Converted builds to explicitly use buildx. buildx build has support for automatically
pushing tags, so separate steps for tagging and pushing images have been removed.
In order to cache multi-stage builds, buildx has an option to cache everything. This
has to be done with a cache target of something other than inline cache (which includes
cache in the image). There is an option to use a Docker repository, but currently this
is not supported by ECR. For now, using S3 as the cache target (another built-in option)
for service images, and GH Actions cache for builder image.
An issue has been opened to switch to the repo for the service images once it's supported.
Commented out running npm install when each project is installed. This appeared to be causing
issues where some packages, particularly semver, were not fully installed properly by the
end, leading to errors when those packages were referenced. There is now a single npm
install after installing all projects.
References
closes #insert number here
Checklist
QA Steps
List any additional steps required to QA the changes of this PR, as well as any supplemental images or videos.