feat: 调整编排删除逻辑 (#6610)

This commit is contained in:
ssongliu 2024-09-28 22:29:08 +08:00 committed by GitHub
parent 634849c347
commit c3bef26ae6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 31 additions and 34 deletions

View File

@ -219,7 +219,7 @@ type ComposeCreate struct {
type ComposeOperation struct {
Name string `json:"name" validate:"required"`
Path string `json:"path" validate:"required"`
Operation string `json:"operation" validate:"required,oneof=up start stop down"`
Operation string `json:"operation" validate:"required,oneof=up start stop down delete"`
WithFile bool `json:"withFile"`
}
type ComposeUpdate struct {

View File

@ -258,30 +258,20 @@ func (u *ContainerService) ComposeOperation(req dto.ComposeOperation) error {
if _, err := os.Stat(req.Path); err != nil {
return fmt.Errorf("load file with path %s failed, %v", req.Path, err)
}
if req.Operation == "up" {
if stdout, err := compose.Up(req.Path); err != nil {
if req.Operation == "delete" {
if stdout, err := compose.Operate(req.Path, "down"); err != nil {
return errors.New(string(stdout))
}
} else {
if stdout, err := compose.Operate(req.Path, req.Operation); err != nil {
return errors.New(string(stdout))
if req.WithFile {
_ = os.RemoveAll(path.Dir(req.Path))
}
_ = composeRepo.DeleteRecord(commonRepo.WithByName(req.Name))
return nil
}
if stdout, err := compose.Operate(req.Path, req.Operation); err != nil {
return errors.New(string(stdout))
}
global.LOG.Infof("docker-compose %s %s successful", req.Operation, req.Name)
if req.Operation == "down" {
if req.WithFile {
_ = composeRepo.DeleteRecord(commonRepo.WithByName(req.Name))
_ = os.RemoveAll(path.Dir(req.Path))
} else {
composeItem, _ := composeRepo.GetRecord(commonRepo.WithByName(req.Name))
if composeItem.Path == "" {
upMap := make(map[string]interface{})
upMap["path"] = req.Path
_ = composeRepo.UpdateRecord(req.Name, upMap)
}
}
}
return nil
}

View File

@ -772,7 +772,7 @@ const message = {
deleteFile: 'Delete file',
allDelete: 'Permanently Delete',
deleteComposeHelper:
'1. Delete container orchestration records \n2. Delete all container orchestration files, including configuration and persistent files',
'Delete all files related to container compose, including configuration files and persistent files. Please proceed with caution!',
deleteCompose: '" Delete this composition.',
apps: 'Apps',
local: 'Local',
@ -793,6 +793,8 @@ const message = {
composeDetailHelper:
'The compose is created external to 1Panel. The start and stop operations are not supported.',
composeOperatorHelper: '{1} operation will be performed on {0}. Do you want to continue?',
composeDownHelper:
'This will stop and remove all containers and networks under the {0} compose. Do you want to continue?',
setting: 'Setting',
operatorStatusHelper: 'This action will {0} Docker service, do you want to continue?',

View File

@ -742,7 +742,7 @@ const message = {
composeHelper: '通過 1Panel 編輯或者模版創建的編排將保存在 {0}/docker/compose 路徑下',
deleteFile: '刪除文件',
allDelete: '徹底刪除',
deleteComposeHelper: '1. 刪除容器編排記錄 \n2. 刪除容器編排的所有文件包括配置文件和持久化文件',
deleteComposeHelper: '刪除容器編排的所有文件包括配置文件和持久化文件請謹慎操作',
deleteCompose: '" 刪除此編排',
apps: '應用商店',
local: '本地',
@ -762,6 +762,7 @@ const message = {
up: '啟動',
composeDetailHelper: ' compose 1Panel 編排外部創建暫不支持啟停操作',
composeOperatorHelper: '將對 {0} 進行 {1} 操作是否繼續',
composeDownHelper: '將停止並刪除 {0} 編排下所有容器及網絡是否繼續',
setting: '配置',
operatorStatusHelper: '此操作將{0}Docker 服務是否繼續',

View File

@ -743,7 +743,7 @@ const message = {
composeHelper: '通过 1Panel 编辑或者模版创建的编排将保存在 {0}/docker/compose 路径下',
deleteFile: '删除文件',
allDelete: '彻底删除',
deleteComposeHelper: '1. 删除容器编排记录 \n2. 删除容器编排的所有文件包括配置文件和持久化文件',
deleteComposeHelper: '删除容器编排的所有文件包括配置文件和持久化文件请谨慎操作',
deleteCompose: '" 删除此编排',
apps: '应用商店',
local: '本地',
@ -763,6 +763,7 @@ const message = {
up: '启动',
composeDetailHelper: ' compose 1Panel 编排外部创建暂不支持启停操作',
composeOperatorHelper: '将对 {0} 进行 {1} 操作是否继续',
composeDownHelper: '将停止并删除 {0} 编排下所有容器及网络是否继续',
setting: '配置',
operatorStatusHelper: '此操作将{0}Docker 服务是否继续',

View File

@ -7,7 +7,7 @@
>
<el-form ref="deleteForm" v-loading="loading">
<el-form-item>
<el-checkbox v-model="deleteFile" :label="$t('container.allDelete')" />
<el-checkbox v-model="deleteFile" :label="$t('container.deleteFile')" />
<span class="input-help whitespace-break-spaces">
{{ $t('container.deleteComposeHelper') }}
</span>
@ -69,7 +69,7 @@ const submit = async () => {
let params = {
name: composeName.value,
path: composePath.value,
operation: 'down',
operation: 'delete',
withFile: deleteFile.value,
};
await composeOperator(params)

View File

@ -260,15 +260,18 @@ const onOperate = async (op: string) => {
};
const onComposeOperate = async (operation: string) => {
ElMessageBox.confirm(
i18n.global.t('container.composeOperatorHelper', [composeName.value, i18n.global.t('container.' + operation)]),
i18n.global.t('container.' + operation),
{
confirmButtonText: i18n.global.t('commons.button.confirm'),
cancelButtonText: i18n.global.t('commons.button.cancel'),
type: 'info',
},
).then(async () => {
let mes =
operation === 'down'
? i18n.global.t('container.composeDownHelper', [composeName.value])
: i18n.global.t('container.composeOperatorHelper', [
composeName.value,
i18n.global.t('container.' + operation),
]);
ElMessageBox.confirm(mes, i18n.global.t('container.' + operation), {
confirmButtonText: i18n.global.t('commons.button.confirm'),
cancelButtonText: i18n.global.t('commons.button.cancel'),
type: 'info',
}).then(async () => {
let params = {
name: composeName.value,
path: composePath.value,