Skip to content

Commit

Permalink
新增容器镜像回滚功能
Browse files Browse the repository at this point in the history
  • Loading branch information
llody55 committed Jun 28, 2024
1 parent 3d6f8ea commit b631533
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 10 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,11 @@ jobs:
${{ env.DOCKER_NAMESPACE }}/${{ env.DOCKER_IMAGE_NAME }}:latest
platforms: linux/amd64,linux/arm64

- name: Login and sync images to Aliyun registry
- name: sync images to Huawei Cloud Container registry
run: |
chmod +x ./bin/skopeo
./bin/skopeo copy --all docker://docker.io/${{ env.DOCKER_NAMESPACE }}/udocker:v1.1.3 docker://${{ env.DOCKER_REGISTRY_HUAWEI }}/${{ env.DOCKER_NAMESPACE }}/udocker:v1.1.3
./bin/skopeo copy --all docker://docker.io/${{ env.DOCKER_NAMESPACE }}/udocker:latest docker://${{ env.DOCKER_REGISTRY_HUAWEI }}/${{ env.DOCKER_NAMESPACE }}/udocker:latest
release:
needs: build
Expand Down
1 change: 1 addition & 0 deletions apps/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
re_path("get_registries_list/",views.get_registries_list,name="get_registries_list"),
re_path("get_volumes_list/",views.get_volumes_list,name="get_volumes_list"),
re_path("get_network_list/",views.get_network_list,name="get_network_list"),
re_path("get_historicalmirror_list/",views.get_historicalmirror_list,name="get_historicalmirror_list"),

re_path("docker_network_info/",views.docker_network_info,name="docker_network_info"), # 远程docker网络管理页面
re_path("docker_network_api/",views.docker_network_api,name="docker_network_api"), # 远程docker网络管理API
Expand Down
38 changes: 38 additions & 0 deletions apps/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,44 @@ def get_volumes_list(request):
except DockerException as e:
logger.error(e)

# 回显历史镜像版本
@login_required
def get_historicalmirror_list(request):
mirror_data = []
image_info = request.GET.get("image")
print("传递的镜像:",image_info)
try:
#容器管理模块API
success, client = docker_mod.connect_to_docker()
if success:
#image_info = [item['image'] for item in request_data]
# 获取所有镜像列表
images = client.images.list()

# 过滤出属于特定仓库的镜像
specific_images = []
for image in images:
for digest in image.attrs.get('RepoDigests', []):
# 使用image_info中的值替换原有的匹配规则
if digest and digest.startswith(image_info.split(':')[0] + '@'):
specific_images.append(image)
break
# 构建返回的历史镜像数据
historical_mirror_data = []
for image in specific_images:
tag_version = image.tags[0].split(':')[-1] if image.tags else '<none>'
historical_mirror_data.append({
'REPOSITORY': image.tags[0] if image.tags else '<none>',
'TAG': tag_version,
'IMAGE ID': image.short_id,
'CREATED': image.attrs['Created'],
'SIZE': image.attrs['VirtualSize']/1024/1024,
})
print("数据:",historical_mirror_data)
return render(request, 'container/docker_mirror.html',{"historical_mirror_data":historical_mirror_data})
except DockerException as e:
logger.error(e)


