mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-07 22:16:16 +08:00
feat: 调整编排删除逻辑 (#6610)
This commit is contained in:
parent
634849c347
commit
c3bef26ae6
7 changed files with 31 additions and 34 deletions
|
@ -219,7 +219,7 @@ type ComposeCreate struct {
|
||||||
type ComposeOperation struct {
|
type ComposeOperation struct {
|
||||||
Name string `json:"name" validate:"required"`
|
Name string `json:"name" validate:"required"`
|
||||||
Path string `json:"path" 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"`
|
WithFile bool `json:"withFile"`
|
||||||
}
|
}
|
||||||
type ComposeUpdate struct {
|
type ComposeUpdate struct {
|
||||||
|
|
|
@ -258,30 +258,20 @@ func (u *ContainerService) ComposeOperation(req dto.ComposeOperation) error {
|
||||||
if _, err := os.Stat(req.Path); err != nil {
|
if _, err := os.Stat(req.Path); err != nil {
|
||||||
return fmt.Errorf("load file with path %s failed, %v", req.Path, err)
|
return fmt.Errorf("load file with path %s failed, %v", req.Path, err)
|
||||||
}
|
}
|
||||||
if req.Operation == "up" {
|
if req.Operation == "delete" {
|
||||||
if stdout, err := compose.Up(req.Path); err != nil {
|
if stdout, err := compose.Operate(req.Path, "down"); err != nil {
|
||||||
return errors.New(string(stdout))
|
return errors.New(string(stdout))
|
||||||
}
|
}
|
||||||
} else {
|
if req.WithFile {
|
||||||
if stdout, err := compose.Operate(req.Path, req.Operation); err != nil {
|
_ = os.RemoveAll(path.Dir(req.Path))
|
||||||
return errors.New(string(stdout))
|
|
||||||
}
|
}
|
||||||
|
_ = 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)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -772,7 +772,7 @@ const message = {
|
||||||
deleteFile: 'Delete file',
|
deleteFile: 'Delete file',
|
||||||
allDelete: 'Permanently Delete',
|
allDelete: 'Permanently Delete',
|
||||||
deleteComposeHelper:
|
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.',
|
deleteCompose: '" Delete this composition.',
|
||||||
apps: 'Apps',
|
apps: 'Apps',
|
||||||
local: 'Local',
|
local: 'Local',
|
||||||
|
@ -793,6 +793,8 @@ const message = {
|
||||||
composeDetailHelper:
|
composeDetailHelper:
|
||||||
'The compose is created external to 1Panel. The start and stop operations are not supported.',
|
'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?',
|
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',
|
setting: 'Setting',
|
||||||
operatorStatusHelper: 'This action will {0} Docker service, do you want to continue?',
|
operatorStatusHelper: 'This action will {0} Docker service, do you want to continue?',
|
||||||
|
|
|
@ -742,7 +742,7 @@ const message = {
|
||||||
composeHelper: '通過 1Panel 編輯或者模版創建的編排,將保存在 {0}/docker/compose 路徑下',
|
composeHelper: '通過 1Panel 編輯或者模版創建的編排,將保存在 {0}/docker/compose 路徑下',
|
||||||
deleteFile: '刪除文件',
|
deleteFile: '刪除文件',
|
||||||
allDelete: '徹底刪除',
|
allDelete: '徹底刪除',
|
||||||
deleteComposeHelper: '1. 刪除容器編排記錄 \n2. 刪除容器編排的所有文件,包括配置文件和持久化文件',
|
deleteComposeHelper: '刪除容器編排的所有文件,包括配置文件和持久化文件,請謹慎操作!',
|
||||||
deleteCompose: '" 刪除此編排',
|
deleteCompose: '" 刪除此編排',
|
||||||
apps: '應用商店',
|
apps: '應用商店',
|
||||||
local: '本地',
|
local: '本地',
|
||||||
|
@ -762,6 +762,7 @@ const message = {
|
||||||
up: '啟動',
|
up: '啟動',
|
||||||
composeDetailHelper: '該 compose 為 1Panel 編排外部創建。暫不支持啟停操作。',
|
composeDetailHelper: '該 compose 為 1Panel 編排外部創建。暫不支持啟停操作。',
|
||||||
composeOperatorHelper: '將對 {0} 進行 {1} 操作,是否繼續?',
|
composeOperatorHelper: '將對 {0} 進行 {1} 操作,是否繼續?',
|
||||||
|
composeDownHelper: '將停止並刪除 {0} 編排下所有容器及網絡,是否繼續?',
|
||||||
|
|
||||||
setting: '配置',
|
setting: '配置',
|
||||||
operatorStatusHelper: '此操作將{0}Docker 服務,是否繼續?',
|
operatorStatusHelper: '此操作將{0}Docker 服務,是否繼續?',
|
||||||
|
|
|
@ -743,7 +743,7 @@ const message = {
|
||||||
composeHelper: '通过 1Panel 编辑或者模版创建的编排,将保存在 {0}/docker/compose 路径下',
|
composeHelper: '通过 1Panel 编辑或者模版创建的编排,将保存在 {0}/docker/compose 路径下',
|
||||||
deleteFile: '删除文件',
|
deleteFile: '删除文件',
|
||||||
allDelete: '彻底删除',
|
allDelete: '彻底删除',
|
||||||
deleteComposeHelper: '1. 删除容器编排记录 \n2. 删除容器编排的所有文件,包括配置文件和持久化文件',
|
deleteComposeHelper: '删除容器编排的所有文件,包括配置文件和持久化文件,请谨慎操作!',
|
||||||
deleteCompose: '" 删除此编排',
|
deleteCompose: '" 删除此编排',
|
||||||
apps: '应用商店',
|
apps: '应用商店',
|
||||||
local: '本地',
|
local: '本地',
|
||||||
|
@ -763,6 +763,7 @@ const message = {
|
||||||
up: '启动',
|
up: '启动',
|
||||||
composeDetailHelper: '该 compose 为 1Panel 编排外部创建。暂不支持启停操作。',
|
composeDetailHelper: '该 compose 为 1Panel 编排外部创建。暂不支持启停操作。',
|
||||||
composeOperatorHelper: '将对 {0} 进行 {1} 操作,是否继续?',
|
composeOperatorHelper: '将对 {0} 进行 {1} 操作,是否继续?',
|
||||||
|
composeDownHelper: '将停止并删除 {0} 编排下所有容器及网络,是否继续?',
|
||||||
|
|
||||||
setting: '配置',
|
setting: '配置',
|
||||||
operatorStatusHelper: '此操作将{0}Docker 服务,是否继续?',
|
operatorStatusHelper: '此操作将{0}Docker 服务,是否继续?',
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
>
|
>
|
||||||
<el-form ref="deleteForm" v-loading="loading">
|
<el-form ref="deleteForm" v-loading="loading">
|
||||||
<el-form-item>
|
<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">
|
<span class="input-help whitespace-break-spaces">
|
||||||
{{ $t('container.deleteComposeHelper') }}
|
{{ $t('container.deleteComposeHelper') }}
|
||||||
</span>
|
</span>
|
||||||
|
@ -69,7 +69,7 @@ const submit = async () => {
|
||||||
let params = {
|
let params = {
|
||||||
name: composeName.value,
|
name: composeName.value,
|
||||||
path: composePath.value,
|
path: composePath.value,
|
||||||
operation: 'down',
|
operation: 'delete',
|
||||||
withFile: deleteFile.value,
|
withFile: deleteFile.value,
|
||||||
};
|
};
|
||||||
await composeOperator(params)
|
await composeOperator(params)
|
||||||
|
|
|
@ -260,15 +260,18 @@ const onOperate = async (op: string) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const onComposeOperate = async (operation: string) => {
|
const onComposeOperate = async (operation: string) => {
|
||||||
ElMessageBox.confirm(
|
let mes =
|
||||||
i18n.global.t('container.composeOperatorHelper', [composeName.value, i18n.global.t('container.' + operation)]),
|
operation === 'down'
|
||||||
i18n.global.t('container.' + operation),
|
? i18n.global.t('container.composeDownHelper', [composeName.value])
|
||||||
{
|
: i18n.global.t('container.composeOperatorHelper', [
|
||||||
confirmButtonText: i18n.global.t('commons.button.confirm'),
|
composeName.value,
|
||||||
cancelButtonText: i18n.global.t('commons.button.cancel'),
|
i18n.global.t('container.' + operation),
|
||||||
type: 'info',
|
]);
|
||||||
},
|
ElMessageBox.confirm(mes, i18n.global.t('container.' + operation), {
|
||||||
).then(async () => {
|
confirmButtonText: i18n.global.t('commons.button.confirm'),
|
||||||
|
cancelButtonText: i18n.global.t('commons.button.cancel'),
|
||||||
|
type: 'info',
|
||||||
|
}).then(async () => {
|
||||||
let params = {
|
let params = {
|
||||||
name: composeName.value,
|
name: composeName.value,
|
||||||
path: composePath.value,
|
path: composePath.value,
|
||||||
|
|
Loading…
Add table
Reference in a new issue