Skip to content

Conversation

@sihyeonn
Copy link

Description

Optimize the debian-dev Dockerfile to leverage Docker layer caching more effectively.
Previously, any code change would invalidate the cache and trigger a full rebuild including make deps and brotli compilation.

What this PR does:

  1. Separate dependency files from source code: Copy only Makefile, rockspec, .requirements, and install-dependencies.sh before running make deps, so dependencies are cached unless these files change.

  2. Move brotli build to build stage: Previously, brotli was built in the runtime stage, requiring installation of ~80 build packages (gcc, cmake, etc.) every time. Now it's built once in the build stage and only the binary is copied to runtime.

Performance improvement:

Scenario Before After Improvement
Source code change only 4m 37s 18s ~15x faster

Which issue(s) this PR fixes:

Fixes #

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. performance generate flamegraph for the current PR labels Dec 12, 2025
@sihyeonn sihyeonn force-pushed the feat/sh-improve-dockerfile branch from a9c6280 to 7d03549 Compare December 12, 2025 00:12
Optimize Docker layer caching to significantly reduce rebuild time
when only source code changes:

- Separate dependency installation from source code copy
- Build brotli in build stage instead of runtime stage
- Copy only dependency-related files before running make deps

Signed-off-by: Sihyeon Jang <sihyeon.jang@navercorp.com>
@sihyeonn sihyeonn force-pushed the feat/sh-improve-dockerfile branch from 7d03549 to ed1042a Compare December 12, 2025 00:26
Copy link
Contributor

@Baoyuantop Baoyuantop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a significant change in the size of the image?

COPY ${INSTALL_BROTLI} /install-brotli.sh
RUN chmod +x /install-brotli.sh \
&& cd / && ./install-brotli.sh && rm -rf /install-brotli.sh
RUN echo /usr/local/brotli/lib | tee /etc/ld.so.conf.d/brotli.conf \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note the handling of the lib64 directory in the original install-brotli.sh script. https://github.com/apache/apisix/blob/master/docker/debian-dev/install-brotli.sh#L28-L32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance generate flamegraph for the current PR size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants