From 275a43fc18712a458b624f8efbb8b3f29ccdf6ca Mon Sep 17 00:00:00 2001 From: CyberL1 Date: Fri, 10 Jan 2025 06:54:47 -0500 Subject: [PATCH] feat(proxy): use lua http module --- compose.yml | 4 ++-- proxy/Dockerfile | 5 +++++ proxy.conf => proxy/proxy.conf.template | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 proxy/Dockerfile rename proxy.conf => proxy/proxy.conf.template (73%) diff --git a/compose.yml b/compose.yml index d2125b2..a645d78 100644 --- a/compose.yml +++ b/compose.yml @@ -8,11 +8,11 @@ services: volumes: - /var/run/docker.sock:/var/run/docker.sock:ro proxy: - image: openresty/openresty:alpine-fat + build: proxy env_file: .env ports: - 80:80 volumes: - - ./proxy.conf:/etc/nginx/conf.d/proxy.conf.template + - ./proxy/proxy.conf.template:/etc/nginx/conf.d/proxy.conf.template network_mode: host command: /bin/sh -c "sed 's/{PROXY_DOMAIN}/$PROXY_DOMAIN/' /etc/nginx/conf.d/proxy.conf.template > /etc/nginx/conf.d/proxy.conf && nginx -g 'daemon off;'" diff --git a/proxy/Dockerfile b/proxy/Dockerfile new file mode 100644 index 0000000..a0f8e37 --- /dev/null +++ b/proxy/Dockerfile @@ -0,0 +1,5 @@ +FROM openresty/openresty:alpine + +RUN wget -O /usr/local/openresty/lualib/resty/http.lua https://github.com/ledgetech/lua-resty-http/raw/refs/heads/master/lib/resty/http.lua +RUN wget -O /usr/local/openresty/lualib/resty/http_connect.lua https://github.com/ledgetech/lua-resty-http/raw/refs/heads/master/lib/resty/http_connect.lua +RUN wget -O /usr/local/openresty/lualib/resty/http_headers.lua https://github.com/ledgetech/lua-resty-http/raw/refs/heads/master/lib/resty/http_headers.lua diff --git a/proxy.conf b/proxy/proxy.conf.template similarity index 73% rename from proxy.conf rename to proxy/proxy.conf.template index 0e40932..d3cd4d2 100644 --- a/proxy.conf +++ b/proxy/proxy.conf.template @@ -22,10 +22,10 @@ server { set $ip ''; rewrite_by_lua_block { - local shell = require("resty.shell") + local http = require("resty.http").new() - local ok, stdout, strerr, reason, status = shell.run("curl http://127.0.0.1:3000/containers/" .. ngx.var.container .. "/ip") - ngx.var.ip = stdout + local res, err = http:request_uri("http://127.0.0.1:3000/containers/" .. ngx.var.container .. "/ip") + ngx.var.ip = res.body } proxy_pass http://$ip:$port;