update-10.02

This commit is contained in:
github-actions[bot] 2021-10-02 19:51:41 +08:00
parent 0007a92a00
commit c0e381eda0
8 changed files with 76 additions and 20 deletions

View File

@ -14,7 +14,7 @@ PKG_LICENSE:=AGPL-3.0
PKG_MAINTAINER:=lisaac <lisaac.cn@gmail.com> \
Florian Eckert <fe@dev.tdt.de>
PKG_VERSION:=v0.5.24
PKG_VERSION:=v0.5.25
include $(TOPDIR)/feeds/luci/luci.mk

View File

@ -45,15 +45,17 @@ function index()
entry({"admin", "docker", "newnetwork"}, form("dockerman/newnetwork")).leaf=true
entry({"admin", "docker", "container"}, form("dockerman/container")).leaf=true
entry({"admin", "docker", "call"}, call("action_call_docker")).leaf=true
entry({"admin", "docker", "container_stats"}, call("action_get_container_stats")).leaf=true
entry({"admin", "docker", "containers_stats"}, call("action_get_containers_stats")).leaf=true
entry({"admin", "docker", "get_system_df"}, call("action_get_system_df")).leaf=true
entry({"admin", "docker", "container_get_archive"}, call("download_archive")).leaf=true
entry({"admin", "docker", "container_put_archive"}, call("upload_archive")).leaf=true
entry({"admin","docker","container_list_file"},call("list_file")).leaf=true
entry({"admin","docker","container_remove_file"},call("remove_file")).leaf=true
entry({"admin","docker","container_rename_file"},call("rename_file")).leaf=true
entry({"admin","docker","container_export"},call("export_container")).leaf=true
entry({"admin", "docker", "container_list_file"}, call("list_file")).leaf=true
entry({"admin", "docker", "container_remove_file"}, call("remove_file")).leaf=true
entry({"admin", "docker", "container_rename_file"}, call("rename_file")).leaf=true
entry({"admin", "docker", "container_export"}, call("export_container")).leaf=true
entry({"admin", "docker", "images_save"}, call("save_images")).leaf=true
entry({"admin", "docker", "images_load"}, call("load_images")).leaf=true
entry({"admin", "docker", "images_import"}, call("import_images")).leaf=true
@ -63,6 +65,17 @@ function index()
entry({"admin", "docker", "confirm"}, call("action_confirm")).leaf=true
end
function action_call_docker()
end
function action_get_system_df()
local res = docker.new():df()
luci.http.status(res.code, res.message)
luci.http.prepare_content("application/json")
luci.http.write_json(res.body)
end
function scandir(id, directory)
local cmd_docker = luci.util.exec("command -v docker"):match("^.+docker") or nil
if not cmd_docker or cmd_docker:match("^%s+$") then

View File

@ -26,8 +26,7 @@ else
res = dk.containers:list({
query = {
all = true,
size = true
all = true
}
})
if res and res.code and res.code < 300 then
@ -90,7 +89,9 @@ function get_containers()
data[index]["_image"] = iv.RepoTags and iv.RepoTags[1] or (iv.RepoDigests[1]:gsub("(.-)@.+", "%1") .. ":&lt;none&gt;")
end
end
data[index]["_id_name"] = '<a href='..luci.dispatcher.build_url("admin/docker/container/"..v.Id)..' class="dockerman_link" title="'..translate("Container detail")..'">'.. data[index]["_name"] .. "<br><font color='#9f9f9f'>ID: " .. data[index]["_id"] .. "</font></a><br>Image: " .. (data[index]["_image"] or "&lt;none&gt;") .. "<br><font color='#9f9f9f' title='"..translate("RW Size: ").. docker.byte_format(v['SizeRw']).. ' / ' .. translate("RootFS Size(Include image): ").. docker.byte_format(v['SizeRootFs']) .."'>Size: " .. docker.byte_format(v['SizeRw']).. '/'.. docker.byte_format(v['SizeRootFs']) .. "</font>"
data[index]["_id_name"] = '<a href='..luci.dispatcher.build_url("admin/docker/container/"..v.Id)..' class="dockerman_link" title="'..translate("Container detail")..'">'.. data[index]["_name"] .. "<br><font color='#9f9f9f'>ID: " .. data[index]["_id"]
.. "</font></a><br>Image: " .. (data[index]["_image"] or "&lt;none&gt;")
.. "<br><font color='#9f9f9f' class='container_size_".. v.Id .."'></font>"
if type(v.Mounts) == "table" and next(v.Mounts) then
for _, v2 in pairs(v.Mounts) do

