Skip to content

Commit e992a99

Browse files
committed
chore: optimize debian-dev Dockerfiles for better layer caching
- Separate build dependencies, brotli build, and apisix installation into distinct layers for improved caching - Copy dependency files (Makefile, rockspec, .requirements) before source code to cache deps layer on code changes - Remove duplicate apt-get installations in production stage Signed-off-by: Sihyeon Jang <sihyeon.jang@navercorp.com>
1 parent 9b3c3d3 commit e992a99

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

debian-dev/Dockerfile

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ FROM api7/apisix-runtime:dev AS build
1919

2020
ARG ENABLE_PROXY=false
2121

22-
ENV DEBIAN_FRONTEND noninteractive
22+
ENV DEBIAN_FRONTEND=noninteractive
2323

24+
# Install build dependencies
2425
RUN set -x \
2526
&& (test "${ENABLE_PROXY}" != "true" || /bin/sed -i 's,http://deb.debian.org,https://mirrors.aliyun.com,g' /etc/apt/sources.list) \
2627
&& apt-get -y update --fix-missing \
@@ -34,8 +35,10 @@ RUN set -x \
3435
sudo \
3536
unzip \
3637
wget \
37-
libyaml-dev \
38-
&& curl https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh -sL | bash - \
38+
libyaml-dev
39+
40+
# Install luarocks and apisix
41+
RUN curl https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh -sL | bash - \
3942
&& luarocks install https://raw.githubusercontent.com/apache/apisix/master/apisix-master-0.rockspec --tree=/usr/local/apisix/deps PCRE_DIR=/usr/local/openresty/pcre \
4043
&& cp -v /usr/local/apisix/deps/lib/luarocks/rocks-5.1/apisix/master-0/bin/apisix /usr/bin/ \
4144
&& mv /usr/local/apisix/deps/share/lua/5.1/apisix /usr/local/apisix \
@@ -53,14 +56,8 @@ RUN apt-get -y update --fix-missing \
5356
COPY --from=build /usr/local/apisix /usr/local/apisix
5457
COPY --from=build /usr/bin/apisix /usr/bin/apisix
5558

56-
ENV DEBIAN_FRONTEND noninteractive
57-
RUN apt-get -y update --fix-missing \
58-
&& apt-get install -y \
59-
libldap2-dev \
60-
&& apt-get remove --purge --auto-remove -y
61-
6259
COPY ./install-brotli.sh /install-brotli.sh
63-
RUN chmod +x /install-brotli.sh \
60+
RUN chmod +x /install-brotli.sh \
6461
&& cd / && ./install-brotli.sh && rm -rf /install-brotli.sh
6562

6663
WORKDIR /usr/local/apisix
@@ -76,5 +73,4 @@ ENTRYPOINT ["/docker-entrypoint.sh"]
7673

7774
CMD ["docker-start"]
7875

79-
8076
STOPSIGNAL SIGQUIT

debian-dev/Dockerfile.local

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,53 @@ FROM debian:bullseye-slim AS build
2222
ARG ENABLE_PROXY=false
2323
ARG CODE_PATH
2424

25-
ENV DEBIAN_FRONTEND noninteractive
26-
ENV ENV_INST_LUADIR /usr/local/apisix
27-
28-
COPY ${CODE_PATH} /apisix
25+
ENV DEBIAN_FRONTEND=noninteractive
26+
ENV ENV_INST_LUADIR=/usr/local/apisix
2927

3028
WORKDIR /apisix
3129

30+
# Install build dependencies
3231
RUN set -x \
3332
&& apt-get -y update --fix-missing \
3433
&& apt-get install -y \
3534
make \
3635
git \
3736
sudo \
38-
libyaml-dev \
39-
&& ls -al \
40-
&& make deps \
37+
libyaml-dev
38+
39+
# Copy only dependency-related files first for better layer caching
40+
COPY ${CODE_PATH}/Makefile ${CODE_PATH}/apisix-master-0.rockspec ${CODE_PATH}/.requirements /apisix/
41+
COPY ${CODE_PATH}/utils/install-dependencies.sh /apisix/utils/
42+
43+
# Install dependencies (cached unless rockspec/Makefile changes)
44+
RUN make deps \
4145
&& mkdir -p ${ENV_INST_LUADIR} \
42-
&& cp -r deps ${ENV_INST_LUADIR} \
43-
&& make install
46+
&& cp -r deps ${ENV_INST_LUADIR}
47+
48+
# Copy remaining source code
49+
COPY ${CODE_PATH} /apisix
50+
51+
# Install apisix
52+
RUN make install
4453

4554
FROM debian:bullseye-slim
4655

4756
ARG ENTRYPOINT_PATH=./docker-entrypoint.sh
4857
ARG INSTALL_BROTLI=./install-brotli.sh
58+
ARG CHECK_STANDALONE_CONFIG=./check_standalone_config.sh
59+
60+
# Install the runtime libyaml package
61+
RUN apt-get -y update --fix-missing \
62+
&& apt-get install -y libldap2-dev libyaml-0-2 \
63+
&& apt-get remove --purge --auto-remove -y \
64+
&& mkdir -p /usr/local/apisix/ui
4965

5066
COPY --from=build /usr/local/apisix /usr/local/apisix
5167
COPY --from=build /usr/local/openresty /usr/local/openresty
5268
COPY --from=build /usr/bin/apisix /usr/bin/apisix
53-
COPY --from=build /usr/lib/x86_64-linux-gnu/libyaml* /usr/local/lib/
5469

5570
COPY ${INSTALL_BROTLI} /install-brotli.sh
56-
RUN chmod +x /install-brotli.sh \
71+
RUN chmod +x /install-brotli.sh \
5772
&& cd / && ./install-brotli.sh && rm -rf /install-brotli.sh
5873

5974
ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin
@@ -66,7 +81,7 @@ RUN ln -sf /dev/stdout /usr/local/apisix/logs/access.log \
6681
EXPOSE 9080 9443
6782

6883
COPY ${ENTRYPOINT_PATH} /docker-entrypoint.sh
69-
COPY ../utils/check_standalone_config.sh /check_standalone_config.sh
84+
COPY ${CHECK_STANDALONE_CONFIG} /check_standalone_config.sh
7085

7186
ENTRYPOINT ["/docker-entrypoint.sh"]
7287

0 commit comments

Comments
 (0)