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).
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.
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
add new badge for Docker workflow in README.
address the issue where latest image is not pushed when main branch is updated.
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 thebuilder
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. (Seescripts/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
latest
image is not pushed whenmain
branch is updated.