View File

@ -12,10 +12,14 @@ local m, s, o
if dk:_ping().code ~= 200 then
lost_state = true
else
res = dk:df()
res = dk.images:list()
if res and res.code and res.code < 300 then
images = res.body.Images
containers = res.body.Containers
images = res.body
end
res = dk.containers:list({ query = { all = true } })
if res and res.code and res.code < 300 then
containers = res.body
end
end

View File

@ -103,10 +103,9 @@ s.volumes_total = '-'
-- local socket = luci.model.uci.cursor():get("dockerd", "dockerman", "socket_path")
if not lost_state then
local res = dk:df()
local containers_list = res.body.Containers
local images_list = res.body.Images
local vol = res.body.Volumes
local containers_list = dk.containers:list({query = {all=true}}).body
local images_list = dk.images:list().body
local vol = dk.volumes:list()
local volumes_list = vol and vol.body and vol.body.Volumes or {}
local networks_list = dk.networks:list().body or {}
local docker_info = dk:info()

View File

@ -41,7 +41,7 @@ function get_volumes()
end
end
data[index]["_created"] = v.CreatedAt
data[index]["_size"] = docker.byte_format(v.UsageData and v.UsageData.Size or nil)
data[index]["_size"] = "<font class='volume_size_" .. v.Name .. "'>-</font>"
end
return data
@ -49,10 +49,18 @@ end
if dk:_ping().code ~= 200 then
lost_state = true
else
res = dk:df()
res = dk.volumes:list()
if res and res.code and res.code <300 then
volumes = res.body.Volumes
containers = res.body.Containers
end
res = dk.containers:list({
query = {
all=true
}
})
if res and res.code and res.code <300 then
containers = res.body
end
end
@ -61,6 +69,7 @@ local volume_list = not lost_state and get_volumes() or {}
m = SimpleForm("docker", translate("Docker - Volumes"))
m.submit=false
m.reset=false
m:append(Template("dockerman/volume_size"))
s = m:section(Table, volume_list, translate("Volumes overview"))
@ -78,6 +87,7 @@ o = s:option(DummyValue, "_containers", translate("Containers"))
o.rawhtml = true
o = s:option(DummyValue, "_mountpoint", translate("Mount Point"))
o = s:option(DummyValue, "_size", translate("Size"))
o.rawhtml = true
o = s:option(DummyValue, "_created", translate("Created"))
s = m:section(SimpleSection)

View File

@ -9,10 +9,18 @@
}
fnWindowLoad = function () {
XHR.get('<%=luci.dispatcher.build_url("admin/docker/get_system_df")%>/', null, (x, info)=>{
if(!info || !info.Containers || !info.Containers.forEach) return
info.Containers.forEach(item=>{
const size_c = document.getElementsByClassName("container_size_" + item.Id)
size_c[0].title = "RW Size: " + niceBytes(item.SizeRw) + " / RootFS Size(Include Image): " + niceBytes(item.SizeRootFs)
size_c[0].innerText = "Size: " + niceBytes(item.SizeRw) + "/" + niceBytes(item.SizeRootFs)
})
})
let lines = document.querySelectorAll('[id^=cbi-containers-]')
let last_bw_tx = {}
let last_bw_rx = {}
let interval = 5
let interval = 30
let containers = []
lines.forEach((item) => {
let containerId = item.id.match(/cbi-containers-.+_id_(.*)/)

View File

@ -0,0 +1,21 @@
<script type="text/javascript">
const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
function niceBytes(x) {
let l = 0, n = parseInt(x, 10) || 0;
while (n >= 1024 && ++l) {
n = n / 1024;
}
return (n.toFixed(n < 10 && l > 0 ? 1 : 0) + ' ' + units[l]);
}
fnWindowLoad = function () {
XHR.get('<%=luci.dispatcher.build_url("admin/docker/get_system_df")%>/', null, (x, info)=>{
if(!info || !info.Volumes || !info.Volumes.forEach) return
info.Volumes.forEach(item=>{
console.log(info)
const size_c = document.getElementsByClassName("volume_size_" + item.Name)
size_c[0].innerText = item.UsageData ? niceBytes(item.UsageData.Size) : '-'
})
})
}
</script>