feat(apisix): add Cloudron package

- Implements Apache APISIX packaging for Cloudron platform.
- Includes Dockerfile, CloudronManifest.json, and start.sh.
- Configured to use Cloudron's etcd addon.

🤖 Generated with Gemini CLI
Co-Authored-By: Gemini <noreply@google.com>
This commit is contained in:
2025-09-04 09:42:47 -05:00
parent f7bae09f22
commit 54cc5f7308
1608 changed files with 388342 additions and 0 deletions

View File

@@ -0,0 +1,218 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
use t::APISIX 'no_plan';
repeat_each(1);
no_long_string();
no_root_location();
log_level("info");
$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
add_block_preprocessor(sub {
my ($block) = @_;
if (!$block->request) {
$block->set_value("request", "GET /t");
}
});
run_tests;
__DATA__
=== TEST 1: flatten send args
--- extra_init_by_lua
local sock = ngx.socket.tcp()
getmetatable(sock.sock).__index.send = function (_, data)
ngx.log(ngx.WARN, data)
return #data
end
sock:send({1, "a", {1, "b", true}})
sock:send(1, "a", {1, "b", false})
--- config
location /t {
return 200;
}
--- grep_error_log eval
qr/send\(\): \S+/
--- grep_error_log_out
send(): 1a1btrue
send(): 1a1bfalse
=== TEST 2: sslhandshake options
--- extra_init_by_lua
local sock = ngx.socket.tcp()
sock:settimeout(1)
local ok, err = sock:connect("0.0.0.0", 12379)
if not ok then
ngx.log(ngx.ERR, "failed to connect: ", err)
return
end
local sess, err = sock:sslhandshake(true, "test.com", true, true)
if not sess then
ngx.log(ngx.ERR, "failed to do SSL handshake: ", err)
end
local sock = ngx.socket.tcp()
local ok, err = sock:connect("0.0.0.0", 12379)
if not ok then
ngx.log(ngx.ERR, "failed to connect: ", err)
return
end
local sess, err = sock:sslhandshake(true, "test.com", nil, true)
if not sess then
ngx.log(ngx.ERR, "failed to do SSL handshake: ", err)
end
sock:setkeepalive()
--- config
location /t {
return 200;
}
--- grep_error_log eval
qr/failed to do SSL handshake/
--- grep_error_log_out
failed to do SSL handshake
--- error_log
reused_session is not supported yet
send_status_req is not supported yet
=== TEST 3: unix socket
--- http_config
server {
listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
}
--- extra_init_worker_by_lua
local sock = ngx.socket.tcp()
sock:settimeout(1)
local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
if not ok then
ngx.log(ngx.ERR, "failed to connect: ", err)
return
end
local ok, err = sock:receive()
if not ok then
ngx.log(ngx.ERR, "failed to read: ", err)
return
end
--- config
location /t {
return 200;
}
--- error_log
failed to read: timeout
=== TEST 4: resolve host by ourselves
--- yaml_config
apisix:
node_listen: 1984
enable_resolv_search_opt: true
--- config
location /t {
content_by_lua_block {
local http = require("resty.http")
local httpc = http.new()
local res, err = httpc:request_uri("http://apisix", {headers={Host="apisix.apache.org"}})
if not res then
ngx.log(ngx.ERR, err)
return
end
ngx.say("ok")
}
}
--- response_body
ok
=== TEST 5: resolve host by ourselves (in stream sub-system)
--- yaml_config
apisix:
node_listen: 1984
enable_resolv_search_opt: true
--- stream_enable
--- stream_server_config
content_by_lua_block {
local sock = ngx.req.socket(true)
-- drain the buffer
local _, err = sock:receive(1)
if err ~= nil then
ngx.log(ngx.ERR, err)
return ngx.exit(-1)
end
local http = require("resty.http")
local httpc = http.new()
local res, err = httpc:request_uri("http://apisix", {headers={Host="apisix.apache.org"}})
if not res then
ngx.log(ngx.ERR, err)
return ngx.exit(-1)
end
sock:send("ok")
}
--- stream_request eval
m
--- stream_response: ok
=== TEST 6: resolve host by ourselves (UDP)
--- yaml_config
apisix:
node_listen: 1984
enable_resolv_search_opt: true
--- config
location /t {
content_by_lua_block {
local sock = ngx.socket.udp()
local res, err = sock:setpeername("apisix", 80)
if not res then
ngx.log(ngx.ERR, err)
end
}
}
=== TEST 7: ensure our patch works with unix socket
--- stream_server_config
content_by_lua_block {
}
--- stream_config
server {
listen unix:$TEST_NGINX_HTML_DIR/nginx.sock;
content_by_lua_block {
}
}
--- config
location /t {
content_by_lua_block {
local sock = ngx.socket.udp()
local res, err = sock:setpeername("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
if not res then
ngx.log(ngx.ERR, err)
end
}
}

View File

@@ -0,0 +1,325 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
use t::APISIX 'no_plan';
repeat_each(1);
no_long_string();
no_root_location();
log_level("info");
$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
add_block_preprocessor(sub {
my ($block) = @_;
if (!$block->request) {
$block->set_value("request", "GET /t");
}
});
run_tests;
__DATA__
=== TEST 1: invalid pre_function
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"methods": ["GET"],
"plugins": {
"limit-count": {
"count": 2,
"time_window": 60,
"rejected_code": 503,
"key": "remote_addr",
"_meta": {
"pre_function": "not a function"
}
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/hello"
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.print(body)
}
}
--- error_code: 400
--- response_body
{"error_msg":"failed to load _meta.pre_function in plugin limit-count: [string \"meta pre_function\"]:1: unexpected symbol near 'not'"}
=== TEST 2: attempt setting pre_function in _meta with a typo in `pre_function`
# this is to test the case where user (or CP) would attempt configuring pre_function
# using incorrect field name, this validation is achieved by setting `additionalProperties = false`
# in schema_def.lua
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"methods": ["GET"],
"plugins": {
"limit-count": {
"count": 2,
"time_window": 60,
"rejected_code": 503,
"key": "remote_addr",
"_meta": {
"prefunction": "not a function"
}
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/hello"
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.print(body)
}
}
--- error_code: 400
--- response_body
{"error_msg":"failed to check the configuration of plugin limit-count err: property \"_meta\" validation failed: additional properties forbidden, found prefunction"}
=== TEST 3: pre_function with error in code
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"methods": ["GET"],
"plugins": {
"limit-count": {
"count": 2,
"time_window": 60,
"rejected_code": 503,
"key": "remote_addr",
"_meta": {
"pre_function": "return function() print(invalid.index) end"
}
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/hello"
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- error_code: 200
--- response_body
passed
=== TEST 4: sending request will execute erroneous code and print error log
--- request
GET /hello
--- error_log
pre_function execution for plugin limit-count failed: [string "meta pre_function"]:1: attempt to index global 'invalid' (a nil value),
=== TEST 5: test pre_function sanity: correct function
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"methods": ["GET"],
"plugins": {
"limit-count": {
"count": 2,
"time_window": 60,
"rejected_code": 503,
"key": "remote_addr",
"_meta": {
"pre_function": "return function(conf, ctx) ngx.log(ngx.WARN, 'hello ', ngx.req.get_headers()[\"User-Agent\"]) end"
}
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/hello"
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- error_code: 200
--- response_body
passed
=== TEST 6: request
--- request
GET /hello
--- more_headers
User-Agent: test-nginx
--- error_log
hello test-nginx
=== TEST 7: pre_function is executed in all phases
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"plugins": {
"example-plugin": {
"i": 11,
"_meta": {
"pre_function": "return function(conf, ctx) ngx.log(ngx.WARN, 'hello: ', ngx.get_phase()) end"
}
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/hello"
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- error_code: 200
--- response_body
passed
=== TEST 8: request
--- request
GET /hello
--- error_log
hello: access
hello: header_filter
hello: body_filter
hello: log
=== TEST 9: test pre-function with proxy-rewrite, (rewrite phase)
--- config
location /t {
content_by_lua_block {
local t = require("lib.test_admin").test
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
[[{
"plugins": {
"proxy-rewrite": {
"uri": "/uri",
"headers": {
"x-api": "$example_var_name"
},
"_meta": {
"pre_function": "return function(conf, ctx) local core = require \"apisix.core\" core.ctx.register_var(\"example_var_name\", function(ctx) return \"example_var_value\" end) end"
}
}
},
"upstream": {
"nodes": {
"127.0.0.1:1980": 1
},
"type": "roundrobin"
},
"uri": "/hello"
}]]
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- request
GET /t
--- response_body
passed
=== TEST 10: hit route(header supports nginx variables)
--- request
GET /hello
--- response_body
uri: /uri
host: localhost
x-api: example_var_value
x-real-ip: 127.0.0.1

View File

@@ -0,0 +1,54 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
use t::APISIX 'no_plan';
repeat_each(1);
no_long_string();
no_root_location();
add_block_preprocessor(sub {
my ($block) = @_;
if (!$block->request) {
$block->set_value("request", "GET /t");
}
});
run_tests;
__DATA__
=== TEST 1: always start a new timer even the previous one is blocked
--- config
location /t {
content_by_lua_block {
local timers = require("apisix.timers")
timers.register_timer("t", function()
ngx.log(ngx.WARN, "fire")
end)
timers.register_timer("c", function()
ngx.sleep(5)
end)
ngx.sleep(2.1)
}
}
--- grep_error_log eval
qr/fire/
--- grep_error_log_out
fire
fire