# 网络管理
@login_required
Expand Down
36 changes: 31 additions & 5 deletions templates/container/docker_container_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="add">{% translate "创建" %}</button>
<button class="layui-btn layui-btn-sm layui-btn-primary" lay-event="clear">{% translate "清理容器" %}</button>
<button class="layui-btn layui-btn-sm layui-btn-warm" lay-event="Batch_restart">{% translate "批量重启" %}</button>
<button class="layui-btn layui-btn-sm layui-btn-red" lay-event="mirror_rollback">{% translate "镜像回滚" %}</button>
{% endif %}
</script>
<script type="text/javascript">
Expand Down Expand Up @@ -113,6 +114,8 @@
elem: '#demo' // 选择table元素
, url: "{% url 'docker_container_api' %}" //数据接口, namespace值从当前session中获取
, page: true //开启分页
//, lineStyle: 'height: 51px;' // 定义表格的多行样式
//, className: 'layui-table-testcss' // 用于给表格主容器追加 css 类名
, toolbar: '#demoTable'
, defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义,去除该参数即可
title: '提示'
Expand All @@ -121,9 +124,9 @@
}]
, cols: [[ //表头
{ type: 'checkbox', fixed: 'left' } //全选按钮
, { field: 'id', title: translations.containerId, sort: true }
, { 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: 'image', title: translations.containerImage, sort: true }
, { 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 }
, { field: 'status', title: translations.runningStatus, width: 100, templet: statusFormat }
Expand All @@ -136,9 +139,9 @@
return '<input type="checkbox" name="restart" lay-skin="switch" lay-filter="restartFilter" lay-text="ON|OFF" ' + checked + ' data-id="' + d.id + '">';
}, width: 110
}
, { field: 'ports_data', title: translations.portMapping, width: 150, templet: portsFormat }
, { field: 'ports_data', title: translations.portMapping, templet: portsFormat}
, { field: 'create_time', title: translations.createTime, sort: true }
, { fixed: 'right', title: translations.actions, toolbar: '#barDemo', width: 320, align: "center" }
, { fixed: 'right', title: translations.actions, toolbar: '#barDemo', width: 300, align: "center" }
]],
id: 'TT',
done: function(res, curr, count) {
Expand Down Expand Up @@ -588,7 +591,7 @@
}else {
// 显示 loading 效果
var loadingIndex = layer.load(3);
layer.msg('开始重启,请稍候...', {time: 2000});
layer.msg('开始重启,请勿刷新页面...', {time: 2000});
$.ajax({
type: "BATCHRESTART",
url: '{% url "docker_container_batchrestart_api" %}',
Expand All @@ -615,6 +618,29 @@
});
}
break
case 'mirror_rollback':
var checkStatus = table.checkStatus(obj.config.id)
var data = checkStatus.data;
if(data.length == 0 ) {
layer.msg("请至少选择一行")
} else if (data.length > 1){
layer.msg("不支持多选")
} else {
layer.open({
type: 2,
area: ['50%', '70%'],
closeBtn: true, // 1或者2表示开启关闭按钮,0表示不开启
title: "文件管理器",
shade: 0.1,
shift: 2,
shadeClose: false,
content: '{% url "get_historicalmirror_list" %}?image=' + data[0].image,
move: false, // 禁止拖动
resize: false, // 禁止调整大小
skin: 'white-background' // 应用自定义的背景颜色类
});
}
break
}
})

Expand Down
59 changes: 59 additions & 0 deletions templates/container/docker_mirror.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>历史镜像</title>
<link rel="stylesheet" href="/static/layui/css/layui.css" />
<style>
body {
margin: 10px;
}
.layui-table {
margin: 10px 0;
}
</style>
</head>
<body>
<div class="layui-card">
<div class="layui-card-body">
<div class="layui-row">
<div class="layui-col-md12">
<fieldset class="layui-elem-field layui-field-title">
<legend>容器镜像回滚</legend>
</fieldset>
</div>
<div class="layui-col-md6">
<div class="layui-card">
<div class="layui-card-body layui-bg-gray">
<table class="layui-table">
<colgroup>
<col width="130" />
<col width="130" />
<col />
</colgroup>
<tbody>
<tr>
<td>REPOSITORY</td>
<td>TAG</td>
<td>CREATED</td>
<td>SIZE</td>
</tr>
{% for mirror in historical_mirror_data %}
<tr>
<td>{{ mirror.REPOSITORY }}</td>
<td>{{ mirror.TAG }}</td>
<td>{{ mirror.CREATED }}</td>
<td>{{ mirror.SIZE }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="/static/layui/layui.js"></script>
</body>
</html>

0 comments on commit b631533

Please sign in to comment.