Skip to content

Optimize Docker build to avoid rebuilding x86 layers twice #17

@missinglink

Description

@missinglink

The current build script builds x86 layers twice:

Once with docker build for -classic tags (single-arch for old Docker/k8s)
Again with docker buildx for multi-arch tags (amd64 + arm64)
This doubles the build time for x86 layers since buildx doesn't reuse the classic build's cache by default.

Solution

Add --cache-from flag to the docker buildx command to reuse layers from the classic build that was just pushed to the registry.

This way: x86 layers are built once (in classic build) buildx reuses those cached layers.
Only arm64 layers need to be built fresh

Implementation

Change build-docker-images.sh to include:
--cache-from="type=registry,ref=$FIRST_REGISTRY/$tag-classic"

This should significantly reduce build times, especially for large images.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions