Optimize dockerfile: Multi segment construction is adopted to reduce the output image size
@@ -6,13 +6,8 @@ RUN apt-get update && \
apt-get -yq --no-install-recommends install \
curl ca-certificates libhyperscan-dev \
gcc pkg-config libssl-dev python2.7 clang-10 libclang1-10 \
- redis-server gcc libluajit-5.1-dev make \
- unzip git redis-server luajit luarocks
+ gcc libluajit-5.1-dev make unzip git luajit
RUN ln -s /usr/bin/python2.7 /usr/bin/python2 && mkdir /build
-RUN luarocks install lua-cjson && \
- luarocks install luafilesystem && \
- luarocks install luasocket && \
- luarocks install redis-lua
COPY curieproxy/rust /build/rust
WORKDIR /build/rust
ENV PATH="/root/.cargo/bin:${PATH}"
@@ -22,9 +17,21 @@ RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \
cp target/release/libcuriefense_lua.so /root/curiefense.so && \
rm -rf target /root/.cargo
-RUN cp /root/curiefense.so /usr/local/lib/lua/5.1/curiefense.so
+FROM ubuntu:${UBUNTU_VERSION} as tester
+RUN apt-get update && \
+ apt-get -yq --no-install-recommends install redis-server luarocks \
+ luajit gcc libssl-dev libhyperscan[45] && \
+ luarocks install lua-cjson && \
+ luarocks install luafilesystem && \
+ luarocks install luasocket && \
+ luarocks install redis-lua && \
+ apt-get remove -y jq luarocks gcc &&\
+ apt-get autoremove -y &&\
+ rm -rf /var/lib/apt/lists/*
+
+COPY --from=builder /root/curiefense.so /usr/local/lib/lua/5.1/curiefense.so
COPY curieproxy/lua/shared-objects/grasshopper.so /usr/local/lib/lua/5.1/grasshopper.so
-RUN mkdir -p /cf-config/current
+RUN ln -s /usr/local/lib/lua/5.1/curiefense.so /root/curiefense.so && mkdir -p /cf-config/current
COPY confdb-initial-data/master/config /cf-config/current/config
COPY curieproxy/rust/luatests/config/json /cf-config/current/config/json
@@ -36,3 +43,6 @@ COPY curieproxy/rust/luatests/test.lua /home/builder/test.lua
COPY curieproxy/rust/luatests /home/builder/luatests
WORKDIR /home/builder
RUN sh luatests/run.sh
+
+FROM scratch
+COPY --from=builder /root/curiefense.so /root/curiefense.so
\ No newline at end of file
