automata-network / automata

Automata Network is a modular attestation layer that extends machine trust to Ethereum with TEE Coprocessors.
https://ata.network
Apache License 2.0
94 stars 19 forks source link

Speed up CI docker build #11

Closed Gnnng closed 3 years ago

Gnnng commented 3 years ago

Previously, the CI docker build takes over 50 minutes because of the limited hardware resources from the official runner spec: 2-core CPU, 7 GB of RAM memory.

This pull request takes advantage of --mount=type=cache to cache the sccache directory (dominant) and cargo registry directories during the builder stage. (cargo target folder is not cached due to large size).

https://github.com/automata-network/automata/blob/6ca74d3a0d134d24c8e0f4974a2ff5459900da00/Dockerfile#L31-L36

The above strategy works fine on local machine where the buildx builder is reused and the cached content from --mount=type=cache can be reused across different builds. (See scripts/docker-build.sh).

In CI environment like Github Action, the buildx builder is recreated every time so some workaround is needed in order to persist the cached content from --mount=type=cache different workflow runs.

Restore https://github.com/automata-network/automata/blob/6ca74d3a0d134d24c8e0f4974a2ff5459900da00/.github/workflows/docker.yaml#L47-L57

Backup https://github.com/automata-network/automata/blob/6ca74d3a0d134d24c8e0f4974a2ff5459900da00/.github/workflows/docker.yaml#L80-L98

As a result, now the CI docker build takes around 23 minutes to complete when most of the cache is valid. If there's some major code change, the time spent should be in the range of 23 to 50 minutes.

Other fixes