From 41be181c7d3ca023dd4780d18ac01da489aa0229 Mon Sep 17 00:00:00 2001 From: ssongliu Date: Tue, 6 Dec 2022 17:24:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20compose=20=E8=AF=A6=E6=83=85=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E5=A2=9E=E5=8A=A0=E5=90=AF=E5=8A=A8=E3=80=81=E5=81=9C?= =?UTF-8?q?=E6=AD=A2=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/v1/compose_template.go | 2 - backend/app/dto/compose_template.go | 6 - backend/app/dto/container.go | 2 +- backend/app/model/compose_template.go | 2 - backend/app/service/container_compose.go | 9 +- frontend/src/api/interface/container.ts | 1 + frontend/src/lang/modules/en.ts | 4 +- frontend/src/lang/modules/zh.ts | 5 +- .../views/container/compose/detail/index.vue | 255 ++++++++++-------- .../src/views/container/compose/index.vue | 95 ++++--- .../src/views/container/template/index.vue | 13 +- .../container/template/operator/index.vue | 32 +-- 12 files changed, 222 insertions(+), 204 deletions(-) diff --git a/backend/app/api/v1/compose_template.go b/backend/app/api/v1/compose_template.go index 75f1ea8a3..18ed7af43 100644 --- a/backend/app/api/v1/compose_template.go +++ b/backend/app/api/v1/compose_template.go @@ -89,8 +89,6 @@ func (b *BaseApi) UpdateComposeTemplate(c *gin.Context) { } upMap := make(map[string]interface{}) - upMap["from"] = req.From - upMap["path"] = req.Path upMap["content"] = req.Content upMap["description"] = req.Description if err := composeTemplateService.Update(id, upMap); err != nil { diff --git a/backend/app/dto/compose_template.go b/backend/app/dto/compose_template.go index 140ae6143..9c41aa2bf 100644 --- a/backend/app/dto/compose_template.go +++ b/backend/app/dto/compose_template.go @@ -4,16 +4,12 @@ import "time" type ComposeTemplateCreate struct { Name string `json:"name" validate:"required"` - From string `json:"from" validate:"required,oneof=edit path"` Description string `json:"description"` - Path string `json:"path"` Content string `json:"content"` } type ComposeTemplateUpdate struct { - From string `json:"from" validate:"required,oneof=edit path"` Description string `json:"description"` - Path string `json:"path"` Content string `json:"content"` } @@ -21,8 +17,6 @@ type ComposeTemplateInfo struct { ID uint `json:"id"` CreatedAt time.Time `json:"createdAt"` Name string `json:"name"` - From string `json:"from"` Description string `json:"description"` - Path string `json:"path"` Content string `json:"content"` } diff --git a/backend/app/dto/container.go b/backend/app/dto/container.go index 9be3bdae8..61683a17e 100644 --- a/backend/app/dto/container.go +++ b/backend/app/dto/container.go @@ -135,7 +135,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 stop down"` + Operation string `json:"operation" validate:"required,oneof=start stop down"` } type ComposeUpdate struct { Path string `json:"path" validate:"required"` diff --git a/backend/app/model/compose_template.go b/backend/app/model/compose_template.go index f604caea7..5d5192eb3 100644 --- a/backend/app/model/compose_template.go +++ b/backend/app/model/compose_template.go @@ -4,9 +4,7 @@ type ComposeTemplate struct { BaseModel Name string `gorm:"type:varchar(64);not null;unique" json:"name"` - From string `gorm:"type:varchar(64);not null" json:"from"` Description string `gorm:"type:varchar(256)" json:"description"` - Path string `gorm:"type:varchar(64)" json:"path"` Content string `gorm:"type:longtext" json:"content"` } diff --git a/backend/app/service/container_compose.go b/backend/app/service/container_compose.go index 0c898673b..6d904c37a 100644 --- a/backend/app/service/container_compose.go +++ b/backend/app/service/container_compose.go @@ -114,12 +114,8 @@ func (u *ContainerService) CreateCompose(req dto.ComposeCreate) error { if err != nil { return err } - req.From = template.From - if req.From == "edit" { - req.File = template.Content - } else { - req.Path = template.Path - } + req.From = "edit" + req.File = template.Content } if req.From == "edit" { dir := fmt.Sprintf("%s/%s", constant.TmpComposeBuildDir, req.Name) @@ -159,6 +155,7 @@ func (u *ContainerService) ComposeOperation(req dto.ComposeOperation) error { global.LOG.Debugf("docker-compose %s %s successful", req.Operation, req.Name) if req.Operation == "down" { _ = composeRepo.DeleteRecord(commonRepo.WithByName(req.Name)) + _ = os.RemoveAll(strings.ReplaceAll(req.Path, req.Name+"/docker-compose.yml", "")) } return nil diff --git a/frontend/src/api/interface/container.ts b/frontend/src/api/interface/container.ts index b3cc176f9..6e86df8be 100644 --- a/frontend/src/api/interface/container.ts +++ b/frontend/src/api/interface/container.ts @@ -193,6 +193,7 @@ export namespace Container { template: number; } export interface ComposeOpration { + name: string; operation: string; path: string; } diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 874840323..5f8e77c82 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -446,7 +446,9 @@ export default { containerNumber: 'Container number', down: 'Down', up: 'Up', - operatorComposeHelper: '{0} will be performed on the selected compose. Do you want to continue?', + 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?', }, cronjob: { cronTask: 'Task', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index f80fc4cc8..98d5c4c96 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -355,7 +355,7 @@ export default { pause: '暂停', unpause: '恢复', rename: '重命名', - remove: '移除', + remove: '删除', container: '容器', upTime: '运行时长', all: '全部', @@ -455,7 +455,8 @@ export default { containerNumber: '容器数量', down: '删除', up: '启动', - operatorComposeHelper: '将对选中 Compose 进行 {0} 操作,是否继续?', + composeDetailHelper: '该 compose 为 1Panel 编排外部创建。暂不支持启停操作。', + composeOperatorHelper: '将对 {0} 进行 {1} 操作,是否继续?', setting: '容器配置', mirrors: '镜像加速', diff --git a/frontend/src/views/container/compose/detail/index.vue b/frontend/src/views/container/compose/detail/index.vue index 72e2bce61..cb0aecc6e 100644 --- a/frontend/src/views/container/compose/detail/index.vue +++ b/frontend/src/views/container/compose/detail/index.vue @@ -1,100 +1,102 @@