mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-09-18 04:25:50 +08:00
fix: 解决容器编辑无法编辑名称的问题 (#1546)
This commit is contained in:
parent
9fa9772c07
commit
12eeb6503c
4 changed files with 36 additions and 16 deletions
|
@ -38,6 +38,7 @@ type ResourceLimit struct {
|
|||
}
|
||||
|
||||
type ContainerOperate struct {
|
||||
ContainerID string `json:"containerID"`
|
||||
Name string `json:"name"`
|
||||
Image string `json:"image"`
|
||||
PublishAllPorts bool `json:"publishAllPorts"`
|
||||
|
|
|
@ -285,6 +285,11 @@ func (u *ContainerService) ContainerCreate(req dto.ContainerOperate) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ctx := context.Background()
|
||||
newContainer, _ := client.ContainerInspect(ctx, req.Name)
|
||||
if len(newContainer.ID) != 0 {
|
||||
return buserr.New(constant.ErrContainerName)
|
||||
}
|
||||
|
||||
var config container.Config
|
||||
var hostConf container.HostConfig
|
||||
|
@ -294,7 +299,6 @@ func (u *ContainerService) ContainerCreate(req dto.ContainerOperate) error {
|
|||
|
||||
global.LOG.Infof("new container info %s has been made, now start to create", req.Name)
|
||||
|
||||
ctx := context.Background()
|
||||
if !checkImageExist(client, req.Image) {
|
||||
if err := pullImages(ctx, client, req.Image); err != nil {
|
||||
return err
|
||||
|
@ -325,6 +329,7 @@ func (u *ContainerService) ContainerInfo(req dto.OperationWithName) (*dto.Contai
|
|||
}
|
||||
|
||||
var data dto.ContainerOperate
|
||||
data.ContainerID = oldContainer.ID
|
||||
data.Name = strings.ReplaceAll(oldContainer.Name, "/", "")
|
||||
data.Image = oldContainer.Config.Image
|
||||
data.Cmd = oldContainer.Config.Cmd
|
||||
|
@ -372,7 +377,12 @@ func (u *ContainerService) ContainerUpdate(req dto.ContainerOperate) error {
|
|||
return err
|
||||
}
|
||||
ctx := context.Background()
|
||||
oldContainer, err := client.ContainerInspect(ctx, req.Name)
|
||||
newContainer, _ := client.ContainerInspect(ctx, req.Name)
|
||||
if len(newContainer.ID) != 0 && newContainer.ID != req.ContainerID {
|
||||
return buserr.New(constant.ErrContainerName)
|
||||
}
|
||||
|
||||
oldContainer, err := client.ContainerInspect(ctx, req.ContainerID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -386,7 +396,7 @@ func (u *ContainerService) ContainerUpdate(req dto.ContainerOperate) error {
|
|||
if err := loadConfigInfo(req, config, hostConf); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := client.ContainerRemove(ctx, req.Name, types.ContainerRemoveOptions{Force: true}); err != nil {
|
||||
if err := client.ContainerRemove(ctx, req.ContainerID, types.ContainerRemoveOptions{Force: true}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -460,6 +470,10 @@ func (u *ContainerService) ContainerOperation(req dto.ContainerOperation) error
|
|||
case constant.ContainerOpUnpause:
|
||||
err = client.ContainerUnpause(ctx, req.Name)
|
||||
case constant.ContainerOpRename:
|
||||
newContainer, _ := client.ContainerInspect(ctx, req.NewName)
|
||||
if len(newContainer.ID) != 0 {
|
||||
return buserr.New(constant.ErrContainerName)
|
||||
}
|
||||
err = client.ContainerRename(ctx, req.Name, req.NewName)
|
||||
case constant.ContainerOpRemove:
|
||||
err = client.ContainerRemove(ctx, req.Name, types.ContainerRemoveOptions{RemoveVolumes: true, Force: true})
|
||||
|
|
|
@ -17,6 +17,7 @@ export namespace Container {
|
|||
memory: number;
|
||||
}
|
||||
export interface ContainerHelper {
|
||||
containerID: string;
|
||||
name: string;
|
||||
image: string;
|
||||
cmdStr: string;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<template>
|
||||
<el-drawer v-model="drawerVisiable" :destroy-on-close="true" :close-on-click-modal="false" size="50%">
|
||||
<template #header>
|
||||
<DrawerHeader :header="title" :back="handleClose" />
|
||||
<DrawerHeader :header="title" :resource="dialogData.rowData?.name" :back="handleClose" />
|
||||
</template>
|
||||
<el-form
|
||||
ref="formRef"
|
||||
|
@ -379,18 +379,22 @@ const onSubmit = async (formEl: FormInstance | undefined) => {
|
|||
confirmButtonText: i18n.global.t('commons.button.confirm'),
|
||||
cancelButtonText: i18n.global.t('commons.button.cancel'),
|
||||
},
|
||||
).then(async () => {
|
||||
await updateContainer(dialogData.value.rowData!)
|
||||
.then(() => {
|
||||
loading.value = false;
|
||||
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
||||
emit('search');
|
||||
drawerVisiable.value = false;
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
});
|
||||
)
|
||||
.then(async () => {
|
||||
await updateContainer(dialogData.value.rowData!)
|
||||
.then(() => {
|
||||
loading.value = false;
|
||||
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
||||
emit('search');
|
||||
drawerVisiable.value = false;
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue