luci-app-dockerman: use uci from docker-ce

Change the source to user docker-ce and update docker uci options name.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
This commit is contained in:
Florian Eckert 2020-07-17 13:16:14 +02:00
parent 88ced18203
commit a4a9f0a683
5 changed files with 53 additions and 41 deletions

View file

@ -16,13 +16,13 @@ function index()
entry({"admin","docker","overview"},cbi("dockerman/overview"),_("Overview"),0).leaf=true entry({"admin","docker","overview"},cbi("dockerman/overview"),_("Overview"),0).leaf=true
local remote = luci.model.uci.cursor():get("dockerman", "local", "remote_endpoint") local remote = luci.model.uci.cursor():get("dockerd", "globals", "remote_endpoint")
if remote == nil then if remote == nil then
local socket = luci.model.uci.cursor():get("dockerman", "local", "socket_path") local socket = luci.model.uci.cursor():get("dockerd", "globals", "socket_path")
if socket and not nixio.fs.access(socket) then return end if socket and not nixio.fs.access(socket) then return end
elseif remote == "true" then elseif remote == "true" then
local host = luci.model.uci.cursor():get("dockerman", "local", "remote_host") local host = luci.model.uci.cursor():get("dockerd", "globals", "remote_host")
local port = luci.model.uci.cursor():get("dockerman", "local", "remote_port") local port = luci.model.uci.cursor():get("dockerd", "globals", "remote_port")
if not host or not port then return end if not host or not port then return end
end end

View file

@ -537,10 +537,10 @@ elseif action == "console" then
luci.util.exec(kill_ttyd) luci.util.exec(kill_ttyd)
local hosts local hosts
local uci = (require "luci.model.uci").cursor() local uci = (require "luci.model.uci").cursor()
local remote = uci:get("dockerman", "local", "remote_endpoint") local remote = uci:get("dockerd", "globals", "remote_endpoint")
local socket_path = (remote == "false" or not remote) and uci:get("dockerman", "local", "socket_path") or nil local socket_path = (remote == "false" or not remote) and uci:get("dockerd", "globals", "socket_path") or nil
local host = (remote == "true") and uci:get("dockerman", "local", "remote_host") or nil local host = (remote == "true") and uci:get("dockerd", "globals", "remote_host") or nil
local port = (remote == "true") and uci:get("dockerman", "local", "remote_port") or nil local port = (remote == "true") and uci:get("dockerd", "globals", "remote_port") or nil
if remote and host and port then if remote and host and port then
hosts = host .. ':'.. port hosts = host .. ':'.. port
elseif socket_path then elseif socket_path then

View file

@ -18,7 +18,12 @@ function byte_format(byte)
end end
end end
local map_dockerman = Map("dockerman", translate("Docker"), translate("DockerMan is a Simple Docker manager client for LuCI, If you have any issue please visit:") .. " ".. [[<a href="https://github.com/lisaac/luci-app-dockerman" target="_blank">]] ..translate("Github") .. [[</a>]]) local map_dockerman = Map("dockerd", translate("Docker"),
translate("DockerMan is a Simple Docker manager client for LuCI, If you have any issue please visit:") ..
" " ..
[[<a href="https://github.com/lisaac/luci-app-dockerman" target="_blank">]] ..
translate("Github") ..
[[</a>]])
local docker_info_table = {} local docker_info_table = {}
-- docker_info_table['0OperatingSystem'] = {_key=translate("Operating System"),_value='-'} -- docker_info_table['0OperatingSystem'] = {_key=translate("Operating System"),_value='-'}
-- docker_info_table['1Architecture'] = {_key=translate("Architecture"),_value='-'} -- docker_info_table['1Architecture'] = {_key=translate("Architecture"),_value='-'}
@ -42,7 +47,7 @@ s.images_total = '-'
s.networks_total = '-' s.networks_total = '-'
s.volumes_total = '-' s.volumes_total = '-'
local containers_list local containers_list
-- local socket = luci.model.uci.cursor():get("dockerman", "local", "socket_path") -- local socket = luci.model.uci.cursor():get("dockerd", "globals", "socket_path")
if (require "luci.model.docker").new():_ping().code == 200 then if (require "luci.model.docker").new():_ping().code == 200 then
local dk = docker.new() local dk = docker.new()
containers_list = dk.containers:list({query = {all=true}}).body containers_list = dk.containers:list({query = {all=true}}).body
@ -86,9 +91,8 @@ if (require "luci.model.docker").new():_ping().code == 200 then
end end
s.template = "dockerman/overview" s.template = "dockerman/overview"
local section_dockerman = map_dockerman:section(NamedSection, "local", "section", translate("Setting")) local section_dockerman = map_dockerman:section(NamedSection, "globals", "section", translate("Setting"))
section_dockerman:tab("daemon", translate("Docker Daemon")) section_dockerman:tab("daemon", translate("Docker Daemon"))
section_dockerman:tab("ac", translate("Access Control"))
section_dockerman:tab("dockerman", translate("DockerMan")) section_dockerman:tab("dockerman", translate("DockerMan"))
local socket_path = section_dockerman:taboption("dockerman", Value, "socket_path", translate("Docker Socket Path")) local socket_path = section_dockerman:taboption("dockerman", Value, "socket_path", translate("Docker Socket Path"))
@ -117,23 +121,31 @@ remote_port.default = "2375"
-- local debug_path = section_dockerman:taboption("dockerman", Value, "debug_path", translate("Debug Tempfile Path"), translate("Where you want to save the debug tempfile")) -- local debug_path = section_dockerman:taboption("dockerman", Value, "debug_path", translate("Debug Tempfile Path"), translate("Where you want to save the debug tempfile"))
if nixio.fs.access("/usr/bin/dockerd") then if nixio.fs.access("/usr/bin/dockerd") then
local dockerd_enable = section_dockerman:taboption("daemon", Flag, "daemon_ea", translate("Enable")) local o
dockerd_enable.enabled = "true"
dockerd_enable.rmempty = true
local data_root = section_dockerman:taboption("daemon", Value, "daemon_data_root", translate("Docker Root Dir"))
data_root.placeholder = "/opt/docker/"
local registry_mirrors = section_dockerman:taboption("daemon", DynamicList, "daemon_registry_mirrors", translate("Registry Mirrors"))
registry_mirrors:value("https://hub-mirror.c.163.com", "https://hub-mirror.c.163.com")
local log_level = section_dockerman:taboption("daemon", ListValue, "daemon_log_level", translate("Log Level"), translate('Set the logging level')) o = section_dockerman:taboption("daemon", Value, "data_root",
log_level:value("debug", "debug") translate("Docker Root Dir"))
log_level:value("info", "info") o.placeholder = "/opt/docker/"
log_level:value("warn", "warn")
log_level:value("error", "error") o = section_dockerman:taboption("daemon", DynamicList, "registry_mirrors",
log_level:value("fatal", "fatal") translate("Registry Mirrors"))
local hosts = section_dockerman:taboption("daemon", DynamicList, "daemon_hosts", translate("Server Host"), translate('Daemon unix socket (unix:///var/run/docker.sock) or TCP Remote Hosts (tcp://0.0.0.0:2375), default: unix:///var/run/docker.sock')) o:value("https://hub-mirror.c.163.com", "https://hub-mirror.c.163.com")
hosts:value("unix:///var/run/docker.sock", "unix:///var/run/docker.sock")
hosts:value("tcp://0.0.0.0:2375", "tcp://0.0.0.0:2375") o = section_dockerman:taboption("daemon", ListValue, "log_level",
hosts.rmempty = true translate("Log Level"),
translate('Set the logging level'))
o:value("debug", "debug")
o:value("info", "info")
o:value("warn", "warn")
o:value("error", "error")
o:value("fatal", "fatal")
o = section_dockerman:taboption("daemon", DynamicList, "hosts",
translate("Server Host"),
translate('Daemon unix socket (unix:///var/run/docker.sock) or TCP Remote Hosts (tcp://0.0.0.0:2375), default: unix:///var/run/docker.sock'))
o:value("unix:///var/run/docker.sock", "unix:///var/run/docker.sock")
o:value("tcp://0.0.0.0:2375", "tcp://0.0.0.0:2375")
o.rmempty = true
end end
return map_dockerman return map_dockerman

