AI Briefing
KO

Fixing Docker Build Cache Issues in GitHub Actions: How to Use build-push-action

·2022.04.14 09:00

Key point

Resolved the clean environment issue on GitHub Actions runners using the type=gha option in docker/build-push-action.

1 / 8

Details

Kakao Webtoon used GitHub Actions for Amazon ECR deployments but faced an issue where build times did not decrease even without changes. This is because GitHub Actions runners execute in a new virtual environment every time, preventing the reuse of existing Docker layer caches.

Root Cause: Clean Environment and Lack of Cache

Locally, rebuilding the same code leverages Docker cache, reducing build time from 53 seconds to 1.2 seconds. However, in GitHub Actions, every step, such as npm install, is re-executed. The default caching features provided by GitHub do not cover Docker layers, leading to inefficiencies in the CI pipeline.

Solution: Utilizing docker/build-push-action

By using the official Docker action docker/build-push-action and BuildKit, you can directly utilize the GitHub Actions cache API. Setting cache-from: type=gha and cache-to: type=gha, mode=max in the workflow caches build results in the GitHub repository for reuse in subsequent runs.

Effects and Caveats

After implementation, build time was reduced by approximately 1 minute when redeploying the same code. Performance improved particularly because the time-consuming RUN npm install step was cached. However, since the type=gha method is still experimental, it can be effectively utilized in large-scale projects with frequent repetitive tasks.

This summary was generated automatically by AI. Check the original for the author's claims and context. Copyright belongs to the original author.

Our guide explains how the AI works. Report summary errors, attribution issues, or removal requests via Contact.