Skip to content

Commit c7328cb

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 <[email protected]>
1 parent 9b3c3d3 commit c7328cb

File tree

2 files changed

+50
-29
lines changed

2 files changed

+50
-29
lines changed

debian-dev/Dockerfile

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ 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+
ARG INSTALL_BROTLI=./install-brotli.sh
25+
26+
# Install build dependencies
2427
RUN set -x \
2528
&& (test "${ENABLE_PROXY}" != "true" || /bin/sed -i 's,http://deb.debian.org,https://mirrors.aliyun.com,g' /etc/apt/sources.list) \
2629
&& apt-get -y update --fix-missing \
@@ -35,14 +38,20 @@ RUN set -x \
3538
unzip \
3639
wget \
3740
libyaml-dev \
38-
&& curl https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh -sL | bash - \
41+
cmake
42+
43+
# Install luarocks and apisix
44+
RUN curl https://raw.githubusercontent.com/apache/apisix/master/utils/linux-install-luarocks.sh -sL | bash - \
3945
&& luarocks install https://raw.githubusercontent.com/apache/apisix/master/apisix-master-0.rockspec --tree=/usr/local/apisix/deps PCRE_DIR=/usr/local/openresty/pcre \
4046
&& cp -v /usr/local/apisix/deps/lib/luarocks/rocks-5.1/apisix/master-0/bin/apisix /usr/bin/ \
4147
&& mv /usr/local/apisix/deps/share/lua/5.1/apisix /usr/local/apisix \
4248
# forward request and error logs to docker log collector
4349
&& ln -sf /dev/stdout /usr/local/apisix/logs/access.log \
4450
&& ln -sf /dev/stderr /usr/local/apisix/logs/error.log
4551

52+
COPY ${INSTALL_BROTLI} /install-brotli.sh
53+
RUN chmod +x /install-brotli.sh && /install-brotli.sh
54+
4655
FROM api7/apisix-runtime:dev AS production-stage
4756

4857
# Install the runtime libyaml package
@@ -52,16 +61,11 @@ RUN apt-get -y update --fix-missing \
5261

5362
COPY --from=build /usr/local/apisix /usr/local/apisix
5463
COPY --from=build /usr/bin/apisix /usr/bin/apisix
64+
COPY --from=build /usr/local/brotli /usr/local/brotli
5565

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-
62-
COPY ./install-brotli.sh /install-brotli.sh
63-
RUN chmod +x /install-brotli.sh \
64-
&& cd / && ./install-brotli.sh && rm -rf /install-brotli.sh
66+
RUN echo /usr/local/brotli/lib | tee /etc/ld.so.conf.d/brotli.conf \
67+
&& ldconfig \
68+
&& ln -sf /usr/local/brotli/bin/brotli /usr/bin/brotli
6569

6670
WORKDIR /usr/local/apisix
6771

@@ -71,10 +75,10 @@ EXPOSE 9080 9443
7175

7276
COPY ./docker-entrypoint.sh /docker-entrypoint.sh
7377
COPY ./check_standalone_config.sh /check_standalone_config.sh
78+
RUN chmod +x /docker-entrypoint.sh /check_standalone_config.sh
7479

7580
ENTRYPOINT ["/docker-entrypoint.sh"]
7681

7782
CMD ["docker-start"]
7883

79-
8084
STOPSIGNAL SIGQUIT

debian-dev/Dockerfile.local

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,47 +14,63 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
#
17-
18-
# Use this dockerfile to create a docker image of your apisix local/patched codebase
19-
2017
FROM debian:bullseye-slim AS build
2118

2219
ARG ENABLE_PROXY=false
2320
ARG CODE_PATH
2421

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

3025
WORKDIR /apisix
3126

27+
ARG INSTALL_BROTLI=./install-brotli.sh
28+
3229
RUN set -x \
3330
&& apt-get -y update --fix-missing \
3431
&& apt-get install -y \
3532
make \
3633
git \
3734
sudo \
3835
libyaml-dev \
39-
&& ls -al \
40-
&& make deps \
36+
cmake \
37+
wget \
38+
unzip
39+
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+
RUN make deps \
4144
&& mkdir -p ${ENV_INST_LUADIR} \
42-
&& cp -r deps ${ENV_INST_LUADIR} \
43-
&& make install
45+
&& cp -r deps ${ENV_INST_LUADIR}
46+
47+
COPY ${INSTALL_BROTLI} /install-brotli.sh
48+
RUN chmod +x /install-brotli.sh && /install-brotli.sh
49+
50+
COPY ${CODE_PATH} /apisix
51+
52+
RUN make install
4453

4554
FROM debian:bullseye-slim
4655

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

5065
COPY --from=build /usr/local/apisix /usr/local/apisix
5166
COPY --from=build /usr/local/openresty /usr/local/openresty
5267
COPY --from=build /usr/bin/apisix /usr/bin/apisix
53-
COPY --from=build /usr/lib/x86_64-linux-gnu/libyaml* /usr/local/lib/
68+
COPY --from=build /usr/local/brotli /usr/local/brotli
69+
COPY --chown=nobody:root ui/ /usr/local/apisix/ui/
5470

55-
COPY ${INSTALL_BROTLI} /install-brotli.sh
56-
RUN chmod +x /install-brotli.sh \
57-
&& cd / && ./install-brotli.sh && rm -rf /install-brotli.sh
71+
RUN echo /usr/local/brotli/lib | tee /etc/ld.so.conf.d/brotli.conf \
72+
&& ldconfig \
73+
&& ln -sf /usr/local/brotli/bin/brotli /usr/bin/brotli
5874

5975
ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin
6076

@@ -66,7 +82,8 @@ RUN ln -sf /dev/stdout /usr/local/apisix/logs/access.log \
6682
EXPOSE 9080 9443
6783

6884
COPY ${ENTRYPOINT_PATH} /docker-entrypoint.sh
69-
COPY ../utils/check_standalone_config.sh /check_standalone_config.sh
85+
COPY ${CHECK_STANDALONE_CONFIG} /check_standalone_config.sh
86+
RUN chmod +x /docker-entrypoint.sh /check_standalone_config.sh
7087

7188
ENTRYPOINT ["/docker-entrypoint.sh"]
7289

0 commit comments

Comments
 (0)