View file

@ -222,22 +222,22 @@ end
_docker.new = function(option) _docker.new = function(option)
local option = option or {} local option = option or {}
local remote = uci:get("dockerman", "local", "remote_endpoint") local remote = uci:get("dockerd", "globals", "remote_endpoint")
options = { options = {
host = (remote == "true") and (option.host or uci:get("dockerman", "local", "remote_host")) or nil, host = (remote == "true") and (option.host or uci:get("dockerd", "globals", "remote_host")) or nil,
port = (remote == "true") and (option.port or uci:get("dockerman", "local", "remote_port")) or nil, port = (remote == "true") and (option.port or uci:get("dockerd", "globals", "remote_port")) or nil,
debug = option.debug or uci:get("dockerman", "local", "debug") == 'true' and true or false, debug = option.debug or uci:get("dockerd", "globals", "debug") == 'true' and true or false,
debug_path = option.debug_path or uci:get("dockerman", "local", "debug_path") debug_path = option.debug_path or uci:get("dockerd", "globals", "debug_path") or "/tmp/.docker_debug"
} }
options.socket_path = (remote ~= "true" or not options.host or not options.port) and (option.socket_path or uci:get("dockerman", "local", "socket_path") or "/var/run/docker.sock") or nil options.socket_path = (remote ~= "true" or not options.host or not options.port) and (option.socket_path or uci:get("dockerd", "globals", "socket_path") or "/var/run/docker.sock") or nil
local _new = docker.new(options) local _new = docker.new(options)
_new.options.status_path = uci:get("dockerman", "local", "status_path") _new.options.status_path = uci:get("dockerd", "globals", "status_path") or "/tmp/.docker_status"
_new.containers_upgrade = upgrade _new.containers_upgrade = upgrade
_new.containers_duplicate_config = duplicate_config _new.containers_duplicate_config = duplicate_config
return _new return _new
end end
_docker.options={} _docker.options={}
_docker.options.status_path = uci:get("dockerman", "local", "status_path") _docker.options.status_path = uci:get("dockerd", "globals", "status_path") or "/tmp/.docker_status"
_docker.append_status=function(self,val) _docker.append_status=function(self,val)
if not val then return end if not val then return end
@ -330,7 +330,7 @@ end
_docker.create_macvlan_interface = function(name, device, gateway, subnet) _docker.create_macvlan_interface = function(name, device, gateway, subnet)
if not nixio.fs.access("/etc/config/network") or not nixio.fs.access("/etc/config/firewall") then return end if not nixio.fs.access("/etc/config/network") or not nixio.fs.access("/etc/config/firewall") then return end
if uci:get("dockerman", "local", "remote_endpoint") == "true" then return end if uci:get("dockerd", "globals", "remote_endpoint") == "true" then return end
local ip = require "luci.ip" local ip = require "luci.ip"
local if_name = "docker_"..name local if_name = "docker_"..name
local dev_name = "macvlan_"..name local dev_name = "macvlan_"..name
@ -371,7 +371,7 @@ end
_docker.remove_macvlan_interface = function(name) _docker.remove_macvlan_interface = function(name)
if not nixio.fs.access("/etc/config/network") or not nixio.fs.access("/etc/config/firewall") then return end if not nixio.fs.access("/etc/config/network") or not nixio.fs.access("/etc/config/firewall") then return end
if uci:get("dockerman", "local", "remote_endpoint") == "true" then return end if uci:get("dockerd", "globals", "remote_endpoint") == "true" then return end
local if_name = "docker_"..name local if_name = "docker_"..name
local dev_name = "macvlan_"..name local dev_name = "macvlan_"..name
uci:foreach("firewall", "zone", function(s) uci:foreach("firewall", "zone", function(s)

View file

@ -2,10 +2,10 @@
"luci-app-dockerman": { "luci-app-dockerman": {
"description": "Grant UCI access for luci-app-dockerman", "description": "Grant UCI access for luci-app-dockerman",
"read": { "read": {
"uci": [ "dockerman" ] "uci": [ "dockerd" ]
}, },
"write": { "write": {
"uci": [ "dockerman" ] "uci": [ "dockerd" ]
} }
} }
} }