Skip to content

Commit

Permalink
修复镜像版本展示内容
Browse files Browse the repository at this point in the history
  • Loading branch information
llody55 committed Oct 18, 2024
1 parent a90c136 commit 6edec26
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ permissions:

env:
PYTHON_VERSION: '3.9.13'
RELEASE_VERSION: 'v1.1.4' # 发布版本
RELEASE_VERSION: 'v1.1.5' # 发布版本
DOCKER_IMAGE_NAME: 'udocker'
DOCKER_NAMESPACE: 'llody'
DOCKER_REGISTRY_HUAWEI: 'swr.cn-southwest-2.myhuaweicloud.com'
Expand Down Expand Up @@ -116,8 +116,8 @@ jobs:
body: |
- **新版本发布**: ${{ env.RELEASE_VERSION }}
- **更新内容**:
- * 容器管理 - 新增镜像回滚功能,可以对容器正在使用的镜像进行镜像回滚,切换镜像并重新创建容器
- * 镜像仓库 - 新增dockerhub代理,(docker.llody.cn)
- * 容器管理 - 修复镜像管理占用判断逻辑
- * 镜像仓库 - 新增compose应用判断
- * 页面优化。
- * 流水线优化 - 新增同步国内镜像仓库镜像。
draft: false
Expand Down
29 changes: 26 additions & 3 deletions apps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ def docker_container_api(request):
isrunning = container.attrs['State']['Running']
status = container.status
ports_data = []

# 检查容器是否是通过docker-compose部署的
labels = container.attrs.get('Config', {}).get('Labels', {})
is_docker_compose = 'com.docker.compose.project' in labels
compose_project = labels.get('com.docker.compose.project', 'N/A') if is_docker_compose else None
compose_service = labels.get('com.docker.compose.service', 'N/A') if is_docker_compose else None

for i in container.attrs['NetworkSettings']['Ports']:
ports = i
#该变量用于获取是否有未映射端口,没有为false,有为true
Expand Down Expand Up @@ -246,7 +253,21 @@ def docker_container_api(request):
time_obj = parser.isoparse(time_str)
time_obj += time_offset
create_time = time_obj.strftime('%Y-%m-%d %H:%M:%S')
dat = {"id":id,"name":name,"image":image,"isrunning":isrunning,"restart_switch":restart_switch,"restart_count":restart_count,"status":status,"create_time":create_time,"ports_data":ports_data,"health_status":health_status}
dat = {
"id": id,
"name": name,
"image": image,
"isrunning": isrunning,
"restart_switch": restart_switch,
"restart_count": restart_count,
"status": status,
"create_time": create_time,
"ports_data": ports_data,
"health_status": health_status,
"is_docker_compose": is_docker_compose,
"compose_project": compose_project,
"compose_service": compose_service
}
# 根据查询关键字返回数据
if search_key:
if search_key in name:
Expand Down Expand Up @@ -852,14 +873,14 @@ def docker_images_api(request):
# 获取所有容器的镜像ID
container_image_ids = {container.image.id for container in containers}
def process_image(image):
image_ids = image.id # 使用完整的image id
image_id = image.short_id
image_tags = image.tags
image_size = humanize.naturalsize(image.attrs['Size'], binary=True)
time_str = image.attrs['Created']
time_obj = parser.isoparse(time_str)
image_create_time = time_obj.strftime('%Y-%m-%d %H:%M:%S')
image_in_use = image_id in container_image_ids

image_in_use = image_ids in container_image_ids
for tag in image_tags:
dat = {
"image_id": image_id,
Expand Down Expand Up @@ -957,6 +978,8 @@ def process_image(image):
code = 2
if e.status_code == 409 and "image has dependent child images" in str(e):
msg = "删除失败:存在多个依赖的子镜像。"
elif e.status_code == 409 and "image is being used by running container" in str(e):
msg = "删除失败:容器正在运行,请先停止容器。"
else:
msg = "删除报错:%s" % e
result = {'code': code, 'msg': msg}
Expand Down
15 changes: 14 additions & 1 deletion templates/container/docker_container_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
{ type: 'checkbox', fixed: 'left' } //全选按钮
, { field: 'id', title: translations.containerId, sort: true ,hide:true}
, { field: 'name', title: translations.containerName +'<i class="layui-icon layui-icon-tips layui-font-14" title="该字段开启了编辑功能" style="margin-left: 5px;"></i>', fieldTitle: '容器名称', hide: 0, sort: true, edit: 'text' } //hide:true 隐藏某一列的信息,edit:'text' 表示开启了编辑
, { field: 'compose_project', title:"compose", sort: true,templet: composeFormat}
, { field: 'image', title: translations.containerImage, sort: true}
//, { field: 'isrunning', title: '就绪状态', width: 100, templet: isrunningFormat }
, { field: 'health_status', title: translations.healthCheck +'<i class="layui-icon layui-icon-survey layui-font-14" title="只标记容器健康状态" style="margin-left: 5px;"></i>', width: 110, templet: health_statusFormat }
Expand Down Expand Up @@ -159,7 +160,19 @@
})
}
});


// 健康状态格式化
function composeFormat(d) {
result = "";
if (d.is_docker_compose == true) {
//给返回值加个样式
result = d.compose_project
return result
} else {
result = '-'
return result
}
}
// 健康状态格式化
function health_statusFormat(d) {
result = "";
Expand Down

0 comments on commit 6edec26

Please sign in to comment.