autowarefoundation / autoware

Autoware - the world's leading open-source software project for autonomous driving
https://www.autoware.org/
Apache License 2.0
9k stars 3.01k forks source link

feat(ci): save cache on `build-main` workflows and only restore cache on `docker-build-and-push-main` workflows #4865

Closed youtalk closed 3 months ago

youtalk commented 3 months ago

Description

The reproducible-containers/buildkit-cache-dance action introduced in https://github.com/autowarefoundation/autoware/pull/4854, unfortunately, might not support extracting the cache from the docker buildx bake and only supports docker build.

I confirmed that replacing docker/bake-action with docker/build-and-push-action as per the official sample code does indeed enable the cache to work. https://github.com/reproducible-containers/buildkit-cache-dance?tab=readme-ov-file#examples

Therefore, in this PR, we will create a cache by running docker/build-and-push-action in the build-main and build-main-self-hosted workflows, which are scheduled to run daily, and in the sequentially executed docker-build-and-push-main and docker-build-and-push-main-self-hosted workflows, we will run docker/bake-action as in the past and only load the cache.

It turns out that the cache was effective in https://github.com/autowarefoundation/autoware/pull/4854 because I forgot to delete the cache from the commit during my experiment, which caused the cache to be effective. I apologize for the oversight.

Tests performed

Using this commit to temporarily run the build-main workflows in this PR, we confirmed that the execution time from the second run onwards was drastically reduced from the previous 2.5 hours to 1 hour.

https://autowarefoundation.github.io/autoware-ci-metrics/

Screenshot 2024-06-14 at 8 49 33

Effects on system behavior

Not applicable.

Interface changes

Pre-review checklist for the PR author

The PR author must check the checkboxes below when creating the PR.

In-review checklist for the PR reviewers

The PR reviewers must check the checkboxes below before approval.

Post-review checklist for the PR author

The PR author must check the checkboxes below before merging.

After all checkboxes are checked, anyone who has write access can merge the PR.

youtalk commented 3 months ago

The workflow namings are unclear, so I would like to refactor and rename them in another PR. ref. https://github.com/autowarefoundation/autoware/pull/4747

youtalk commented 3 months ago

Unfortunately, this PR still has an issue where the docker-build-and-push-main workflows cannot restore the cache, even though a fully matching cache is already available. However, since this issue can be resolved in a separate PR, we would like to consider this PR is ready for review for now.

Cache not found for input keys: cache-amd64-cuda-0187c3f0f9a23c6232cfe50f211e9deee563e665bcd440c1d921e03bb67898cc, cache-amd64-cuda-, cache-amd64-

https://github.com/autowarefoundation/autoware/actions/runs/9500467708/job/26183604143#step:6:13

Screenshot 2024-06-14 at 9 16 55

https://github.com/autowarefoundation/autoware/actions/caches

xmfcx commented 3 months ago

Unfortunately, this PR still has an issue where thedocker-build-and-push-main workflows cannot restore the cache, even though a fully matching cache is already available. However, since this issue can be resolved in a separate PR, we would like to consider this PR is ready for review for now.

This is happens because the workflow trigger of schedule isolates the cache. Only scheduled build-main can get the cache of another scheduled build-main job, nothing else. I guess not even workflow_dispatch event can reach it.

See: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache

For this to work as intended, docker-build-and-push-main should maintain its own cache.

Also

Reasons:

The reason for -${{ github.sha }} is to know where the cache was created from.

restore-keys: |
  ccache-build-main-${{ runner.arch }}-humble-

Will fetch the most fresh version anyways. As long as it is unique, it will be enough.

@youtalk -san, I know you are busy this week and I would like to implement all I've mentioned until wednesday, is that OK?

youtalk commented 3 months ago

@xmfcx It's my pleasure! Please go ahead.