@@ -8,32 +8,35 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
88
99WORKDIR /usr/src
1010
11+ # ----------------------------
12+ # LuaJIT
13+ # ----------------------------
1114RUN git clone --branch v2.1-agentzh --single-branch https://github.com/openresty/luajit2.git
1215WORKDIR /usr/src/luajit2
1316RUN make -j"$(nproc)" && make install
1417
1518ENV LUAJIT_LIB=/usr/local/lib
1619ENV LUAJIT_INC=/usr/local/include/luajit-2.1
1720
21+ # ----------------------------
22+ # lua-cjson (cjson.so + cjson/safe.lua)
23+ # ----------------------------
1824ARG LUA_CJSON_V=2.1.0.10
1925WORKDIR /usr/src
2026RUN git clone --branch "${LUA_CJSON_V}" --single-branch https://github.com/openresty/lua-cjson.git
2127WORKDIR /usr/src/lua-cjson
2228RUN make -j"$(nproc)" LUA_INCLUDE_DIR="${LUAJIT_INC}" \
2329 && make install LUA_INCLUDE_DIR="${LUAJIT_INC}" LUA_LIB_DIR="${LUAJIT_LIB}"
24- RUN install -d /usr/local/share/lua/5.1/cjson \
25- && cp -v /usr/src/lua-cjson/lua/cjson/*.lua /usr/local/share/lua/5.1/cjson/
2630
31+ # Copy Lua helpers if present (util.lua etc.), and always provide safe.lua
2732RUN set -eux; \
2833 install -d /usr/local/share/lua/5.1/cjson; \
2934 if [ -d /usr/src/lua-cjson/lua/cjson ]; then \
3035 find /usr/src/lua-cjson/lua/cjson -maxdepth 1 -type f -name '*.lua' -exec cp -v {} /usr/local/share/lua/5.1/cjson/ \;; \
3136 fi; \
3237 chmod 0644 /usr/local/share/lua/5.1/cjson/*.lua || true
3338
34- RUN set -eux; \
35- if [ ! -f /usr/local/share/lua/5.1/cjson/safe.lua ]; then \
36- cat > /usr/local/share/lua/5.1/cjson/safe.lua <<'EOF'
39+ RUN cat > /usr/local/share/lua/5.1/cjson/safe.lua <<'EOF'
3740local cjson = require "cjson"
3841
3942local _M = {}
5962
6063return _M
6164EOF
62- fi; \
63- chmod 0644 /usr/local/share/lua/5.1/cjson/safe.lua
6465
66+ RUN chmod 0644 /usr/local/share/lua/5.1/cjson/safe.lua
67+
68+ # ----------------------------
69+ # NDK + lua-nginx-module (dynamic)
70+ # ----------------------------
6571ARG NDK_V=v0.3.3
6672ARG LUA_NGX_V=v0.10.27
6773WORKDIR /usr/src
6874RUN git clone --branch "${NDK_V}" --single-branch https://github.com/simpl/ngx_devel_kit.git
6975RUN git clone --branch "${LUA_NGX_V}" --single-branch https://github.com/openresty/lua-nginx-module.git
7076
77+ # ----------------------------
78+ # Build NGINX dynamic modules with --with-compat
79+ # ----------------------------
7180ARG NGINX_V=1.27.4
7281RUN wget -O "nginx-${NGINX_V}.tar.gz" "http://nginx.org/download/nginx-${NGINX_V}.tar.gz" \
7382 && tar zxf "nginx-${NGINX_V}.tar.gz"
7483
7584WORKDIR /usr/src/nginx-${NGINX_V}
76-
7785RUN ./configure --with-compat \
7886 --add-dynamic-module=../ngx_devel_kit \
7987 --add-dynamic-module=../lua-nginx-module \
8088 --with-ld-opt="-Wl,-rpath,/usr/local/lib"
8189RUN make modules -j"$(nproc)"
8290
91+ # ----------------------------
92+ # Smoke test: ensure cjson.safe is loadable by LuaJIT
93+ # ----------------------------
8394RUN /usr/local/bin/luajit -e 'local x=require("cjson.safe"); assert(x and x.encode and x.decode); print("cjson.safe OK")'
8495
96+ # ----------------------------
97+ # Export artifacts
98+ # ----------------------------
8599FROM scratch AS out
86100COPY --from=build /usr/src/nginx-1.27.4/objs/ndk_http_module.so /ndk_http_module.so
87101COPY --from=build /usr/src/nginx-1.27.4/objs/ngx_http_lua_module.so /ngx_http_lua_module.so
88102COPY --from=build /usr/local/lib/libluajit-5.1.so.2 /libluajit-5.1.so.2
89103COPY --from=build /usr/local/lib/lua/5.1/cjson.so /usr/local/lib/lua/5.1/cjson.so
90104COPY --from=build /usr/local/share/lua/5.1/cjson /usr/local/share/lua/5.1/cjson
91-
0 commit comments