Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: setup cache to build images in CI #204

Merged
merged 8 commits into from
Jun 12, 2024

Conversation

acuarica
Copy link
Contributor

@acuarica acuarica commented Jun 12, 2024

Description:

This PR setups docker/build-push-action cache in the workflow to improve building images in CI.

After the cache is filled, most of the docker/build-push-action step output should look like

#43 [linux/amd64 production 11/12] RUN npm ci --workspace=sourcify-server --include-workspace-root --omit=dev
#43 CACHED

This reduces the workflow runtime from about an hour to a about minute when hitting the cache!

Note

Each docker/build-push-action step needs to setup its own scope to avoid overwriting its cache between steps. The docs here regarding scope are not clear about this behavior. However, the usage of scope for buildx here is more descriptive.

Important

To avoid any surprises regarding cache management, please be aware that GitHub's cache access restrictions still apply.

Workflow runs can restore caches created in either the current branch or the default branch (usually main). If a workflow run is triggered for a pull request, it can also restore caches created in the base branch, including base branches of forked repositories. For example, if the branch feature-b has the base branch feature-a, a workflow run triggered on a pull request would have access to caches created in the default main branch, the base feature-a branch, and the current feature-b branch.

But on the other hand

Workflow runs cannot restore caches created for child branches or sibling branches. For example, a cache created for the child feature-b branch would not be accessible to a workflow run triggered on the parent main branch.

You can inspect the branches a docker/build-push-action step has access to in the logs under GitHub Actions runtime token ACs group
image

Related issue(s):

Fixes #203.

Notes for reviewer:

This feature was implemented with several trials and errors to get these settings right. Each docker/build-push-action step was enabled one at a time to ensure the cache was filled successfully. In subsequent runs I could verify that the cache for a previous run was used.

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

Signed-off-by: Luis Mastrangelo <[email protected]>
@acuarica acuarica linked an issue Jun 12, 2024 that may be closed by this pull request
@acuarica acuarica marked this pull request as ready for review June 12, 2024 21:22
@acuarica acuarica requested review from a team as code owners June 12, 2024 21:22
@acuarica acuarica requested review from matteriben, rbarkerSL, quiet-node and Sheng-Long and removed request for a team June 12, 2024 21:22
@acuarica acuarica merged commit 43dbd8f into main Jun 12, 2024
12 checks passed
@acuarica acuarica deleted the 203-improve-image-building-in-ci branch June 12, 2024 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve image building in CI
2 participants