From d43df6941bddb34ae88e1b88859da8567e45bdef Mon Sep 17 00:00:00 2001 From: John Bro <42930107+john1298308460@users.noreply.github.com> Date: Sat, 11 May 2024 17:50:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=8F=8A=E5=AE=B9=E5=99=A8=E8=8F=9C=E5=8D=95=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=B8=85=E7=90=86=E6=9E=84=E5=BB=BA=E7=BC=93=E5=AD=98=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=20(#4978)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: zhoujunhong <1298308460@qq.com> --- backend/app/dto/container.go | 2 +- backend/app/service/container.go | 7 ++++ frontend/src/lang/modules/en.ts | 3 ++ frontend/src/lang/modules/tw.ts | 2 + frontend/src/lang/modules/zh.ts | 2 + frontend/src/views/container/image/index.vue | 37 ++++++++++++++++++- .../src/views/website/runtime/node/index.vue | 30 +++++++++++++++ .../src/views/website/runtime/php/index.vue | 30 +++++++++++++++ 8 files changed, 111 insertions(+), 2 deletions(-) diff --git a/backend/app/dto/container.go b/backend/app/dto/container.go index c19d43163..99d151dae 100644 --- a/backend/app/dto/container.go +++ b/backend/app/dto/container.go @@ -123,7 +123,7 @@ type ContainerRename struct { } type ContainerPrune struct { - PruneType string `json:"pruneType" validate:"required,oneof=container image volume network"` + PruneType string `json:"pruneType" validate:"required,oneof=container image volume network buildcache"` WithTagAll bool `json:"withTagAll"` } diff --git a/backend/app/service/container.go b/backend/app/service/container.go index 88148d84a..1d8debab1 100644 --- a/backend/app/service/container.go +++ b/backend/app/service/container.go @@ -329,6 +329,13 @@ func (u *ContainerService) Prune(req dto.ContainerPrune) (dto.ContainerPruneRepo } report.DeletedNumber = len(rep.VolumesDeleted) report.SpaceReclaimed = int(rep.SpaceReclaimed) + case "buildcache": + rep, err := client.BuildCachePrune(context.Background(), types.BuildCachePruneOptions{}) + if err != nil { + return report, err + } + report.DeletedNumber = len(rep.CachesDeleted) + report.SpaceReclaimed = int(rep.SpaceReclaimed) } return report, nil } diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index f9c82e7c4..a0de52d47 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -691,6 +691,9 @@ const message = { tag: 'Tag', tagHelper: 'one in a row, for example, \nkey1=value1\nkey2=value2', imageNameHelper: 'Image name and Tag, for example: nginx:latest', + cleanBuildCache: 'Clean Build Cache', + delBuildCacheHelper: + 'Cleaning the build cache will delete all cached artifacts generated during builds. This action cannot be undone. Continue?', network: 'Network', createNetwork: 'Create network', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index dcbea0496..ee91de046 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -672,6 +672,8 @@ const message = { tag: '標簽', tagHelper: '一行一個,例: \nkey1=value1\nkey2=value2', imageNameHelper: '鏡像名稱及 Tag,例:nginx:latest', + cleanBuildCache: '清理建置快取', + delBuildCacheHelper: '清理建置快取將刪除所有建置所產生的快取,此操作無法回復。是否繼續?', network: '網絡', createNetwork: '創建網絡', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index c7f40e50e..6634dac6b 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -673,6 +673,8 @@ const message = { tag: '标签', tagHelper: '一行一个,例: \nkey1=value1\nkey2=value2', imageNameHelper: '镜像名称及 Tag,例:nginx:latest', + cleanBuildCache: '清理构建缓存', + delBuildCacheHelper: '清理构建缓存 将删除所有构建产生的缓存,该操作无法回滚,是否继续?', network: '网络', createNetwork: '创建网络', diff --git a/frontend/src/views/container/image/index.vue b/frontend/src/views/container/image/index.vue index c7435e9df..0c40e8337 100644 --- a/frontend/src/views/container/image/index.vue +++ b/frontend/src/views/container/image/index.vue @@ -19,6 +19,9 @@ {{ $t('container.imageBuild') }} + + {{ $t('container.cleanBuildCache') }} + {{ $t('container.imagePrune') }} @@ -112,10 +115,19 @@ import Build from '@/views/container/image/build/index.vue'; import Delete from '@/views/container/image/delete/index.vue'; import Prune from '@/views/container/image/prune/index.vue'; import CodemirrorDialog from '@/components/codemirror-dialog/index.vue'; -import { searchImage, listImageRepo, loadDockerStatus, imageRemove, inspect } from '@/api/modules/container'; +import { + searchImage, + listImageRepo, + loadDockerStatus, + imageRemove, + inspect, + containerPrune, +} from '@/api/modules/container'; import i18n from '@/lang'; import router from '@/routers'; import { GlobalStore } from '@/store'; +import { ElMessageBox } from 'element-plus'; +import { MsgSuccess } from '@/utils/message'; const globalStore = GlobalStore(); const mobile = computed(() => { @@ -222,6 +234,29 @@ const onOpenPrune = () => { dialogPruneRef.value!.acceptParams(); }; +const onOpenBuildCache = () => { + ElMessageBox.confirm(i18n.global.t('container.delBuildCacheHelper'), i18n.global.t('container.cleanBuildCache'), { + confirmButtonText: i18n.global.t('commons.button.confirm'), + cancelButtonText: i18n.global.t('commons.button.cancel'), + type: 'info', + }).then(async () => { + loading.value = true; + let params = { + pruneType: 'buildcache', + withTagAll: false, + }; + await containerPrune(params) + .then((res) => { + loading.value = false; + MsgSuccess(i18n.global.t('container.cleanSuccess', [res.data.deletedNumber])); + search(); + }) + .catch(() => { + loading.value = false; + }); + }); +}; + const onOpenload = () => { dialogLoadRef.value!.acceptParams(); }; diff --git a/frontend/src/views/website/runtime/node/index.vue b/frontend/src/views/website/runtime/node/index.vue index b2cc9f81f..622106971 100644 --- a/frontend/src/views/website/runtime/node/index.vue +++ b/frontend/src/views/website/runtime/node/index.vue @@ -13,6 +13,10 @@ {{ $t('runtime.create') }} + + + {{ $t('container.cleanBuildCache') }} +