hashgraph / hedera-sourcify

Tools for verifying Hedera smart contracts using standard open source libraries.
Apache License 2.0
6 stars 7 forks source link

build: setup cache to build images in CI #204

Closed acuarica closed 3 months ago

acuarica commented 3 months ago

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