Use luarocks to manage Lua dependencies

This commit is contained in:
Elvin Efendi 2023-02-08 20:37:11 -05:00
parent 7db4b95e19
commit 891d07ea12
4 changed files with 73 additions and 10 deletions

View file

@ -126,9 +126,6 @@ export LUA_RESTY_REDIS_VERSION=0.30
# Check for recent changes: https://github.com/api7/lua-resty-ipmatcher/compare/v0.6.1...master
export LUA_RESTY_IPMATCHER_VERSION=0.6.1
# Check for recent changes: https://github.com/ElvinEfendi/lua-resty-global-throttle/compare/v0.2.0...main
export LUA_RESTY_GLOBAL_THROTTLE_VERSION=0.2.0
# Check for recent changes: https://github.com/microsoft/mimalloc/compare/v1.7.6...master
export MIMALOC_VERSION=1.7.6
@ -323,9 +320,6 @@ get_src c15aed1a01c88a3a6387d9af67a957dff670357f5fdb4ee182beb44635eef3f1 \
get_src efb767487ea3f6031577b9b224467ddbda2ad51a41c5867a47582d4ad85d609e \
"https://github.com/api7/lua-resty-ipmatcher/archive/v$LUA_RESTY_IPMATCHER_VERSION.tar.gz"
get_src 0fb790e394510e73fdba1492e576aaec0b8ee9ef08e3e821ce253a07719cf7ea \
"https://github.com/ElvinEfendi/lua-resty-global-throttle/archive/v$LUA_RESTY_GLOBAL_THROTTLE_VERSION.tar.gz"
get_src d74f86ada2329016068bc5a243268f1f555edd620b6a7d6ce89295e7d6cf18da \
"https://github.com/microsoft/mimalloc/archive/refs/tags/v${MIMALOC_VERSION}.tar.gz"
@ -721,9 +715,6 @@ make install
cd "$BUILD_PATH/lua-resty-ipmatcher-$LUA_RESTY_IPMATCHER_VERSION"
INST_LUADIR=/usr/local/lib/lua make install
cd "$BUILD_PATH/lua-resty-global-throttle-$LUA_RESTY_GLOBAL_THROTTLE_VERSION"
make install
cd "$BUILD_PATH/mimalloc-$MIMALOC_VERSION"
mkdir -p out/release
cd out/release

View file

@ -14,6 +14,25 @@
ARG BASE_IMAGE
# Prepare Lua files and their dependencies.
FROM ${BASE_IMAGE} as lua_builder
RUN apk add \
make \
wget \
git
RUN curl -sSL -o /tmp/luarocks.tar.gz https://github.com/luarocks/luarocks/archive/refs/tags/v3.9.2.tar.gz \
&& echo "a0b36cd68586cd79966d0106bb2e5a4f5523327867995fd66bee4237062b3e3b */tmp/luarocks.tar.gz" | sha256sum -c - \
&& tar -C /tmp -xzf /tmp/luarocks.tar.gz \
&& cd /tmp/luarocks* \
&& ./configure \
&& make \
&& make install
COPY etc/nginx/lua /lua
WORKDIR /lua
RUN luarocks make --local --tree /luarocks ingress-nginx-lua-main-1.rockspec
# Build the final image.
FROM ${BASE_IMAGE}
ARG TARGETARCH
@ -39,7 +58,11 @@ RUN apk update \
diffutils \
&& rm -rf /var/cache/apk/*
COPY --chown=www-data:www-data etc /etc
COPY --chown=www-data:www-data etc/nginx/template /etc/nginx/template
COPY --chown=www-data:www-data etc/nginx/nginx.conf /etc/nginx
COPY --chown=www-data:www-data etc/nginx/opentracing.json /etc/nginx
COPY --from=lua_builder --chown=www-data:www-data /luarocks/lib/luarocks/rocks-5.1/ingress-nginx-lua/main-1/ingress-nginx-lua /etc/nginx/lua
COPY --from=lua_builder --chown=www-data:www-data /luarocks/share/lua/5.1 /usr/local/lib/lua
COPY --chown=www-data:www-data bin/${TARGETARCH}/dbg /
COPY --chown=www-data:www-data bin/${TARGETARCH}/nginx-ingress-controller /

View file

@ -0,0 +1,17 @@
all:
@echo --- build
@echo CFLAGS: $(CFLAGS)
@echo LIBFLAG: $(LIBFLAG)
@echo LUA_LIBDIR: $(LUA_LIBDIR)
@echo LUA_BINDIR: $(LUA_BINDIR)
@echo LUA_INCDIR: $(LUA_INCDIR)
.PHONY: install
install:
@echo $(INST_PREFIX)
@echo $(INST_CONFDIR)
@echo INST_LIBDIR: $(INST_LIBDIR)
@echo INST_LUADIR: $(INST_LUADIR)
mkdir $(INST_PREFIX)/ingress-nginx-lua
cp -r . $(INST_PREFIX)/ingress-nginx-lua
rm -rf $(INST_PREFIX)/ingress-nginx-lua/test $(INST_PREFIX)/ingress-nginx-lua/Makefile $(INST_PREFIX)/ingress-nginx-lua/*.rockspec

View file

@ -0,0 +1,32 @@
package = "ingress-nginx-lua"
version = "main-1"
supported_platforms = {"linux", "macosx"}
source = {
url = "git+https://github.com/kubernetes/ingress-nginx.git"
}
description = {
summary = "Lua modules for ingress-nginx.",
homepage = "https://github.com/kubernetes/ingress-nginx",
license = "Apache License 2.0"
}
dependencies = {
"lua-resty-global-throttle >= 0.2"
}
build = {
type = "make",
build_variables = {
CFLAGS="$(CFLAGS)",
LIBFLAG="$(LIBFLAG)",
LUA_LIBDIR="$(LUA_LIBDIR)",
LUA_BINDIR="$(LUA_BINDIR)",
LUA_INCDIR="$(LUA_INCDIR)",
LUA="$(LUA)",
},
install_variables = {
INST_PREFIX="$(PREFIX)",
INST_BINDIR="$(BINDIR)",
INST_LIBDIR="$(LIBDIR)",
INST_LUADIR="$(LUADIR)",
INST_CONFDIR="$(CONFDIR)",
},
}