mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
Merge pull request #554 from bunkerity/dev
Merge "dev" branch into "staging" branch
This commit is contained in:
commit
c11b44285b
46 changed files with 1088 additions and 1003 deletions
7
.github/workflows/test-core.yml
vendored
7
.github/workflows/test-core.yml
vendored
|
|
@ -31,10 +31,15 @@ jobs:
|
|||
run: docker pull ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-tests:${{ inputs.RELEASE }} && docker tag ${{ secrets.PRIVATE_REGISTRY }}/infra/bunkerweb-tests:${{ inputs.RELEASE }} bunkerweb-tests
|
||||
- name: Pull Scheduler image
|
||||
run: docker pull ${{ secrets.PRIVATE_REGISTRY }}/infra/scheduler-tests:${{ inputs.RELEASE }} && docker tag ${{ secrets.PRIVATE_REGISTRY }}/infra/scheduler-tests:${{ inputs.RELEASE }} scheduler-tests
|
||||
# Temp fix "is not connected to the network" until compose v2.19.1 is available
|
||||
- name: Downgrade compose
|
||||
run: |
|
||||
sudo apt update
|
||||
sudo apt install -y --allow-downgrades moby-compose=2.18.1+azure-ubuntu22.04u2
|
||||
# Run test
|
||||
- name: Run test
|
||||
run: |
|
||||
cd ./tests/core/${{ inputs.TEST }}
|
||||
find . -type f -name 'docker-compose.*' -exec sed -i "s@bunkerity/bunkerweb:.*@bunkerweb-tests@" {} \;
|
||||
find . -type f -name 'docker-compose.*' -exec sed -i "s@bunkerity/bunkerweb-scheduler:.*@scheduler-tests@" {} \;
|
||||
./test.sh
|
||||
./test.sh
|
||||
|
|
|
|||
|
|
@ -80,10 +80,10 @@ Here is how you can access the logs, depending on your integration :
|
|||
journalctl -u bunkerweb --no-pager
|
||||
```
|
||||
|
||||
Common logs are located inside the `/var/log/nginx` directory :
|
||||
Common logs are located inside the `/var/log/bunkerweb` directory :
|
||||
```shell
|
||||
cat /var/log/nginx/error.log
|
||||
cat /var/log/nginx/access.log
|
||||
cat /var/log/bunkerweb/error.log
|
||||
cat /var/log/bunkerweb/access.log
|
||||
```
|
||||
|
||||
=== "Ansible"
|
||||
|
|
@ -93,10 +93,10 @@ Here is how you can access the logs, depending on your integration :
|
|||
ansible -i inventory.yml all -a "journalctl -u bunkerweb --no-pager" --become
|
||||
```
|
||||
|
||||
Common logs are located inside the `/var/log/nginx` directory :
|
||||
Common logs are located inside the `/var/log/bunkerweb` directory :
|
||||
```shell
|
||||
ansible -i inventory.yml all -a "cat /var/log/nginx/error.log" --become
|
||||
ansible -i inventory.yml all -a "cat /var/log/nginx/access.log" --become
|
||||
ansible -i inventory.yml all -a "cat /var/log/bunkerweb/error.log" --become
|
||||
ansible -i inventory.yml all -a "cat /var/log/bunkerweb/access.log" --become
|
||||
```
|
||||
|
||||
=== "Vagrant"
|
||||
|
|
@ -106,10 +106,10 @@ Here is how you can access the logs, depending on your integration :
|
|||
journalctl -u bunkerweb --no-pager
|
||||
```
|
||||
|
||||
Common logs are located inside the `/var/log/nginx` directory :
|
||||
Common logs are located inside the `/var/log/bunkerweb` directory :
|
||||
```shell
|
||||
cat /var/log/nginx/error.log
|
||||
cat /var/log/nginx/access.log
|
||||
cat /var/log/bunkerweb/error.log
|
||||
cat /var/log/bunkerweb/access.log
|
||||
```
|
||||
|
||||
## Permissions
|
||||
|
|
|
|||
|
|
@ -1,164 +1,136 @@
|
|||
init_by_lua_block {
|
||||
local class = require "middleclass"
|
||||
local clogger = require "bunkerweb.logger"
|
||||
local helpers = require "bunkerweb.helpers"
|
||||
local cdatastore = require "bunkerweb.datastore"
|
||||
local cjson = require "cjson"
|
||||
|
||||
local class = require "middleclass"
|
||||
local clogger = require "bunkerweb.logger"
|
||||
local helpers = require "bunkerweb.helpers"
|
||||
local cdatastore = require "bunkerweb.datastore"
|
||||
local cjson = require "cjson"
|
||||
-- Start init phase
|
||||
local logger = clogger:new("INIT")
|
||||
local datastore = cdatastore:new()
|
||||
logger:log(ngx.NOTICE, "init phase started")
|
||||
|
||||
-- Start init phase
|
||||
local logger = clogger:new("INIT")
|
||||
local datastore = cdatastore:new()
|
||||
logger:log(ngx.NOTICE, "init phase started")
|
||||
|
||||
-- Remove previous data from the datastore
|
||||
logger:log(ngx.NOTICE, "deleting old keys from datastore ...")
|
||||
datastore:flush_lru()
|
||||
local data_keys = {"^plugin", "^misc_"}
|
||||
for i, key in pairs(data_keys) do
|
||||
local ok, err = datastore:delete_all(key)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't delete " .. key .. " from datastore : " .. err)
|
||||
return false
|
||||
end
|
||||
logger:log(ngx.INFO, "deleted " .. key .. " from datastore")
|
||||
end
|
||||
logger:log(ngx.NOTICE, "deleted old keys from datastore")
|
||||
|
||||
-- Load plugins into the datastore
|
||||
logger:log(ngx.NOTICE, "saving plugins into datastore ...")
|
||||
local plugins = {}
|
||||
local plugin_paths = {"/usr/share/bunkerweb/core", "/etc/bunkerweb/plugins"}
|
||||
for i, plugin_path in ipairs(plugin_paths) do
|
||||
local paths = io.popen("find -L " .. plugin_path .. " -maxdepth 1 -type d ! -path " .. plugin_path)
|
||||
for path in paths:lines() do
|
||||
local ok, plugin = helpers.load_plugin(path .. "/plugin.json")
|
||||
-- Remove previous data from the datastore
|
||||
logger:log(ngx.NOTICE, "deleting old keys from datastore ...")
|
||||
datastore:flush_lru()
|
||||
local data_keys = { "^plugin", "^misc_" }
|
||||
for i, key in pairs(data_keys) do
|
||||
local ok, err = datastore:delete_all(key)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, plugin)
|
||||
else
|
||||
local ok, err = datastore:set("plugin_" .. plugin.id, plugin, nil, true)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't save " .. plugin.id .. " into datastore : " .. err)
|
||||
else
|
||||
table.insert(plugins, plugin)
|
||||
logger:log(ngx.NOTICE, "loaded plugin " .. plugin.id .. " v" .. plugin.version)
|
||||
end
|
||||
logger:log(ngx.ERR, "can't delete " .. key .. " from datastore : " .. err)
|
||||
return false
|
||||
end
|
||||
logger:log(ngx.INFO, "deleted " .. key .. " from datastore")
|
||||
end
|
||||
end
|
||||
local ok, err = datastore:set("plugins", plugins, nil, true)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't save plugins into datastore : " .. err)
|
||||
return false
|
||||
end
|
||||
logger:log(ngx.NOTICE, "deleted old keys from datastore")
|
||||
|
||||
-- Load variables into the datastore
|
||||
logger:log(ngx.NOTICE, "saving variables into datastore ...")
|
||||
local file = io.open("/etc/nginx/variables.env")
|
||||
if not file then
|
||||
logger:log(ngx.ERR, "can't open /etc/nginx/variables.env file")
|
||||
return false
|
||||
end
|
||||
file:close()
|
||||
local all_variables = {}
|
||||
for line in io.lines("/etc/nginx/variables.env") do
|
||||
local variable, value = line:match("^([^=]+)=(.*)$")
|
||||
all_variables[variable] = value
|
||||
end
|
||||
local ok, variables = helpers.load_variables(all_variables, plugins)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "error while loading variables : " .. variables)
|
||||
return false
|
||||
end
|
||||
local ok, err = datastore:set("variables", variables, nil, true)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't save plugins into datastore : " .. err)
|
||||
return false
|
||||
end
|
||||
logger:log(ngx.NOTICE, "saved variables into datastore")
|
||||
|
||||
-- Purge cache
|
||||
local cachestore = require "bunkerweb.cachestore":new(false, true)
|
||||
local ok, err = cachestore:purge()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't purge cachestore : " .. err)
|
||||
end
|
||||
|
||||
-- Set API values into the datastore
|
||||
-- logger:log(ngx.NOTICE, "saving API values into datastore ...")
|
||||
-- local value, err = datastore:get("variable_USE_API")
|
||||
-- if not value then
|
||||
-- logger:log(ngx.ERR, "can't get variable USE_API from the datastore : " .. err)
|
||||
-- return false
|
||||
-- end
|
||||
-- if value == "yes" then
|
||||
-- local value, err = datastore:get("variable_API_WHITELIST_IP")
|
||||
-- if not value then
|
||||
-- logger:log(ngx.ERR, "can't get variable API_WHITELIST_IP from the datastore : " .. err)
|
||||
-- return false
|
||||
-- end
|
||||
-- local whitelists = {}
|
||||
-- for whitelist in value:gmatch("%S+") do
|
||||
-- table.insert(whitelists, whitelist)
|
||||
-- end
|
||||
-- local ok, err = datastore:set("api_whitelist_ip", cjson.encode(whitelists))
|
||||
-- if not ok then
|
||||
-- logger:log(ngx.ERR, "can't save API whitelist_ip to datastore : " .. err)
|
||||
-- return false
|
||||
-- end
|
||||
-- logger:log(ngx.INFO, "saved API whitelist_ip into datastore")
|
||||
-- end
|
||||
-- logger:log(ngx.NOTICE, "saved API values into datastore")
|
||||
|
||||
logger:log(ngx.NOTICE, "saving plugins order into datastore ...")
|
||||
local ok, order = helpers.order_plugins(plugins)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't compute plugins order : " .. err)
|
||||
return false
|
||||
end
|
||||
for phase, id_list in pairs(order) do
|
||||
logger:log(ngx.NOTICE, "plugins order for phase " .. phase .. " : " .. cjson.encode(id_list))
|
||||
end
|
||||
local ok, err = datastore:set("plugins_order", order, nil, true)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't save plugins order into datastore : " .. err)
|
||||
return false
|
||||
end
|
||||
logger:log(ngx.NOTICE, "saved plugins order into datastore")
|
||||
|
||||
-- Call init() method
|
||||
logger:log(ngx.NOTICE, "calling init() methods of plugins ...")
|
||||
for i, plugin_id in ipairs(order["init"]) do
|
||||
-- Require call
|
||||
local plugin_lua, err = helpers.require_plugin(plugin_id)
|
||||
if plugin_lua == false then
|
||||
logger:log(ngx.ERR, err)
|
||||
elseif plugin_lua == nil then
|
||||
logger:log(ngx.NOTICE, err)
|
||||
else
|
||||
-- Check if plugin has init method
|
||||
if plugin_lua.init ~= nil then
|
||||
-- New call
|
||||
local ok, plugin_obj = helpers.new_plugin(plugin_lua)
|
||||
-- Load plugins into the datastore
|
||||
logger:log(ngx.NOTICE, "saving plugins into datastore ...")
|
||||
local plugins = {}
|
||||
local plugin_paths = { "/usr/share/bunkerweb/core", "/etc/bunkerweb/plugins" }
|
||||
for i, plugin_path in ipairs(plugin_paths) do
|
||||
local paths = io.popen("find -L " .. plugin_path .. " -maxdepth 1 -type d ! -path " .. plugin_path)
|
||||
for path in paths:lines() do
|
||||
local ok, plugin = helpers.load_plugin(path .. "/plugin.json")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, plugin_obj)
|
||||
logger:log(ngx.ERR, plugin)
|
||||
else
|
||||
local ok, ret = helpers.call_plugin(plugin_obj, "init")
|
||||
local ok, err = datastore:set("plugin_" .. plugin.id, plugin, nil, true)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
logger:log(ngx.ERR, plugin_id .. ":init() call failed : " .. ret.msg)
|
||||
logger:log(ngx.ERR, "can't save " .. plugin.id .. " into datastore : " .. err)
|
||||
else
|
||||
logger:log(ngx.NOTICE, plugin_id .. ":init() call successful : " .. ret.msg)
|
||||
table.insert(plugins, plugin)
|
||||
logger:log(ngx.NOTICE, "loaded plugin " .. plugin.id .. " v" .. plugin.version)
|
||||
end
|
||||
end
|
||||
else
|
||||
logger:log(ngx.NOTICE, "skipped execution of " .. plugin.id .. " because method init() is not defined")
|
||||
end
|
||||
end
|
||||
end
|
||||
logger:log(ngx.NOTICE, "called init() methods of plugins")
|
||||
local ok, err = datastore:set("plugins", plugins, nil, true)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't save plugins into datastore : " .. err)
|
||||
return false
|
||||
end
|
||||
|
||||
logger:log(ngx.NOTICE, "init phase ended")
|
||||
-- Load variables into the datastore
|
||||
logger:log(ngx.NOTICE, "saving variables into datastore ...")
|
||||
local file = io.open("/etc/nginx/variables.env")
|
||||
if not file then
|
||||
logger:log(ngx.ERR, "can't open /etc/nginx/variables.env file")
|
||||
return false
|
||||
end
|
||||
file:close()
|
||||
local all_variables = {}
|
||||
for line in io.lines("/etc/nginx/variables.env") do
|
||||
local variable, value = line:match("^([^=]+)=(.*)$")
|
||||
all_variables[variable] = value
|
||||
end
|
||||
local ok, variables = helpers.load_variables(all_variables, plugins)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "error while loading variables : " .. variables)
|
||||
return false
|
||||
end
|
||||
local ok, err = datastore:set("variables", variables, nil, true)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't save plugins into datastore : " .. err)
|
||||
return false
|
||||
end
|
||||
logger:log(ngx.NOTICE, "saved variables into datastore")
|
||||
|
||||
-- Purge cache
|
||||
local cachestore = require "bunkerweb.cachestore":new(false, true)
|
||||
local ok, err = cachestore:purge()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't purge cachestore : " .. err)
|
||||
end
|
||||
|
||||
logger:log(ngx.NOTICE, "saving plugins order into datastore ...")
|
||||
local ok, order = helpers.order_plugins(plugins)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't compute plugins order : " .. err)
|
||||
return false
|
||||
end
|
||||
for phase, id_list in pairs(order) do
|
||||
logger:log(ngx.NOTICE, "plugins order for phase " .. phase .. " : " .. cjson.encode(id_list))
|
||||
end
|
||||
local ok, err = datastore:set("plugins_order", order, nil, true)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't save plugins order into datastore : " .. err)
|
||||
return false
|
||||
end
|
||||
logger:log(ngx.NOTICE, "saved plugins order into datastore")
|
||||
|
||||
-- Call init() method
|
||||
logger:log(ngx.NOTICE, "calling init() methods of plugins ...")
|
||||
for i, plugin_id in ipairs(order["init"]) do
|
||||
-- Require call
|
||||
local plugin_lua, err = helpers.require_plugin(plugin_id)
|
||||
if plugin_lua == false then
|
||||
logger:log(ngx.ERR, err)
|
||||
elseif plugin_lua == nil then
|
||||
logger:log(ngx.NOTICE, err)
|
||||
else
|
||||
-- Check if plugin has init method
|
||||
if plugin_lua.init ~= nil then
|
||||
-- New call
|
||||
local ok, plugin_obj = helpers.new_plugin(plugin_lua)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, plugin_obj)
|
||||
else
|
||||
local ok, ret = helpers.call_plugin(plugin_obj, "init")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
logger:log(ngx.ERR, plugin_id .. ":init() call failed : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.NOTICE, plugin_id .. ":init() call successful : " .. ret.msg)
|
||||
end
|
||||
end
|
||||
else
|
||||
logger:log(ngx.NOTICE, "skipped execution of " .. plugin.id .. " because method init() is not defined")
|
||||
end
|
||||
end
|
||||
end
|
||||
logger:log(ngx.NOTICE, "called init() methods of plugins")
|
||||
|
||||
logger:log(ngx.NOTICE, "init phase ended")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,138 +1,136 @@
|
|||
init_by_lua_block {
|
||||
local class = require "middleclass"
|
||||
local clogger = require "bunkerweb.logger"
|
||||
local helpers = require "bunkerweb.helpers"
|
||||
local cdatastore = require "bunkerweb.datastore"
|
||||
local cjson = require "cjson"
|
||||
|
||||
local class = require "middleclass"
|
||||
local clogger = require "bunkerweb.logger"
|
||||
local helpers = require "bunkerweb.helpers"
|
||||
local cdatastore = require "bunkerweb.datastore"
|
||||
local cjson = require "cjson"
|
||||
-- Start init phase
|
||||
local logger = clogger:new("INIT")
|
||||
local datastore = cdatastore:new()
|
||||
logger:log(ngx.NOTICE, "init-stream phase started")
|
||||
|
||||
-- Start init phase
|
||||
local logger = clogger:new("INIT")
|
||||
local datastore = cdatastore:new()
|
||||
logger:log(ngx.NOTICE, "init-stream phase started")
|
||||
|
||||
-- Remove previous data from the datastore
|
||||
logger:log(ngx.NOTICE, "deleting old keys from datastore ...")
|
||||
datastore:flush_lru()
|
||||
local data_keys = {"^plugin", "^misc_"}
|
||||
for i, key in pairs(data_keys) do
|
||||
local ok, err = datastore:delete_all(key)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't delete " .. key .. " from datastore : " .. err)
|
||||
return false
|
||||
end
|
||||
logger:log(ngx.INFO, "deleted " .. key .. " from datastore")
|
||||
end
|
||||
logger:log(ngx.NOTICE, "deleted old keys from datastore")
|
||||
|
||||
-- Load plugins into the datastore
|
||||
logger:log(ngx.NOTICE, "saving plugins into datastore ...")
|
||||
local plugins = {}
|
||||
local plugin_paths = {"/usr/share/bunkerweb/core", "/etc/bunkerweb/plugins"}
|
||||
for i, plugin_path in ipairs(plugin_paths) do
|
||||
local paths = io.popen("find -L " .. plugin_path .. " -maxdepth 1 -type d ! -path " .. plugin_path)
|
||||
for path in paths:lines() do
|
||||
local ok, plugin = helpers.load_plugin(path .. "/plugin.json")
|
||||
-- Remove previous data from the datastore
|
||||
logger:log(ngx.NOTICE, "deleting old keys from datastore ...")
|
||||
datastore:flush_lru()
|
||||
local data_keys = { "^plugin", "^misc_" }
|
||||
for i, key in pairs(data_keys) do
|
||||
local ok, err = datastore:delete_all(key)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, plugin)
|
||||
else
|
||||
local ok, err = datastore:set("plugin_" .. plugin.id, plugin, true)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't save " .. plugin.id .. " into datastore : " .. err)
|
||||
else
|
||||
table.insert(plugins, plugin)
|
||||
logger:log(ngx.NOTICE, "loaded plugin " .. plugin.id .. " v" .. plugin.version)
|
||||
end
|
||||
logger:log(ngx.ERR, "can't delete " .. key .. " from datastore : " .. err)
|
||||
return false
|
||||
end
|
||||
logger:log(ngx.INFO, "deleted " .. key .. " from datastore")
|
||||
end
|
||||
end
|
||||
local ok, err = datastore:set("plugins", plugins, nil, true)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't save plugins into datastore : " .. err)
|
||||
return false
|
||||
end
|
||||
logger:log(ngx.NOTICE, "deleted old keys from datastore")
|
||||
|
||||
-- Load variables into the datastore
|
||||
logger:log(ngx.NOTICE, "saving variables into datastore ...")
|
||||
local file = io.open("/etc/nginx/variables.env")
|
||||
if not file then
|
||||
logger:log(ngx.ERR, "can't open /etc/nginx/variables.env file")
|
||||
return false
|
||||
end
|
||||
file:close()
|
||||
local all_variables = {}
|
||||
for line in io.lines("/etc/nginx/variables.env") do
|
||||
local variable, value = line:match("^([^=]+)=(.*)$")
|
||||
all_variables[variable] = value
|
||||
end
|
||||
local ok, variables = helpers.load_variables(all_variables, plugins)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "error while loading variables : " .. variables)
|
||||
return false
|
||||
end
|
||||
local ok, err = datastore:set("variables", variables, nil, true)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't save plugins into datastore : " .. err)
|
||||
return false
|
||||
end
|
||||
logger:log(ngx.NOTICE, "saved variables into datastore")
|
||||
|
||||
-- Purge cache
|
||||
local cachestore = require "bunkerweb.cachestore":new(false, true)
|
||||
local ok, err = cachestore:purge()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't purge cachestore : " .. err)
|
||||
end
|
||||
|
||||
logger:log(ngx.NOTICE, "saving plugins order into datastore ...")
|
||||
local ok, order = helpers.order_plugins(plugins)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't compute plugins order : " .. err)
|
||||
return false
|
||||
end
|
||||
for phase, id_list in pairs(order) do
|
||||
logger:log(ngx.NOTICE, "plugins order for phase " .. phase .. " : " .. cjson.encode(id_list))
|
||||
end
|
||||
local ok, err = datastore:set("plugins_order", order, nil, true)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't save plugins order into datastore : " .. err)
|
||||
return false
|
||||
end
|
||||
logger:log(ngx.NOTICE, "saved plugins order into datastore")
|
||||
|
||||
-- Call init() method
|
||||
logger:log(ngx.NOTICE, "calling init() methods of plugins ...")
|
||||
for i, plugin_id in ipairs(order["init"]) do
|
||||
-- Require call
|
||||
local plugin_lua, err = helpers.require_plugin(plugin_id)
|
||||
if plugin_lua == false then
|
||||
logger:log(ngx.ERR, err)
|
||||
elseif plugin_lua == nil then
|
||||
logger:log(ngx.NOTICE, err)
|
||||
else
|
||||
-- Check if plugin has init method
|
||||
if plugin_lua.init ~= nil then
|
||||
-- New call
|
||||
local ok, plugin_obj = helpers.new_plugin(plugin_lua)
|
||||
-- Load plugins into the datastore
|
||||
logger:log(ngx.NOTICE, "saving plugins into datastore ...")
|
||||
local plugins = {}
|
||||
local plugin_paths = { "/usr/share/bunkerweb/core", "/etc/bunkerweb/plugins" }
|
||||
for i, plugin_path in ipairs(plugin_paths) do
|
||||
local paths = io.popen("find -L " .. plugin_path .. " -maxdepth 1 -type d ! -path " .. plugin_path)
|
||||
for path in paths:lines() do
|
||||
local ok, plugin = helpers.load_plugin(path .. "/plugin.json")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, plugin_obj)
|
||||
logger:log(ngx.ERR, plugin)
|
||||
else
|
||||
local ok, ret = helpers.call_plugin(plugin_obj, "init")
|
||||
local ok, err = datastore:set("plugin_" .. plugin.id, plugin, true)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
logger:log(ngx.ERR, plugin_id .. ":init() call failed : " .. ret.msg)
|
||||
logger:log(ngx.ERR, "can't save " .. plugin.id .. " into datastore : " .. err)
|
||||
else
|
||||
logger:log(ngx.NOTICE, plugin_id .. ":init() call successful : " .. ret.msg)
|
||||
table.insert(plugins, plugin)
|
||||
logger:log(ngx.NOTICE, "loaded plugin " .. plugin.id .. " v" .. plugin.version)
|
||||
end
|
||||
end
|
||||
else
|
||||
logger:log(ngx.NOTICE, "skipped execution of " .. plugin.id .. " because method init() is not defined")
|
||||
end
|
||||
end
|
||||
end
|
||||
logger:log(ngx.NOTICE, "called init() methods of plugins")
|
||||
local ok, err = datastore:set("plugins", plugins, nil, true)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't save plugins into datastore : " .. err)
|
||||
return false
|
||||
end
|
||||
|
||||
logger:log(ngx.NOTICE, "init-stream phase ended")
|
||||
-- Load variables into the datastore
|
||||
logger:log(ngx.NOTICE, "saving variables into datastore ...")
|
||||
local file = io.open("/etc/nginx/variables.env")
|
||||
if not file then
|
||||
logger:log(ngx.ERR, "can't open /etc/nginx/variables.env file")
|
||||
return false
|
||||
end
|
||||
file:close()
|
||||
local all_variables = {}
|
||||
for line in io.lines("/etc/nginx/variables.env") do
|
||||
local variable, value = line:match("^([^=]+)=(.*)$")
|
||||
all_variables[variable] = value
|
||||
end
|
||||
local ok, variables = helpers.load_variables(all_variables, plugins)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "error while loading variables : " .. variables)
|
||||
return false
|
||||
end
|
||||
local ok, err = datastore:set("variables", variables, nil, true)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't save plugins into datastore : " .. err)
|
||||
return false
|
||||
end
|
||||
logger:log(ngx.NOTICE, "saved variables into datastore")
|
||||
|
||||
-- Purge cache
|
||||
local cachestore = require "bunkerweb.cachestore":new(false, true)
|
||||
local ok, err = cachestore:purge()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't purge cachestore : " .. err)
|
||||
end
|
||||
|
||||
logger:log(ngx.NOTICE, "saving plugins order into datastore ...")
|
||||
local ok, order = helpers.order_plugins(plugins)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't compute plugins order : " .. err)
|
||||
return false
|
||||
end
|
||||
for phase, id_list in pairs(order) do
|
||||
logger:log(ngx.NOTICE, "plugins order for phase " .. phase .. " : " .. cjson.encode(id_list))
|
||||
end
|
||||
local ok, err = datastore:set("plugins_order", order, nil, true)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't save plugins order into datastore : " .. err)
|
||||
return false
|
||||
end
|
||||
logger:log(ngx.NOTICE, "saved plugins order into datastore")
|
||||
|
||||
-- Call init() method
|
||||
logger:log(ngx.NOTICE, "calling init() methods of plugins ...")
|
||||
for i, plugin_id in ipairs(order["init"]) do
|
||||
-- Require call
|
||||
local plugin_lua, err = helpers.require_plugin(plugin_id)
|
||||
if plugin_lua == false then
|
||||
logger:log(ngx.ERR, err)
|
||||
elseif plugin_lua == nil then
|
||||
logger:log(ngx.NOTICE, err)
|
||||
else
|
||||
-- Check if plugin has init method
|
||||
if plugin_lua.init ~= nil then
|
||||
-- New call
|
||||
local ok, plugin_obj = helpers.new_plugin(plugin_lua)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, plugin_obj)
|
||||
else
|
||||
local ok, ret = helpers.call_plugin(plugin_obj, "init")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
logger:log(ngx.ERR, plugin_id .. ":init() call failed : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.NOTICE, plugin_id .. ":init() call successful : " .. ret.msg)
|
||||
end
|
||||
end
|
||||
else
|
||||
logger:log(ngx.NOTICE, "skipped execution of " .. plugin.id .. " because method init() is not defined")
|
||||
end
|
||||
end
|
||||
end
|
||||
logger:log(ngx.NOTICE, "called init() methods of plugins")
|
||||
|
||||
logger:log(ngx.NOTICE, "init-stream phase ended")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,120 +1,116 @@
|
|||
lua_shared_dict worker_lock 16k;
|
||||
|
||||
init_worker_by_lua_block {
|
||||
-- Our timer function
|
||||
local ready_work = function(premature)
|
||||
-- Libs
|
||||
local helpers = require "bunkerweb.helpers"
|
||||
local cjson = require "cjson"
|
||||
|
||||
-- Our timer function
|
||||
local ready_work = function(premature)
|
||||
-- Instantiate objects
|
||||
local logger = require "bunkerweb.logger":new("INIT-WORKER")
|
||||
local datastore = require "bunkerweb.datastore":new()
|
||||
|
||||
-- Libs
|
||||
local helpers = require "bunkerweb.helpers"
|
||||
local cjson = require "cjson"
|
||||
|
||||
-- Instantiate objects
|
||||
local logger = require "bunkerweb.logger":new("INIT-WORKER")
|
||||
local datastore = require "bunkerweb.datastore":new()
|
||||
|
||||
-- Don't go further we are in loading state
|
||||
local is_loading, err = require "bunkerweb.utils".get_variable("IS_LOADING", false)
|
||||
if not is_loading then
|
||||
logger:log(ngx.ERR, "utils.get_variable() failed : " .. err)
|
||||
return
|
||||
elseif is_loading == "yes" then
|
||||
return
|
||||
end
|
||||
|
||||
-- Instantiate lock
|
||||
local lock = require "resty.lock":new("worker_lock", {timeout = 10})
|
||||
if not lock then
|
||||
logger:log(ngx.ERR, "lock:new() failed : " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
-- Acquire lock
|
||||
local elapsed, err = lock:lock("ready")
|
||||
if elapsed == nil then
|
||||
logger:log(ngx.ERR, "lock:lock() failed : " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
-- Check if work is done
|
||||
local ok, err = datastore:get("misc_ready")
|
||||
if not ok and err ~= "not found" then
|
||||
logger:log(ngx.ERR, "datastore:get() failed : " .. err)
|
||||
local ok, err = lock:unlock()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "lock:unlock() failed : " .. err)
|
||||
-- Don't go further we are in loading state
|
||||
local is_loading, err = require "bunkerweb.utils".get_variable("IS_LOADING", false)
|
||||
if not is_loading then
|
||||
logger:log(ngx.ERR, "utils.get_variable() failed : " .. err)
|
||||
return
|
||||
elseif is_loading == "yes" then
|
||||
return
|
||||
end
|
||||
return
|
||||
end
|
||||
if ok then
|
||||
local ok, err = lock:unlock()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "lock:unlock() failed : " .. err)
|
||||
|
||||
-- Instantiate lock
|
||||
local lock = require "resty.lock":new("worker_lock", { timeout = 10 })
|
||||
if not lock then
|
||||
logger:log(ngx.ERR, "lock:new() failed : " .. err)
|
||||
return
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
logger:log(ngx.INFO, "init_worker phase started")
|
||||
|
||||
-- Get plugins order
|
||||
local order, err = datastore:get("plugins_order", true)
|
||||
if not order then
|
||||
logger:log(ngx.ERR, "can't get plugins order from datastore : " .. err)
|
||||
local ok, err = lock:unlock()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "lock:unlock() failed : " .. err)
|
||||
-- Acquire lock
|
||||
local elapsed, err = lock:lock("ready")
|
||||
if elapsed == nil then
|
||||
logger:log(ngx.ERR, "lock:lock() failed : " .. err)
|
||||
return
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
-- Call init_worker() methods
|
||||
logger:log(ngx.INFO, "calling init_worker() methods of plugins ...")
|
||||
for i, plugin_id in ipairs(order.init_worker) do
|
||||
-- Require call
|
||||
local plugin_lua, err = helpers.require_plugin(plugin_id)
|
||||
if plugin_lua == false then
|
||||
logger:log(ngx.ERR, err)
|
||||
elseif plugin_lua == nil then
|
||||
logger:log(ngx.INFO, err)
|
||||
else
|
||||
-- Check if plugin has init_worker method
|
||||
if plugin_lua.init_worker ~= nil then
|
||||
-- New call
|
||||
local ok, plugin_obj = helpers.new_plugin(plugin_lua)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, plugin_obj)
|
||||
else
|
||||
local ok, ret = helpers.call_plugin(plugin_obj, "init_worker")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
logger:log(ngx.ERR, plugin_id .. ":init_worker() call failed : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.INFO, plugin_id .. ":init_worker() call successful : " .. ret.msg)
|
||||
end
|
||||
end
|
||||
-- Check if work is done
|
||||
local ok, err = datastore:get("misc_ready")
|
||||
if not ok and err ~= "not found" then
|
||||
logger:log(ngx.ERR, "datastore:get() failed : " .. err)
|
||||
local ok, err = lock:unlock()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "lock:unlock() failed : " .. err)
|
||||
end
|
||||
return
|
||||
end
|
||||
if ok then
|
||||
local ok, err = lock:unlock()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "lock:unlock() failed : " .. err)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
logger:log(ngx.INFO, "init_worker phase started")
|
||||
|
||||
-- Get plugins order
|
||||
local order, err = datastore:get("plugins_order", true)
|
||||
if not order then
|
||||
logger:log(ngx.ERR, "can't get plugins order from datastore : " .. err)
|
||||
local ok, err = lock:unlock()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "lock:unlock() failed : " .. err)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
-- Call init_worker() methods
|
||||
logger:log(ngx.INFO, "calling init_worker() methods of plugins ...")
|
||||
for i, plugin_id in ipairs(order.init_worker) do
|
||||
-- Require call
|
||||
local plugin_lua, err = helpers.require_plugin(plugin_id)
|
||||
if plugin_lua == false then
|
||||
logger:log(ngx.ERR, err)
|
||||
elseif plugin_lua == nil then
|
||||
logger:log(ngx.INFO, err)
|
||||
else
|
||||
logger:log(ngx.INFO, "skipped execution of " .. plugin_id .. " because method init_worker() is not defined")
|
||||
-- Check if plugin has init_worker method
|
||||
if plugin_lua.init_worker ~= nil then
|
||||
-- New call
|
||||
local ok, plugin_obj = helpers.new_plugin(plugin_lua)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, plugin_obj)
|
||||
else
|
||||
local ok, ret = helpers.call_plugin(plugin_obj, "init_worker")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
logger:log(ngx.ERR, plugin_id .. ":init_worker() call failed : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.INFO, plugin_id .. ":init_worker() call successful : " .. ret.msg)
|
||||
end
|
||||
end
|
||||
else
|
||||
logger:log(ngx.INFO, "skipped execution of " .. plugin_id .. " because method init_worker() is not defined")
|
||||
end
|
||||
end
|
||||
end
|
||||
logger:log(ngx.INFO, "called init_worker() methods of plugins")
|
||||
|
||||
-- End
|
||||
local ok, err = datastore:set("misc_ready", "ok")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "datastore:set() failed : " .. err)
|
||||
end
|
||||
local ok, err = lock:unlock()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "lock:unlock() failed : " .. err)
|
||||
end
|
||||
logger:log(ngx.INFO, "init phase ended")
|
||||
logger:log(ngx.NOTICE, "BunkerWeb is ready to fool hackers ! 🚀")
|
||||
end
|
||||
logger:log(ngx.INFO, "called init_worker() methods of plugins")
|
||||
|
||||
-- End
|
||||
local ok, err = datastore:set("misc_ready", "ok")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "datastore:set() failed : " .. err)
|
||||
end
|
||||
local ok, err = lock:unlock()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "lock:unlock() failed : " .. err)
|
||||
end
|
||||
logger:log(ngx.INFO, "init phase ended")
|
||||
logger:log(ngx.NOTICE, "BunkerWeb is ready to fool hackers ! 🚀")
|
||||
|
||||
end
|
||||
|
||||
-- Start timer
|
||||
ngx.timer.at(5, ready_work)
|
||||
|
||||
-- Start timer
|
||||
ngx.timer.at(5, ready_work)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,120 +1,119 @@
|
|||
access_by_lua_block {
|
||||
local class = require "middleclass"
|
||||
local clogger = require "bunkerweb.logger"
|
||||
local helpers = require "bunkerweb.helpers"
|
||||
local utils = require "bunkerweb.utils"
|
||||
local cdatastore = require "bunkerweb.datastore"
|
||||
local cclusterstore = require "bunkerweb.clusterstore"
|
||||
local cjson = require "cjson"
|
||||
|
||||
local class = require "middleclass"
|
||||
local clogger = require "bunkerweb.logger"
|
||||
local helpers = require "bunkerweb.helpers"
|
||||
local utils = require "bunkerweb.utils"
|
||||
local cdatastore = require "bunkerweb.datastore"
|
||||
local cclusterstore = require "bunkerweb.clusterstore"
|
||||
local cjson = require "cjson"
|
||||
|
||||
-- Don't process internal requests
|
||||
local logger = clogger:new("ACCESS")
|
||||
if ngx.req.is_internal() then
|
||||
logger:log(ngx.INFO, "skipped access phase because request is internal")
|
||||
return true
|
||||
end
|
||||
|
||||
-- Start access phase
|
||||
local datastore = cdatastore:new()
|
||||
logger:log(ngx.INFO, "access phase started")
|
||||
|
||||
-- Fill ctx
|
||||
logger:log(ngx.INFO, "filling ngx.ctx ...")
|
||||
local ok, ret, errors, ctx = helpers.fill_ctx()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "fill_ctx() failed : " .. ret)
|
||||
elseif errors then
|
||||
for i, error in ipairs(errors) do
|
||||
logger:log(ngx.ERR, "fill_ctx() error " .. tostring(i) .. " : " .. error)
|
||||
-- Don't process internal requests
|
||||
local logger = clogger:new("ACCESS")
|
||||
if ngx.req.is_internal() then
|
||||
logger:log(ngx.INFO, "skipped access phase because request is internal")
|
||||
return true
|
||||
end
|
||||
end
|
||||
logger:log(ngx.INFO, "ngx.ctx filled (ret = " .. ret .. ")")
|
||||
|
||||
-- Process bans as soon as possible
|
||||
if ctx.bw.is_whitelisted ~= "yes" then
|
||||
local banned, reason, ttl = utils.is_banned(ctx.bw.remote_addr)
|
||||
if banned == nil then
|
||||
logger:log(ngx.ERR, "can't check if IP " .. ctx.bw.remote_addr .. " is banned : " .. reason)
|
||||
elseif banned then
|
||||
logger:log(ngx.WARN, "IP " .. ctx.bw.remote_addr .. " is banned with reason " .. reason .. " (" .. tostring(ttl) .. "s remaining)")
|
||||
return ngx.exit(utils.get_deny_status(ctx))
|
||||
else
|
||||
logger:log(ngx.INFO, "IP " .. ctx.bw.remote_addr .. " is not banned")
|
||||
end
|
||||
end
|
||||
-- Start access phase
|
||||
local datastore = cdatastore:new()
|
||||
logger:log(ngx.INFO, "access phase started")
|
||||
|
||||
-- Get plugins order
|
||||
local order, err = datastore:get("plugins_order", true)
|
||||
if not order then
|
||||
logger:log(ngx.ERR, "can't get plugins order from datastore : " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
-- Call access() methods
|
||||
logger:log(ngx.INFO, "calling access() methods of plugins ...")
|
||||
local status = nil
|
||||
local redirect = nil
|
||||
for i, plugin_id in ipairs(order.access) do
|
||||
-- Require call
|
||||
local plugin_lua, err = helpers.require_plugin(plugin_id)
|
||||
if plugin_lua == false then
|
||||
logger:log(ngx.ERR, err)
|
||||
elseif plugin_lua == nil then
|
||||
logger:log(ngx.INFO, err)
|
||||
else
|
||||
-- Check if plugin has access method
|
||||
if plugin_lua.access ~= nil then
|
||||
-- New call
|
||||
local ok, plugin_obj = helpers.new_plugin(plugin_lua, ctx)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, plugin_obj)
|
||||
else
|
||||
local ok, ret = helpers.call_plugin(plugin_obj, "access")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
logger:log(ngx.ERR, plugin_id .. ":access() call failed : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.INFO, plugin_id .. ":access() call successful : " .. ret.msg)
|
||||
end
|
||||
if ret.status then
|
||||
if ret.status == utils.get_deny_status(ctx) then
|
||||
ctx.bw.reason = plugin_id
|
||||
logger:log(ngx.WARN, "denied access from " .. plugin_id .. " : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.NOTICE, plugin_id .. " returned status " .. tostring(ret.status) .. " : " .. ret.msg)
|
||||
end
|
||||
status = ret.status
|
||||
break
|
||||
elseif ret.redirect then
|
||||
logger:log(ngx.NOTICE, plugin_id .. " redirect to " .. ret.redirect .. " : " .. ret.msg)
|
||||
redirect = ret.redirect
|
||||
break
|
||||
end
|
||||
end
|
||||
else
|
||||
logger:log(ngx.INFO, "skipped execution of " .. plugin_id .. " because method access() is not defined")
|
||||
-- Fill ctx
|
||||
logger:log(ngx.INFO, "filling ngx.ctx ...")
|
||||
local ok, ret, errors, ctx = helpers.fill_ctx()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "fill_ctx() failed : " .. ret)
|
||||
elseif errors then
|
||||
for i, error in ipairs(errors) do
|
||||
logger:log(ngx.ERR, "fill_ctx() error " .. tostring(i) .. " : " .. error)
|
||||
end
|
||||
end
|
||||
end
|
||||
logger:log(ngx.INFO, "called access() methods of plugins")
|
||||
logger:log(ngx.INFO, "ngx.ctx filled (ret = " .. ret .. ")")
|
||||
|
||||
-- Save ctx
|
||||
ngx.ctx = ctx
|
||||
-- Process bans as soon as possible
|
||||
if ctx.bw.is_whitelisted ~= "yes" then
|
||||
local banned, reason, ttl = utils.is_banned(ctx.bw.remote_addr)
|
||||
if banned == nil then
|
||||
logger:log(ngx.ERR, "can't check if IP " .. ctx.bw.remote_addr .. " is banned : " .. reason)
|
||||
elseif banned then
|
||||
logger:log(ngx.WARN,
|
||||
"IP " .. ctx.bw.remote_addr .. " is banned with reason " .. reason .. " (" .. tostring(ttl) .. "s remaining)")
|
||||
return ngx.exit(utils.get_deny_status(ctx))
|
||||
else
|
||||
logger:log(ngx.INFO, "IP " .. ctx.bw.remote_addr .. " is not banned")
|
||||
end
|
||||
end
|
||||
|
||||
logger:log(ngx.INFO, "access phase ended")
|
||||
-- Get plugins order
|
||||
local order, err = datastore:get("plugins_order", true)
|
||||
if not order then
|
||||
logger:log(ngx.ERR, "can't get plugins order from datastore : " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
-- Return status if needed
|
||||
if status then
|
||||
return ngx.exit(status)
|
||||
end
|
||||
-- Call access() methods
|
||||
logger:log(ngx.INFO, "calling access() methods of plugins ...")
|
||||
local status = nil
|
||||
local redirect = nil
|
||||
for i, plugin_id in ipairs(order.access) do
|
||||
-- Require call
|
||||
local plugin_lua, err = helpers.require_plugin(plugin_id)
|
||||
if plugin_lua == false then
|
||||
logger:log(ngx.ERR, err)
|
||||
elseif plugin_lua == nil then
|
||||
logger:log(ngx.INFO, err)
|
||||
else
|
||||
-- Check if plugin has access method
|
||||
if plugin_lua.access ~= nil then
|
||||
-- New call
|
||||
local ok, plugin_obj = helpers.new_plugin(plugin_lua, ctx)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, plugin_obj)
|
||||
else
|
||||
local ok, ret = helpers.call_plugin(plugin_obj, "access")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
logger:log(ngx.ERR, plugin_id .. ":access() call failed : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.INFO, plugin_id .. ":access() call successful : " .. ret.msg)
|
||||
end
|
||||
if ret.status then
|
||||
if ret.status == utils.get_deny_status(ctx) then
|
||||
ctx.bw.reason = plugin_id
|
||||
logger:log(ngx.WARN, "denied access from " .. plugin_id .. " : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.NOTICE, plugin_id .. " returned status " .. tostring(ret.status) .. " : " .. ret.msg)
|
||||
end
|
||||
status = ret.status
|
||||
break
|
||||
elseif ret.redirect then
|
||||
logger:log(ngx.NOTICE, plugin_id .. " redirect to " .. ret.redirect .. " : " .. ret.msg)
|
||||
redirect = ret.redirect
|
||||
break
|
||||
end
|
||||
end
|
||||
else
|
||||
logger:log(ngx.INFO, "skipped execution of " .. plugin_id .. " because method access() is not defined")
|
||||
end
|
||||
end
|
||||
end
|
||||
logger:log(ngx.INFO, "called access() methods of plugins")
|
||||
|
||||
-- Redirect if needed
|
||||
if redirect then
|
||||
return ngx.redirect(redirect)
|
||||
end
|
||||
-- Save ctx
|
||||
ngx.ctx = ctx
|
||||
|
||||
return true
|
||||
logger:log(ngx.INFO, "access phase ended")
|
||||
|
||||
}
|
||||
-- Return status if needed
|
||||
if status then
|
||||
return ngx.exit(status)
|
||||
end
|
||||
|
||||
-- Redirect if needed
|
||||
if redirect then
|
||||
return ngx.redirect(redirect)
|
||||
end
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,71 +1,69 @@
|
|||
header_filter_by_lua_block {
|
||||
local class = require "middleclass"
|
||||
local clogger = require "bunkerweb.logger"
|
||||
local helpers = require "bunkerweb.helpers"
|
||||
local cdatastore = require "bunkerweb.datastore"
|
||||
local cjson = require "cjson"
|
||||
|
||||
local class = require "middleclass"
|
||||
local clogger = require "bunkerweb.logger"
|
||||
local helpers = require "bunkerweb.helpers"
|
||||
local cdatastore = require "bunkerweb.datastore"
|
||||
local cjson = require "cjson"
|
||||
-- Start set phase
|
||||
local logger = clogger:new("HEADER")
|
||||
local datastore = cdatastore:new()
|
||||
logger:log(ngx.INFO, "header phase started")
|
||||
|
||||
-- Start set phase
|
||||
local logger = clogger:new("HEADER")
|
||||
local datastore = cdatastore:new()
|
||||
logger:log(ngx.INFO, "header phase started")
|
||||
|
||||
-- Fill ctx
|
||||
logger:log(ngx.INFO, "filling ngx.ctx ...")
|
||||
local ok, ret, errors, ctx = helpers.fill_ctx()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "fill_ctx() failed : " .. ret)
|
||||
elseif errors then
|
||||
for i, error in ipairs(errors) do
|
||||
logger:log(ngx.ERR, "fill_ctx() error " .. tostring(i) .. " : " .. error)
|
||||
end
|
||||
end
|
||||
logger:log(ngx.INFO, "ngx.ctx filled (ret = " .. ret .. ")")
|
||||
|
||||
-- Get plugins order
|
||||
local order, err = datastore:get("plugins_order", true)
|
||||
if not order then
|
||||
logger:log(ngx.ERR, "can't get plugins order from datastore : " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
-- Call header() methods
|
||||
logger:log(ngx.INFO, "calling header() methods of plugins ...")
|
||||
for i, plugin_id in ipairs(order.header) do
|
||||
-- Require call
|
||||
local plugin_lua, err = helpers.require_plugin(plugin_id)
|
||||
if plugin_lua == false then
|
||||
logger:log(ngx.ERR, err)
|
||||
elseif plugin_lua == nil then
|
||||
logger:log(ngx.INFO, err)
|
||||
else
|
||||
-- Check if plugin has header method
|
||||
if plugin_lua.header ~= nil then
|
||||
-- New call
|
||||
local ok, plugin_obj = helpers.new_plugin(plugin_lua, ctx)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, plugin_obj)
|
||||
else
|
||||
local ok, ret = helpers.call_plugin(plugin_obj, "header")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
logger:log(ngx.ERR, plugin_id .. ":header() call failed : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.INFO, plugin_id .. ":header() call successful : " .. ret.msg)
|
||||
end
|
||||
end
|
||||
else
|
||||
logger:log(ngx.INFO, "skipped execution of " .. plugin_id .. " because method header() is not defined")
|
||||
-- Fill ctx
|
||||
logger:log(ngx.INFO, "filling ngx.ctx ...")
|
||||
local ok, ret, errors, ctx = helpers.fill_ctx()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "fill_ctx() failed : " .. ret)
|
||||
elseif errors then
|
||||
for i, error in ipairs(errors) do
|
||||
logger:log(ngx.ERR, "fill_ctx() error " .. tostring(i) .. " : " .. error)
|
||||
end
|
||||
end
|
||||
end
|
||||
logger:log(ngx.INFO, "called header() methods of plugins")
|
||||
logger:log(ngx.INFO, "ngx.ctx filled (ret = " .. ret .. ")")
|
||||
|
||||
-- Save ctx
|
||||
ngx.ctx = ctx
|
||||
-- Get plugins order
|
||||
local order, err = datastore:get("plugins_order", true)
|
||||
if not order then
|
||||
logger:log(ngx.ERR, "can't get plugins order from datastore : " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
return true
|
||||
-- Call header() methods
|
||||
logger:log(ngx.INFO, "calling header() methods of plugins ...")
|
||||
for i, plugin_id in ipairs(order.header) do
|
||||
-- Require call
|
||||
local plugin_lua, err = helpers.require_plugin(plugin_id)
|
||||
if plugin_lua == false then
|
||||
logger:log(ngx.ERR, err)
|
||||
elseif plugin_lua == nil then
|
||||
logger:log(ngx.INFO, err)
|
||||
else
|
||||
-- Check if plugin has header method
|
||||
if plugin_lua.header ~= nil then
|
||||
-- New call
|
||||
local ok, plugin_obj = helpers.new_plugin(plugin_lua, ctx)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, plugin_obj)
|
||||
else
|
||||
local ok, ret = helpers.call_plugin(plugin_obj, "header")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
logger:log(ngx.ERR, plugin_id .. ":header() call failed : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.INFO, plugin_id .. ":header() call successful : " .. ret.msg)
|
||||
end
|
||||
end
|
||||
else
|
||||
logger:log(ngx.INFO, "skipped execution of " .. plugin_id .. " because method header() is not defined")
|
||||
end
|
||||
end
|
||||
end
|
||||
logger:log(ngx.INFO, "called header() methods of plugins")
|
||||
|
||||
}
|
||||
-- Save ctx
|
||||
ngx.ctx = ctx
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,76 +1,74 @@
|
|||
log_by_lua_block {
|
||||
local class = require "middleclass"
|
||||
local clogger = require "bunkerweb.logger"
|
||||
local helpers = require "bunkerweb.helpers"
|
||||
local cdatastore = require "bunkerweb.datastore"
|
||||
local cjson = require "cjson"
|
||||
|
||||
local class = require "middleclass"
|
||||
local clogger = require "bunkerweb.logger"
|
||||
local helpers = require "bunkerweb.helpers"
|
||||
local cdatastore = require "bunkerweb.datastore"
|
||||
local cjson = require "cjson"
|
||||
-- Start log phase
|
||||
local logger = clogger:new("LOG")
|
||||
local datastore = cdatastore:new()
|
||||
logger:log(ngx.INFO, "log phase started")
|
||||
|
||||
-- Start log phase
|
||||
local logger = clogger:new("LOG")
|
||||
local datastore = cdatastore:new()
|
||||
logger:log(ngx.INFO, "log phase started")
|
||||
|
||||
-- Fill ctx
|
||||
logger:log(ngx.INFO, "filling ngx.ctx ...")
|
||||
local ok, ret, errors, ctx = helpers.fill_ctx()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "fill_ctx() failed : " .. ret)
|
||||
elseif errors then
|
||||
for i, error in ipairs(errors) do
|
||||
logger:log(ngx.ERR, "fill_ctx() error " .. tostring(i) .. " : " .. error)
|
||||
end
|
||||
end
|
||||
logger:log(ngx.INFO, "ngx.ctx filled (ret = " .. ret .. ")")
|
||||
|
||||
-- Get plugins order
|
||||
local order, err = datastore:get("plugins_order", true)
|
||||
if not order then
|
||||
logger:log(ngx.ERR, "can't get plugins order from datastore : " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
-- Call log() methods
|
||||
logger:log(ngx.INFO, "calling log() methods of plugins ...")
|
||||
for i, plugin_id in ipairs(order.log) do
|
||||
-- Require call
|
||||
local plugin_lua, err = helpers.require_plugin(plugin_id)
|
||||
if plugin_lua == false then
|
||||
logger:log(ngx.ERR, err)
|
||||
elseif plugin_lua == nil then
|
||||
logger:log(ngx.INFO, err)
|
||||
else
|
||||
-- Check if plugin has log method
|
||||
if plugin_lua.log ~= nil then
|
||||
-- New call
|
||||
local ok, plugin_obj = helpers.new_plugin(plugin_lua, ctx)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, plugin_obj)
|
||||
else
|
||||
local ok, ret = helpers.call_plugin(plugin_obj, "log")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
logger:log(ngx.ERR, plugin_id .. ":log() call failed : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.INFO, plugin_id .. ":log() call successful : " .. ret.msg)
|
||||
end
|
||||
end
|
||||
else
|
||||
logger:log(ngx.INFO, "skipped execution of " .. plugin_id .. " because method log() is not defined")
|
||||
-- Fill ctx
|
||||
logger:log(ngx.INFO, "filling ngx.ctx ...")
|
||||
local ok, ret, errors, ctx = helpers.fill_ctx()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "fill_ctx() failed : " .. ret)
|
||||
elseif errors then
|
||||
for i, error in ipairs(errors) do
|
||||
logger:log(ngx.ERR, "fill_ctx() error " .. tostring(i) .. " : " .. error)
|
||||
end
|
||||
end
|
||||
end
|
||||
logger:log(ngx.INFO, "called log() methods of plugins")
|
||||
logger:log(ngx.INFO, "ngx.ctx filled (ret = " .. ret .. ")")
|
||||
|
||||
-- Display reason at info level
|
||||
if ctx.reason then
|
||||
logger:log(ngx.INFO, "client was denied with reason : " .. ctx.reason)
|
||||
end
|
||||
-- Get plugins order
|
||||
local order, err = datastore:get("plugins_order", true)
|
||||
if not order then
|
||||
logger:log(ngx.ERR, "can't get plugins order from datastore : " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
-- Save ctx
|
||||
ngx.ctx = ctx
|
||||
-- Call log() methods
|
||||
logger:log(ngx.INFO, "calling log() methods of plugins ...")
|
||||
for i, plugin_id in ipairs(order.log) do
|
||||
-- Require call
|
||||
local plugin_lua, err = helpers.require_plugin(plugin_id)
|
||||
if plugin_lua == false then
|
||||
logger:log(ngx.ERR, err)
|
||||
elseif plugin_lua == nil then
|
||||
logger:log(ngx.INFO, err)
|
||||
else
|
||||
-- Check if plugin has log method
|
||||
if plugin_lua.log ~= nil then
|
||||
-- New call
|
||||
local ok, plugin_obj = helpers.new_plugin(plugin_lua, ctx)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, plugin_obj)
|
||||
else
|
||||
local ok, ret = helpers.call_plugin(plugin_obj, "log")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
logger:log(ngx.ERR, plugin_id .. ":log() call failed : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.INFO, plugin_id .. ":log() call successful : " .. ret.msg)
|
||||
end
|
||||
end
|
||||
else
|
||||
logger:log(ngx.INFO, "skipped execution of " .. plugin_id .. " because method log() is not defined")
|
||||
end
|
||||
end
|
||||
end
|
||||
logger:log(ngx.INFO, "called log() methods of plugins")
|
||||
|
||||
logger:log(ngx.INFO, "log phase ended")
|
||||
-- Display reason at info level
|
||||
if ctx.reason then
|
||||
logger:log(ngx.INFO, "client was denied with reason : " .. ctx.reason)
|
||||
end
|
||||
|
||||
-- Save ctx
|
||||
ngx.ctx = ctx
|
||||
|
||||
logger:log(ngx.INFO, "log phase ended")
|
||||
}
|
||||
|
|
@ -1,86 +1,84 @@
|
|||
set $dummy_set "";
|
||||
set_by_lua_block $dummy_set {
|
||||
local class = require "middleclass"
|
||||
local clogger = require "bunkerweb.logger"
|
||||
local helpers = require "bunkerweb.helpers"
|
||||
local cdatastore = require "bunkerweb.datastore"
|
||||
local ccachestore = require "bunkerweb.cachestore"
|
||||
local cjson = require "cjson"
|
||||
|
||||
local class = require "middleclass"
|
||||
local clogger = require "bunkerweb.logger"
|
||||
local helpers = require "bunkerweb.helpers"
|
||||
local cdatastore = require "bunkerweb.datastore"
|
||||
local ccachestore = require "bunkerweb.cachestore"
|
||||
local cjson = require "cjson"
|
||||
|
||||
-- Don't process internal requests
|
||||
local logger = clogger:new("SET")
|
||||
if ngx.req.is_internal() then
|
||||
logger:log(ngx.INFO, "skipped set phase because request is internal")
|
||||
return true
|
||||
end
|
||||
|
||||
-- Start set phase
|
||||
local datastore = cdatastore:new()
|
||||
logger:log(ngx.INFO, "set phase started")
|
||||
|
||||
-- Update cachestore only once and before any other code
|
||||
local cachestore = ccachestore:new()
|
||||
local ok, err = cachestore.cache:update()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't update cachestore : " .. err)
|
||||
end
|
||||
|
||||
-- Fill ctx
|
||||
logger:log(ngx.INFO, "filling ngx.ctx ...")
|
||||
local ok, ret, errors, ctx = helpers.fill_ctx()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "fill_ctx() failed : " .. ret)
|
||||
elseif errors then
|
||||
for i, error in ipairs(errors) do
|
||||
logger:log(ngx.ERR, "fill_ctx() error " .. tostring(i) .. " : " .. error)
|
||||
-- Don't process internal requests
|
||||
local logger = clogger:new("SET")
|
||||
if ngx.req.is_internal() then
|
||||
logger:log(ngx.INFO, "skipped set phase because request is internal")
|
||||
return true
|
||||
end
|
||||
end
|
||||
logger:log(ngx.INFO, "ngx.ctx filled (ret = " .. ret .. ")")
|
||||
|
||||
-- Get plugins order
|
||||
local order, err = datastore:get("plugins_order", true)
|
||||
if not order then
|
||||
logger:log(ngx.ERR, "can't get plugins order from datastore : " .. err)
|
||||
return
|
||||
end
|
||||
-- Start set phase
|
||||
local datastore = cdatastore:new()
|
||||
logger:log(ngx.INFO, "set phase started")
|
||||
|
||||
-- Call set() methods
|
||||
logger:log(ngx.INFO, "calling set() methods of plugins ...")
|
||||
for i, plugin_id in ipairs(order.set) do
|
||||
-- Require call
|
||||
local plugin_lua, err = helpers.require_plugin(plugin_id)
|
||||
if plugin_lua == false then
|
||||
logger:log(ngx.ERR, err)
|
||||
elseif plugin_lua == nil then
|
||||
logger:log(ngx.INFO, err)
|
||||
else
|
||||
-- Check if plugin has set method
|
||||
if plugin_lua.set ~= nil then
|
||||
-- New call
|
||||
local ok, plugin_obj = helpers.new_plugin(plugin_lua, ctx)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, plugin_obj)
|
||||
else
|
||||
local ok, ret = helpers.call_plugin(plugin_obj, "set")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
logger:log(ngx.ERR, plugin_id .. ":set() call failed : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.INFO, plugin_id .. ":set() call successful : " .. ret.msg)
|
||||
end
|
||||
end
|
||||
else
|
||||
logger:log(ngx.INFO, "skipped execution of " .. plugin_id .. " because method set() is not defined")
|
||||
-- Update cachestore only once and before any other code
|
||||
local cachestore = ccachestore:new()
|
||||
local ok, err = cachestore.cache:update()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "can't update cachestore : " .. err)
|
||||
end
|
||||
|
||||
-- Fill ctx
|
||||
logger:log(ngx.INFO, "filling ngx.ctx ...")
|
||||
local ok, ret, errors, ctx = helpers.fill_ctx()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "fill_ctx() failed : " .. ret)
|
||||
elseif errors then
|
||||
for i, error in ipairs(errors) do
|
||||
logger:log(ngx.ERR, "fill_ctx() error " .. tostring(i) .. " : " .. error)
|
||||
end
|
||||
end
|
||||
end
|
||||
logger:log(ngx.INFO, "called set() methods of plugins")
|
||||
logger:log(ngx.INFO, "ngx.ctx filled (ret = " .. ret .. ")")
|
||||
|
||||
-- Save ctx
|
||||
ngx.ctx = ctx
|
||||
-- Get plugins order
|
||||
local order, err = datastore:get("plugins_order", true)
|
||||
if not order then
|
||||
logger:log(ngx.ERR, "can't get plugins order from datastore : " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
return true
|
||||
-- Call set() methods
|
||||
logger:log(ngx.INFO, "calling set() methods of plugins ...")
|
||||
for i, plugin_id in ipairs(order.set) do
|
||||
-- Require call
|
||||
local plugin_lua, err = helpers.require_plugin(plugin_id)
|
||||
if plugin_lua == false then
|
||||
logger:log(ngx.ERR, err)
|
||||
elseif plugin_lua == nil then
|
||||
logger:log(ngx.INFO, err)
|
||||
else
|
||||
-- Check if plugin has set method
|
||||
if plugin_lua.set ~= nil then
|
||||
-- New call
|
||||
local ok, plugin_obj = helpers.new_plugin(plugin_lua, ctx)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, plugin_obj)
|
||||
else
|
||||
local ok, ret = helpers.call_plugin(plugin_obj, "set")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
logger:log(ngx.ERR, plugin_id .. ":set() call failed : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.INFO, plugin_id .. ":set() call successful : " .. ret.msg)
|
||||
end
|
||||
end
|
||||
else
|
||||
logger:log(ngx.INFO, "skipped execution of " .. plugin_id .. " because method set() is not defined")
|
||||
end
|
||||
end
|
||||
end
|
||||
logger:log(ngx.INFO, "called set() methods of plugins")
|
||||
|
||||
}
|
||||
-- Save ctx
|
||||
ngx.ctx = ctx
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,76 +1,74 @@
|
|||
log_by_lua_block {
|
||||
local class = require "middleclass"
|
||||
local clogger = require "bunkerweb.logger"
|
||||
local helpers = require "bunkerweb.helpers"
|
||||
local cdatastore = require "bunkerweb.datastore"
|
||||
local cjson = require "cjson"
|
||||
|
||||
local class = require "middleclass"
|
||||
local clogger = require "bunkerweb.logger"
|
||||
local helpers = require "bunkerweb.helpers"
|
||||
local cdatastore = require "bunkerweb.datastore"
|
||||
local cjson = require "cjson"
|
||||
-- Start log phase
|
||||
local logger = clogger:new("LOG")
|
||||
local datastore = cdatastore:new()
|
||||
logger:log(ngx.INFO, "log phase started")
|
||||
|
||||
-- Start log phase
|
||||
local logger = clogger:new("LOG")
|
||||
local datastore = cdatastore:new()
|
||||
logger:log(ngx.INFO, "log phase started")
|
||||
|
||||
-- Fill ctx
|
||||
logger:log(ngx.INFO, "filling ngx.ctx ...")
|
||||
local ok, ret, errors, ctx = helpers.fill_ctx()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "fill_ctx() failed : " .. ret)
|
||||
elseif errors then
|
||||
for i, error in ipairs(errors) do
|
||||
logger:log(ngx.ERR, "fill_ctx() error " .. tostring(i) .. " : " .. error)
|
||||
end
|
||||
end
|
||||
logger:log(ngx.INFO, "ngx.ctx filled (ret = " .. ret .. ")")
|
||||
|
||||
-- Get plugins order
|
||||
local order, err = datastore:get("plugins_order", true)
|
||||
if not order then
|
||||
logger:log(ngx.ERR, "can't get plugins order from datastore : " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
-- Call log_stream() methods
|
||||
logger:log(ngx.INFO, "calling log_stream() methods of plugins ...")
|
||||
for i, plugin_id in ipairs(order.log_stream) do
|
||||
-- Require call
|
||||
local plugin_lua, err = helpers.require_plugin(plugin_id)
|
||||
if plugin_lua == false then
|
||||
logger:log(ngx.ERR, err)
|
||||
elseif plugin_lua == nil then
|
||||
logger:log(ngx.INFO, err)
|
||||
else
|
||||
-- Check if plugin has log_stream method
|
||||
if plugin_lua.log_stream ~= nil then
|
||||
-- New call
|
||||
local ok, plugin_obj = helpers.new_plugin(plugin_lua, ctx)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, plugin_obj)
|
||||
else
|
||||
local ok, ret = helpers.call_plugin(plugin_obj, "log_stream")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
logger:log(ngx.ERR, plugin_id .. ":log_stream() call failed : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.INFO, plugin_id .. ":log_stream() call successful : " .. ret.msg)
|
||||
end
|
||||
end
|
||||
else
|
||||
logger:log(ngx.INFO, "skipped execution of " .. plugin_id .. " because method log_stream() is not defined")
|
||||
-- Fill ctx
|
||||
logger:log(ngx.INFO, "filling ngx.ctx ...")
|
||||
local ok, ret, errors, ctx = helpers.fill_ctx()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "fill_ctx() failed : " .. ret)
|
||||
elseif errors then
|
||||
for i, error in ipairs(errors) do
|
||||
logger:log(ngx.ERR, "fill_ctx() error " .. tostring(i) .. " : " .. error)
|
||||
end
|
||||
end
|
||||
end
|
||||
logger:log(ngx.INFO, "called log_stream() methods of plugins")
|
||||
logger:log(ngx.INFO, "ngx.ctx filled (ret = " .. ret .. ")")
|
||||
|
||||
-- Display reason at info level
|
||||
if ctx.reason then
|
||||
logger:log(ngx.INFO, "client was denied with reason : " .. ctx.reason)
|
||||
end
|
||||
-- Get plugins order
|
||||
local order, err = datastore:get("plugins_order", true)
|
||||
if not order then
|
||||
logger:log(ngx.ERR, "can't get plugins order from datastore : " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
-- Save ctx
|
||||
ngx.ctx = ctx
|
||||
-- Call log_stream() methods
|
||||
logger:log(ngx.INFO, "calling log_stream() methods of plugins ...")
|
||||
for i, plugin_id in ipairs(order.log_stream) do
|
||||
-- Require call
|
||||
local plugin_lua, err = helpers.require_plugin(plugin_id)
|
||||
if plugin_lua == false then
|
||||
logger:log(ngx.ERR, err)
|
||||
elseif plugin_lua == nil then
|
||||
logger:log(ngx.INFO, err)
|
||||
else
|
||||
-- Check if plugin has log_stream method
|
||||
if plugin_lua.log_stream ~= nil then
|
||||
-- New call
|
||||
local ok, plugin_obj = helpers.new_plugin(plugin_lua, ctx)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, plugin_obj)
|
||||
else
|
||||
local ok, ret = helpers.call_plugin(plugin_obj, "log_stream")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
logger:log(ngx.ERR, plugin_id .. ":log_stream() call failed : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.INFO, plugin_id .. ":log_stream() call successful : " .. ret.msg)
|
||||
end
|
||||
end
|
||||
else
|
||||
logger:log(ngx.INFO, "skipped execution of " .. plugin_id .. " because method log_stream() is not defined")
|
||||
end
|
||||
end
|
||||
end
|
||||
logger:log(ngx.INFO, "called log_stream() methods of plugins")
|
||||
|
||||
logger:log(ngx.INFO, "log phase ended")
|
||||
-- Display reason at info level
|
||||
if ctx.reason then
|
||||
logger:log(ngx.INFO, "client was denied with reason : " .. ctx.reason)
|
||||
end
|
||||
|
||||
}
|
||||
-- Save ctx
|
||||
ngx.ctx = ctx
|
||||
|
||||
logger:log(ngx.INFO, "log phase ended")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,104 +1,104 @@
|
|||
preread_by_lua_block {
|
||||
ngx.ctx
|
||||
local class = require "middleclass"
|
||||
local clogger = require "bunkerweb.logger"
|
||||
local helpers = require "bunkerweb.helpers"
|
||||
local utils = require "bunkerweb.utils"
|
||||
local cdatastore = require "bunkerweb.datastore"
|
||||
local cclusterstore = require "bunkerweb.clusterstore"
|
||||
local cjson = require "cjson"
|
||||
ngx.ctx
|
||||
local class = require "middleclass"
|
||||
local clogger = require "bunkerweb.logger"
|
||||
local helpers = require "bunkerweb.helpers"
|
||||
local utils = require "bunkerweb.utils"
|
||||
local cdatastore = require "bunkerweb.datastore"
|
||||
local cclusterstore = require "bunkerweb.clusterstore"
|
||||
local cjson = require "cjson"
|
||||
|
||||
-- Start preread phase
|
||||
local logger = clogger:new("PREREAD")
|
||||
local datastore = cdatastore:new()
|
||||
logger:log(ngx.INFO, "preread phase started")
|
||||
-- Start preread phase
|
||||
local logger = clogger:new("PREREAD")
|
||||
local datastore = cdatastore:new()
|
||||
logger:log(ngx.INFO, "preread phase started")
|
||||
|
||||
-- Fill ctx
|
||||
logger:log(ngx.INFO, "filling ngx.ctx ...")
|
||||
local ok, ret, errors, ctx = helpers.fill_ctx()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "fill_ctx() failed : " .. ret)
|
||||
elseif errors then
|
||||
for i, error in ipairs(errors) do
|
||||
logger:log(ngx.ERR, "fill_ctx() error " .. tostring(i) .. " : " .. error)
|
||||
end
|
||||
end
|
||||
logger:log(ngx.INFO, "ngx.ctx filled (ret = " .. ret .. ")")
|
||||
|
||||
-- Process bans as soon as possible
|
||||
if ctx.bw.is_whitelisted ~= "yes" then
|
||||
local banned, reason, ttl = utils.is_banned(ctx.bw.remote_addr)
|
||||
if banned == nil then
|
||||
logger:log(ngx.ERR, "can't check if IP " .. ctx.bw.remote_addr .. " is banned : " .. reason)
|
||||
elseif banned then
|
||||
logger:log(ngx.WARN, "IP " .. ctx.bw.remote_addr .. " is banned with reason " .. reason .. " (" .. tostring(ttl) .. "s remaining)")
|
||||
return ngx.exit(utils.get_deny_status())
|
||||
else
|
||||
logger:log(ngx.INFO, "IP " .. ctx.bw.remote_addr .. " is not banned")
|
||||
end
|
||||
end
|
||||
|
||||
-- Get plugins order
|
||||
local order, err = datastore:get("plugins_order", true)
|
||||
if not order then
|
||||
logger:log(ngx.ERR, "can't get plugins order from datastore : " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
-- Call preread() methods
|
||||
logger:log(ngx.INFO, "calling preread() methods of plugins ...")
|
||||
local status = nil
|
||||
for i, plugin_id in ipairs(order.preread) do
|
||||
-- Require call
|
||||
local plugin_lua, err = helpers.require_plugin(plugin_id)
|
||||
if plugin_lua == false then
|
||||
logger:log(ngx.ERR, err)
|
||||
elseif plugin_lua == nil then
|
||||
logger:log(ngx.INFO, err)
|
||||
else
|
||||
-- Check if plugin has preread method
|
||||
if plugin_lua.preread ~= nil then
|
||||
-- New call
|
||||
local ok, plugin_obj = helpers.new_plugin(plugin_lua, ctx)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, plugin_obj)
|
||||
else
|
||||
local ok, ret = helpers.call_plugin(plugin_obj, "preread")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
logger:log(ngx.ERR, plugin_id .. ":preread() call failed : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.INFO, plugin_id .. ":preread() call successful : " .. ret.msg)
|
||||
end
|
||||
if ret.status then
|
||||
if ret.status == utils.get_deny_status(ctx) then
|
||||
ctx.bw.reason = plugin_id
|
||||
logger:log(ngx.WARN, "denied preread from " .. plugin_id .. " : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.NOTICE, plugin_id .. " returned status " .. tostring(ret.status) .. " : " .. ret.msg)
|
||||
end
|
||||
status = ret.status
|
||||
break
|
||||
end
|
||||
end
|
||||
else
|
||||
logger:log(ngx.INFO, "skipped execution of " .. plugin_id .. " because method preread() is not defined")
|
||||
-- Fill ctx
|
||||
logger:log(ngx.INFO, "filling ngx.ctx ...")
|
||||
local ok, ret, errors, ctx = helpers.fill_ctx()
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, "fill_ctx() failed : " .. ret)
|
||||
elseif errors then
|
||||
for i, error in ipairs(errors) do
|
||||
logger:log(ngx.ERR, "fill_ctx() error " .. tostring(i) .. " : " .. error)
|
||||
end
|
||||
end
|
||||
end
|
||||
logger:log(ngx.INFO, "called preread() methods of plugins")
|
||||
logger:log(ngx.INFO, "ngx.ctx filled (ret = " .. ret .. ")")
|
||||
|
||||
-- Save ctx
|
||||
ngx.ctx = ctx
|
||||
-- Process bans as soon as possible
|
||||
if ctx.bw.is_whitelisted ~= "yes" then
|
||||
local banned, reason, ttl = utils.is_banned(ctx.bw.remote_addr)
|
||||
if banned == nil then
|
||||
logger:log(ngx.ERR, "can't check if IP " .. ctx.bw.remote_addr .. " is banned : " .. reason)
|
||||
elseif banned then
|
||||
logger:log(ngx.WARN,
|
||||
"IP " .. ctx.bw.remote_addr .. " is banned with reason " .. reason .. " (" .. tostring(ttl) .. "s remaining)")
|
||||
return ngx.exit(utils.get_deny_status())
|
||||
else
|
||||
logger:log(ngx.INFO, "IP " .. ctx.bw.remote_addr .. " is not banned")
|
||||
end
|
||||
end
|
||||
|
||||
logger:log(ngx.INFO, "preread phase ended")
|
||||
-- Get plugins order
|
||||
local order, err = datastore:get("plugins_order", true)
|
||||
if not order then
|
||||
logger:log(ngx.ERR, "can't get plugins order from datastore : " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
-- Return status if needed
|
||||
if status then
|
||||
return ngx.exit(status)
|
||||
end
|
||||
-- Call preread() methods
|
||||
logger:log(ngx.INFO, "calling preread() methods of plugins ...")
|
||||
local status = nil
|
||||
for i, plugin_id in ipairs(order.preread) do
|
||||
-- Require call
|
||||
local plugin_lua, err = helpers.require_plugin(plugin_id)
|
||||
if plugin_lua == false then
|
||||
logger:log(ngx.ERR, err)
|
||||
elseif plugin_lua == nil then
|
||||
logger:log(ngx.INFO, err)
|
||||
else
|
||||
-- Check if plugin has preread method
|
||||
if plugin_lua.preread ~= nil then
|
||||
-- New call
|
||||
local ok, plugin_obj = helpers.new_plugin(plugin_lua, ctx)
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, plugin_obj)
|
||||
else
|
||||
local ok, ret = helpers.call_plugin(plugin_obj, "preread")
|
||||
if not ok then
|
||||
logger:log(ngx.ERR, ret)
|
||||
elseif not ret.ret then
|
||||
logger:log(ngx.ERR, plugin_id .. ":preread() call failed : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.INFO, plugin_id .. ":preread() call successful : " .. ret.msg)
|
||||
end
|
||||
if ret.status then
|
||||
if ret.status == utils.get_deny_status(ctx) then
|
||||
ctx.bw.reason = plugin_id
|
||||
logger:log(ngx.WARN, "denied preread from " .. plugin_id .. " : " .. ret.msg)
|
||||
else
|
||||
logger:log(ngx.NOTICE, plugin_id .. " returned status " .. tostring(ret.status) .. " : " .. ret.msg)
|
||||
end
|
||||
status = ret.status
|
||||
break
|
||||
end
|
||||
end
|
||||
else
|
||||
logger:log(ngx.INFO, "skipped execution of " .. plugin_id .. " because method preread() is not defined")
|
||||
end
|
||||
end
|
||||
end
|
||||
logger:log(ngx.INFO, "called preread() methods of plugins")
|
||||
|
||||
return true
|
||||
-- Save ctx
|
||||
ngx.ctx = ctx
|
||||
|
||||
}
|
||||
logger:log(ngx.INFO, "preread phase ended")
|
||||
|
||||
-- Return status if needed
|
||||
if status then
|
||||
return ngx.exit(status)
|
||||
end
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -465,6 +465,8 @@ class Database:
|
|||
).delete()
|
||||
|
||||
if config:
|
||||
config.pop("DATABASE_URI", None)
|
||||
|
||||
if config.get("MULTISITE", "no") == "yes":
|
||||
global_values = []
|
||||
db_services = (
|
||||
|
|
|
|||
|
|
@ -223,6 +223,8 @@ if __name__ == "__main__":
|
|||
logger.info(
|
||||
f"Found custom conf env var {'for service ' + custom_conf[0] if custom_conf[0] else 'without service'} with type {custom_conf[1]} and name {custom_conf[2]}"
|
||||
)
|
||||
|
||||
db = Database(logger, config_files.get("DATABASE_URI", None))
|
||||
else:
|
||||
docker_client = DockerClient(
|
||||
base_url=getenv("DOCKER_HOST", "unix:///var/run/docker.sock")
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ cleanup_stack () {
|
|||
|
||||
echo "🤖 Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🤖 Down failed ❌"
|
||||
|
|
@ -54,13 +54,13 @@ do
|
|||
fi
|
||||
|
||||
echo "🤖 Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🤖 Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🤖 Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -95,7 +95,7 @@ do
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🤖 Test \"$test\" failed ❌"
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ cleanup_stack () {
|
|||
|
||||
echo "🔐 Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🔐 Down failed ❌"
|
||||
|
|
@ -63,13 +63,13 @@ do
|
|||
fi
|
||||
|
||||
echo "🔐 Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🔐 Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🔐 Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -104,7 +104,7 @@ do
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🔐 Test \"$test\" failed ❌"
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ services:
|
|||
- "www.example.com:192.168.0.2"
|
||||
networks:
|
||||
bw-docker:
|
||||
ipv4_address: 10.10.10.4
|
||||
bw-services:
|
||||
ipv4_address: 192.168.0.3
|
||||
|
||||
|
|
|
|||
|
|
@ -36,8 +36,9 @@ services:
|
|||
DOCKER_HOST: "tcp://bw-docker:2375"
|
||||
LOG_LEVEL: "info"
|
||||
networks:
|
||||
- bw-universe
|
||||
- bw-docker
|
||||
bw-universe:
|
||||
bw-docker:
|
||||
ipv4_address: 10.10.10.3
|
||||
|
||||
bw-docker:
|
||||
image: tecnativa/docker-socket-proxy
|
||||
|
|
@ -46,7 +47,8 @@ services:
|
|||
environment:
|
||||
CONTAINERS: "1"
|
||||
networks:
|
||||
- bw-docker
|
||||
bw-docker:
|
||||
ipv4_address: 10.10.10.2
|
||||
|
||||
networks:
|
||||
bw-universe:
|
||||
|
|
@ -63,3 +65,7 @@ networks:
|
|||
- subnet: 192.168.0.0/24
|
||||
bw-docker:
|
||||
name: bw-docker
|
||||
ipam:
|
||||
driver: default
|
||||
config:
|
||||
- subnet: 10.10.10.0/24
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ cleanup_stack () {
|
|||
|
||||
echo "📟 Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "📟 Down failed ❌"
|
||||
|
|
@ -70,13 +70,13 @@ do
|
|||
fi
|
||||
|
||||
echo "📟 Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "📟 Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "📟 Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -111,7 +111,7 @@ do
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "📟 Test \"$test\" failed ❌"
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ cleanup_stack () {
|
|||
|
||||
echo "🏴 Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🏴 Down failed ❌"
|
||||
|
|
@ -198,13 +198,13 @@ do
|
|||
fi
|
||||
|
||||
echo "🏴 Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🏴 Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🏴 Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -240,9 +240,9 @@ do
|
|||
# Start tests
|
||||
|
||||
if [[ "$test" = "asn" || "$test" = "ignore_asn" || "$test" = "ignore_asn_urls" || "$test" = "asn_urls" ]] ; then
|
||||
docker compose -f docker-compose.test.yml up global-tests --abort-on-container-exit --exit-code-from global-tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up global-tests --abort-on-container-exit --exit-code-from global-tests
|
||||
else
|
||||
docker compose -f docker-compose.test.yml up tests --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up tests --abort-on-container-exit --exit-code-from tests
|
||||
fi
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ cleanup_stack () {
|
|||
|
||||
echo "📦 Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "📦 Down failed ❌"
|
||||
|
|
@ -50,13 +50,13 @@ do
|
|||
fi
|
||||
|
||||
echo "📦 Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "📦 Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "📦 Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -91,7 +91,7 @@ do
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "📦 Test \"$test\" failed ❌"
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ cleanup_stack () {
|
|||
|
||||
echo "🕸️ Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🕸️ Down failed ❌"
|
||||
|
|
@ -59,13 +59,13 @@ do
|
|||
fi
|
||||
|
||||
echo "🕸️ Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🕸️ Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🕸️ Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -100,7 +100,7 @@ do
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🕸️ Test \"$test\" failed ❌"
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ fi
|
|||
cleanup_stack () {
|
||||
echo "⌨️ Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "⌨️ Down failed ❌"
|
||||
|
|
@ -33,13 +33,13 @@ trap cleanup_stack EXIT
|
|||
echo "⌨️ Running bwcli tests ..."
|
||||
|
||||
echo "⌨️ Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "⌨️ Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "⌨️ Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -74,7 +74,7 @@ if [ $i -ge 120 ] ; then
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "⌨️ Test bwcli failed ❌"
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ cleanup_stack () {
|
|||
|
||||
echo "📝 Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "📝 Down failed ❌"
|
||||
|
|
@ -64,13 +64,13 @@ do
|
|||
fi
|
||||
|
||||
echo "📝 Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "📝 Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "📝 Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -105,7 +105,7 @@ do
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "📝 Test \"$test\" failed ❌"
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ cleanup_stack () {
|
|||
|
||||
echo "🛰️ Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🛰️ Down failed ❌"
|
||||
|
|
@ -79,13 +79,13 @@ do
|
|||
fi
|
||||
|
||||
echo "🛰️ Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🛰️ Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🛰️ Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -120,7 +120,7 @@ do
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🛰️ Test \"$test\" failed ❌"
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ cleanup_stack () {
|
|||
|
||||
echo "🌍 Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🌍 Down failed ❌"
|
||||
|
|
@ -55,13 +55,13 @@ do
|
|||
fi
|
||||
|
||||
echo "🌍 Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🌍 Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🌍 Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -97,7 +97,7 @@ do
|
|||
# Start tests
|
||||
|
||||
echo "🌍 Starting the FR container"
|
||||
docker compose -f docker-compose.test.yml up tests-fr --abort-on-container-exit --exit-code-from tests-fr 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up tests-fr --abort-on-container-exit --exit-code-from tests-fr
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🌍 Test \"$test\" failed for the FR container ❌"
|
||||
|
|
@ -109,7 +109,7 @@ do
|
|||
fi
|
||||
|
||||
echo "🌍 Starting the US container"
|
||||
docker compose -f docker-compose.test.yml up tests-us --abort-on-container-exit --exit-code-from tests-us 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up tests-us --abort-on-container-exit --exit-code-from tests-us
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🌍 Test \"$test\" failed for the US container ❌"
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ cleanup_stack () {
|
|||
|
||||
echo "🔏 Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🔏 Down failed ❌"
|
||||
|
|
@ -66,13 +66,13 @@ do
|
|||
fi
|
||||
|
||||
echo "🔏 Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🔏 Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🔏 Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -107,7 +107,7 @@ do
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🔏 Test \"$test\" failed ❌"
|
||||
|
|
|
|||
16
tests/core/db/docker-compose.mariadb.yml
Normal file
16
tests/core/db/docker-compose.mariadb.yml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
version: "3.5"
|
||||
|
||||
services:
|
||||
bw-db:
|
||||
image: mariadb:10.10
|
||||
environment:
|
||||
- MYSQL_RANDOM_ROOT_PASSWORD=yes
|
||||
- MYSQL_DATABASE=db
|
||||
- MYSQL_USER=bunkerweb
|
||||
- MYSQL_PASSWORD=secret
|
||||
networks:
|
||||
- bw-docker
|
||||
|
||||
networks:
|
||||
bw-docker:
|
||||
external: true
|
||||
16
tests/core/db/docker-compose.mysql.yml
Normal file
16
tests/core/db/docker-compose.mysql.yml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
version: "3.5"
|
||||
|
||||
services:
|
||||
bw-db:
|
||||
image: mysql:8.0
|
||||
environment:
|
||||
- MYSQL_RANDOM_ROOT_PASSWORD=yes
|
||||
- MYSQL_DATABASE=db
|
||||
- MYSQL_USER=bunkerweb
|
||||
- MYSQL_PASSWORD=secret
|
||||
networks:
|
||||
- bw-docker
|
||||
|
||||
networks:
|
||||
bw-docker:
|
||||
external: true
|
||||
15
tests/core/db/docker-compose.postgres.yml
Normal file
15
tests/core/db/docker-compose.postgres.yml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
version: "3.5"
|
||||
|
||||
services:
|
||||
bw-db:
|
||||
image: postgres:15.1
|
||||
environment:
|
||||
- POSTGRES_USER=bunkerweb
|
||||
- POSTGRES_PASSWORD=secret
|
||||
- POSTGRES_DB=db
|
||||
networks:
|
||||
- bw-docker
|
||||
|
||||
networks:
|
||||
bw-docker:
|
||||
external: true
|
||||
|
|
@ -57,35 +57,6 @@ services:
|
|||
bw-services:
|
||||
ipv4_address: 192.168.0.4
|
||||
|
||||
bw-maria-db:
|
||||
image: mariadb:10.10
|
||||
environment:
|
||||
- MYSQL_RANDOM_ROOT_PASSWORD=yes
|
||||
- MYSQL_DATABASE=db
|
||||
- MYSQL_USER=bunkerweb
|
||||
- MYSQL_PASSWORD=secret
|
||||
networks:
|
||||
- bw-docker
|
||||
|
||||
bw-mysql-db:
|
||||
image: mysql:8.0
|
||||
environment:
|
||||
- MYSQL_RANDOM_ROOT_PASSWORD=yes
|
||||
- MYSQL_DATABASE=db
|
||||
- MYSQL_USER=bunkerweb
|
||||
- MYSQL_PASSWORD=secret
|
||||
networks:
|
||||
- bw-docker
|
||||
|
||||
bw-postgres-db:
|
||||
image: postgres:15.1
|
||||
environment:
|
||||
- POSTGRES_USER=bunkerweb
|
||||
- POSTGRES_PASSWORD=secret
|
||||
- POSTGRES_DB=db
|
||||
networks:
|
||||
- bw-docker
|
||||
|
||||
volumes:
|
||||
bw-data:
|
||||
name: bw-data
|
||||
|
|
@ -106,4 +77,4 @@ networks:
|
|||
config:
|
||||
- subnet: 192.168.0.0/24
|
||||
bw-docker:
|
||||
name: bw-docker
|
||||
external: true
|
||||
|
|
|
|||
|
|
@ -3,7 +3,25 @@
|
|||
echo "💾 Building db stack ..."
|
||||
|
||||
# Starting stack
|
||||
docker compose pull bw-docker app1 bw-maria-db bw-mysql-db bw-postgres-db
|
||||
docker compose pull bw-docker app1
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💾 Pull failed ❌"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
docker compose -f docker-compose.mariadb.yml pull bw-db
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💾 Pull failed ❌"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
docker compose -f docker-compose.mysql.yml pull bw-db
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💾 Pull failed ❌"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
docker compose -f docker-compose.postgres.yml pull bw-db
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💾 Pull failed ❌"
|
||||
exit 1
|
||||
|
|
@ -48,7 +66,7 @@ cleanup_stack () {
|
|||
|
||||
echo "💾 Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💾 Down failed ❌"
|
||||
|
|
@ -61,14 +79,17 @@ cleanup_stack () {
|
|||
# Cleanup stack on exit
|
||||
trap cleanup_stack EXIT
|
||||
|
||||
echo "💾 Creating the bw-docker network ..."
|
||||
docker network create bw-docker
|
||||
|
||||
echo "💾 Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💾 Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💾 Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -108,6 +129,9 @@ fi
|
|||
|
||||
for test in "local" "multisite" "mariadb" "mysql" "postgres"
|
||||
do
|
||||
echo "💾 Creating the bw-docker network ..."
|
||||
docker network create bw-docker
|
||||
|
||||
if [ "$test" = "local" ] ; then
|
||||
echo "💾 Running tests with a local database ..."
|
||||
elif [ "$test" = "multisite" ] ; then
|
||||
|
|
@ -126,25 +150,86 @@ do
|
|||
elif [ "$test" = "mariadb" ] ; then
|
||||
echo "💾 Running tests with MariaDB database ..."
|
||||
echo "ℹ️ Keeping the MULTISITE variable to yes and multisite settings ..."
|
||||
find . -type f -name 'docker-compose.*' -exec sed -i 's@DATABASE_URI: ".*"$@DATABASE_URI: "mariadb+pymysql://bunkerweb:secret\@bw-maria-db:3306/db"@' {} \;
|
||||
find . -type f -name 'docker-compose.*' -exec sed -i 's@DATABASE_URI: ".*"$@DATABASE_URI: "mariadb+pymysql://bunkerweb:secret\@bw-db:3306/db"@' {} \;
|
||||
|
||||
echo "💾 Starting mariadb ..."
|
||||
docker compose -f docker-compose.mariadb.yml up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💾 Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose -f docker-compose.mariadb.yml up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💾 Up failed ❌"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
elif [ "$test" = "mysql" ] ; then
|
||||
echo "💾 Running tests with MySQL database ..."
|
||||
echo "ℹ️ Keeping the MULTISITE variable to yes and multisite settings ..."
|
||||
find . -type f -name 'docker-compose.*' -exec sed -i 's@DATABASE_URI: ".*"$@DATABASE_URI: "mysql+pymysql://bunkerweb:secret\@bw-mysql-db:3306/db"@' {} \;
|
||||
find . -type f -name 'docker-compose.*' -exec sed -i 's@DATABASE_URI: ".*"$@DATABASE_URI: "mysql+pymysql://bunkerweb:secret\@bw-db:3306/db"@' {} \;
|
||||
|
||||
echo "💾 Starting mysql ..."
|
||||
docker compose -f docker-compose.mysql.yml up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💾 Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose -f docker-compose.mysql.yml up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💾 Up failed ❌"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
elif [ "$test" = "postgres" ] ; then
|
||||
echo "💾 Running tests with PostgreSQL database ..."
|
||||
echo "ℹ️ Keeping the MULTISITE variable to yes and multisite settings ..."
|
||||
find . -type f -name 'docker-compose.*' -exec sed -i 's@DATABASE_URI: ".*"$@DATABASE_URI: "postgresql://bunkerweb:secret\@bw-postgres-db:5432/db"@' {} \;
|
||||
find . -type f -name 'docker-compose.*' -exec sed -i 's@DATABASE_URI: ".*"$@DATABASE_URI: "postgresql://bunkerweb:secret\@bw-db:5432/db"@' {} \;
|
||||
|
||||
echo "💾 Starting postgres ..."
|
||||
docker compose -f docker-compose.postgres.yml up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💾 Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose -f docker-compose.postgres.yml up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💾 Up failed ❌"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "💾 Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💾 Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
if [ "$test" = "mariadb" ] ; then
|
||||
docker compose -f docker-compose.mariadb.yml up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💾 Up failed ❌"
|
||||
exit 1
|
||||
fi
|
||||
elif [ "$test" = "mysql" ] ; then
|
||||
docker compose -f docker-compose.mysql.yml up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💾 Up failed ❌"
|
||||
exit 1
|
||||
fi
|
||||
elif [ "$test" = "postgres" ] ; then
|
||||
docker compose -f docker-compose.postgres.yml up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💾 Up failed ❌"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💾 Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -181,7 +266,7 @@ do
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💾 Test \"$test\" failed ❌"
|
||||
|
|
@ -197,6 +282,15 @@ do
|
|||
manual=0
|
||||
|
||||
echo " "
|
||||
|
||||
echo "💾 Removing bw-docker network ..."
|
||||
|
||||
docker network rm bw-docker
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💾 Network removal failed ❌"
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
end=1
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ cleanup_stack () {
|
|||
|
||||
echo "🚫 Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🚫 Down failed ❌"
|
||||
|
|
@ -82,13 +82,13 @@ do
|
|||
fi
|
||||
|
||||
echo "🚫 Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🚫 Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🚫 Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -123,7 +123,7 @@ do
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🚫 Test \"$test\" failed ❌"
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ cleanup_stack () {
|
|||
|
||||
echo "⭕ Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "⭕ Down failed ❌"
|
||||
|
|
@ -55,13 +55,13 @@ do
|
|||
fi
|
||||
|
||||
echo "⭕ Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "⭕ Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "⭕ Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -96,7 +96,7 @@ do
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "⭕ Test \"$test\" failed ❌"
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ cleanup_stack () {
|
|||
|
||||
echo "🏁 Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🏁 Down failed ❌"
|
||||
|
|
@ -136,13 +136,13 @@ do
|
|||
fi
|
||||
|
||||
echo "🏁 Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🏁 Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🏁 Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -180,7 +180,7 @@ do
|
|||
if ! [[ "$test" = "user_agent" || "$test" = "user_agent_urls" || "$test" = "uri" || "$test" = "uri_urls" ]] ; then
|
||||
echo "🏁 Running global container tests ..."
|
||||
|
||||
docker compose -f docker-compose.test.yml up global-tests --abort-on-container-exit --exit-code-from global-tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up global-tests --abort-on-container-exit --exit-code-from global-tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🏁 Test \"$test\" failed for global tests ❌"
|
||||
|
|
@ -194,7 +194,7 @@ do
|
|||
|
||||
echo "🏁 Running local container tests ..."
|
||||
|
||||
docker compose -f docker-compose.test.yml up local-tests --abort-on-container-exit --exit-code-from local-tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up local-tests --abort-on-container-exit --exit-code-from local-tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🏁 Test \"$test\" failed for local tests ❌"
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ cleanup_stack () {
|
|||
|
||||
echo "🗜️ Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🗜️ Down failed ❌"
|
||||
|
|
@ -50,13 +50,13 @@ do
|
|||
fi
|
||||
|
||||
echo "🗜️ Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🗜️ Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🗜️ Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -91,7 +91,7 @@ do
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🗜️ Test \"$test\" failed ❌"
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ cleanup_stack () {
|
|||
|
||||
echo "🎛️ Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🎛️ Down failed ❌"
|
||||
|
|
@ -106,13 +106,13 @@ do
|
|||
fi
|
||||
|
||||
echo "🎛️ Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🎛️ Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🎛️ Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -147,7 +147,7 @@ do
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🎛️ Test \"$test\" failed ❌"
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ fi
|
|||
cleanup_stack () {
|
||||
echo "💉 Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💉 Down failed ❌"
|
||||
|
|
@ -33,13 +33,13 @@ trap cleanup_stack EXIT
|
|||
echo "💉 Running tests while injecting TEST into the HTML page ..."
|
||||
|
||||
echo "💉 Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💉 Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💉 Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -74,7 +74,7 @@ fi
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "💉 Test \"inject\" failed ❌"
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ cleanup_stack () {
|
|||
|
||||
echo "🎚️ Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🎚️ Down failed ❌"
|
||||
|
|
@ -84,13 +84,13 @@ do
|
|||
fi
|
||||
|
||||
echo "🎚️ Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🎚️ Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🎚️ Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -125,7 +125,7 @@ do
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🎚️ Test \"$test\" failed ❌"
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ cleanup_stack () {
|
|||
|
||||
echo "🗃️ Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🗃️ Down failed ❌"
|
||||
|
|
@ -76,13 +76,13 @@ do
|
|||
fi
|
||||
|
||||
echo "🗃️ Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🗃️ Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🗃️ Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -117,7 +117,7 @@ do
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🗃️ Test \"$test\" failed ❌"
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ cleanup_stack () {
|
|||
|
||||
echo "👮 Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "👮 Down failed ❌"
|
||||
|
|
@ -55,13 +55,13 @@ do
|
|||
fi
|
||||
|
||||
echo "👮 Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "👮 Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "👮 Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -96,7 +96,7 @@ do
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "👮 Test \"$test\" failed ❌"
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ cleanup_stack () {
|
|||
|
||||
echo "↩️ Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "↩️ Down failed ❌"
|
||||
|
|
@ -52,13 +52,13 @@ do
|
|||
fi
|
||||
|
||||
echo "↩️ Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "↩️ Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "↩️ Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -93,7 +93,7 @@ do
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "↩️ Test \"$test\" failed ❌"
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ cleanup_stack () {
|
|||
|
||||
echo "🧰 Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🧰 Down failed ❌"
|
||||
|
|
@ -74,13 +74,13 @@ do
|
|||
fi
|
||||
|
||||
echo "🧰 Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🧰 Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🧰 Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -115,7 +115,7 @@ do
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🧰 Test \"$test\" failed ❌"
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ cleanup_stack () {
|
|||
|
||||
echo "🕵️ Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🕵️ Down failed ❌"
|
||||
|
|
@ -54,13 +54,13 @@ do
|
|||
fi
|
||||
|
||||
echo "🕵️ Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🕵️ Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🕵️ Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -95,7 +95,7 @@ do
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🕵️ Test \"$test\" failed ❌"
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ cleanup_stack () {
|
|||
|
||||
echo "🔑 Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🔑 Down failed ❌"
|
||||
|
|
@ -56,13 +56,13 @@ do
|
|||
fi
|
||||
|
||||
echo "🔑 Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🔑 Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🔑 Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -97,7 +97,7 @@ do
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🔑 Test \"$test\" failed ❌"
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ cleanup_stack () {
|
|||
|
||||
echo "🧳 Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🧳 Down failed ❌"
|
||||
|
|
@ -55,13 +55,13 @@ do
|
|||
fi
|
||||
|
||||
echo "🧳 Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🧳 Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🧳 Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -96,7 +96,7 @@ do
|
|||
|
||||
# Start tests
|
||||
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up --abort-on-container-exit --exit-code-from tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🧳 Test \"$test\" failed ❌"
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ cleanup_stack () {
|
|||
|
||||
echo "🏳️ Cleaning up current stack ..."
|
||||
|
||||
docker compose down -v --remove-orphans 2>/dev/null
|
||||
docker compose down -v --remove-orphans
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🏳️ Down failed ❌"
|
||||
|
|
@ -137,13 +137,13 @@ do
|
|||
fi
|
||||
|
||||
echo "🏳️ Starting stack ..."
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🏳️ Up failed, retrying ... ⚠️"
|
||||
manual=1
|
||||
cleanup_stack
|
||||
manual=0
|
||||
docker compose up -d 2>/dev/null
|
||||
docker compose up -d
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🏳️ Up failed ❌"
|
||||
exit 1
|
||||
|
|
@ -181,7 +181,7 @@ do
|
|||
if ! [[ "$test" = "user_agent" || "$test" = "user_agent_urls" || "$test" = "uri" || "$test" = "uri_urls" ]] ; then
|
||||
echo "🏳️ Running global container tests ..."
|
||||
|
||||
docker compose -f docker-compose.test.yml up global-tests --abort-on-container-exit --exit-code-from global-tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up global-tests --abort-on-container-exit --exit-code-from global-tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🏳️ Test \"$test\" failed for global tests ❌"
|
||||
|
|
@ -195,7 +195,7 @@ do
|
|||
|
||||
echo "🏳️ Running local container tests ..."
|
||||
|
||||
docker compose -f docker-compose.test.yml up local-tests --abort-on-container-exit --exit-code-from local-tests 2>/dev/null
|
||||
docker compose -f docker-compose.test.yml up local-tests --abort-on-container-exit --exit-code-from local-tests
|
||||
|
||||
if [ $? -ne 0 ] ; then
|
||||
echo "🏳️ Test \"$test\" failed for local tests ❌"
|
||||
|
|
|
|||
Loading…
Reference in a new issue