From 958993f81f9ebab3dfa46e2c68a2f9d7cc650a5d Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Wed, 9 Oct 2024 17:26:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=A2=9E=E5=8A=A0=E6=8C=82=E8=BD=BD=20(#6662?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs https://github.com/1Panel-dev/1Panel/issues/5837 --- agent/app/dto/request/runtime.go | 5 ++ agent/app/dto/response/runtime.go | 1 + agent/app/service/runtime.go | 27 +++++++ agent/app/service/runtime_utils.go | 45 +++++++++++ agent/constant/runtime.go | 13 +++ agent/utils/docker/compose.go | 1 + agent/utils/nginx/components/location.go | 2 + frontend/src/api/interface/runtime.ts | 6 ++ frontend/src/components/group/change.vue | 46 ++++------- .../src/views/app-store/installed/index.vue | 2 +- .../views/container/image/delete/index.vue | 72 +++++++---------- .../src/views/container/image/save/index.vue | 79 ++++++++----------- .../views/container/setting/ipv6/index.vue | 63 ++++++--------- .../src/views/container/setting/log/index.vue | 60 +++++--------- .../views/container/setting/mirror/index.vue | 44 ++++------- .../container/setting/registry/index.vue | 45 ++++------- .../container/setting/sock-path/index.vue | 46 ++++------- .../database/postgresql/privileges/index.vue | 50 +++++------- .../website/runtime/environment/index.vue | 51 ++++++------ .../website/runtime/go/operate/index.vue | 4 + .../views/website/runtime/volume/index.vue | 60 ++++++++++++++ .../config/basic/proxy/create/index.vue | 1 - 22 files changed, 373 insertions(+), 350 deletions(-) create mode 100644 frontend/src/views/website/runtime/volume/index.vue diff --git a/agent/app/dto/request/runtime.go b/agent/app/dto/request/runtime.go index a1286185e..8e6045f58 100644 --- a/agent/app/dto/request/runtime.go +++ b/agent/app/dto/request/runtime.go @@ -30,12 +30,17 @@ type NodeConfig struct { Port int `json:"port"` ExposedPorts []ExposedPort `json:"exposedPorts"` Environments []Environment `json:"environments"` + Volumes []Volume `json:"volumes"` } type Environment struct { Key string `json:"key"` Value string `json:"value"` } +type Volume struct { + Source string `json:"source"` + Target string `json:"target"` +} type ExposedPort struct { HostPort int `json:"hostPort"` diff --git a/agent/app/dto/response/runtime.go b/agent/app/dto/response/runtime.go index e1f556799..16a9de36d 100644 --- a/agent/app/dto/response/runtime.go +++ b/agent/app/dto/response/runtime.go @@ -27,6 +27,7 @@ type RuntimeDTO struct { Path string `json:"path"` ExposedPorts []request.ExposedPort `json:"exposedPorts"` Environments []request.Environment `json:"environments"` + Volumes []request.Volume `json:"volumes"` } type PackageScripts struct { diff --git a/agent/app/service/runtime.go b/agent/app/service/runtime.go index 896455ce8..9adb284ac 100644 --- a/agent/app/service/runtime.go +++ b/agent/app/service/runtime.go @@ -387,6 +387,32 @@ func (r *RuntimeService) Get(id uint) (*response.RuntimeDTO, error) { if err != nil { return nil, err } + volumes, err := getDockerComposeVolumes(composeByte) + if err != nil { + return nil, err + } + + defaultVolumes := make(map[string]string) + switch runtime.Type { + case constant.RuntimeNode: + defaultVolumes = constant.RuntimeDefaultVolumes + case constant.RuntimeJava: + defaultVolumes = constant.RuntimeDefaultVolumes + case constant.RuntimeGo: + defaultVolumes = constant.GoDefaultVolumes + } + for _, volume := range volumes { + exist := false + for key, value := range defaultVolumes { + if key == volume.Source && value == volume.Target { + exist = true + break + } + } + if !exist { + res.Volumes = append(res.Volumes, volume) + } + } } return &res, nil @@ -461,6 +487,7 @@ func (r *RuntimeService) Update(req request.RuntimeUpdate) error { Install: true, ExposedPorts: req.ExposedPorts, Environments: req.Environments, + Volumes: req.Volumes, }, } composeContent, envContent, _, err := handleParams(create, projectDir) diff --git a/agent/app/service/runtime_utils.go b/agent/app/service/runtime_utils.go index 84c13930b..87d4b985b 100644 --- a/agent/app/service/runtime_utils.go +++ b/agent/app/service/runtime_utils.go @@ -474,9 +474,27 @@ func handleCompose(env gotenv.Env, composeContent []byte, create request.Runtime for _, e := range create.Environments { environments = append(environments, fmt.Sprintf("%s:%s", e.Key, e.Value)) } + delete(serviceValue, "environment") if len(environments) > 0 { serviceValue["environment"] = environments } + var volumes []interface{} + defaultVolumes := make(map[string]string) + switch create.Type { + case constant.RuntimeNode: + defaultVolumes = constant.RuntimeDefaultVolumes + case constant.RuntimeJava: + defaultVolumes = constant.RuntimeDefaultVolumes + case constant.RuntimeGo: + defaultVolumes = constant.GoDefaultVolumes + } + for k, v := range defaultVolumes { + volumes = append(volumes, fmt.Sprintf("%s:%s", k, v)) + } + for _, volume := range create.Volumes { + volumes = append(volumes, fmt.Sprintf("%s:%s", volume.Source, volume.Target)) + } + serviceValue["volumes"] = volumes break } for k := range env { @@ -648,3 +666,30 @@ func getDockerComposeEnvironments(yml []byte) ([]request.Environment, error) { } return res, nil } + +func getDockerComposeVolumes(yml []byte) ([]request.Volume, error) { + var ( + composeProject docker.ComposeProject + err error + ) + err = yaml.Unmarshal(yml, &composeProject) + if err != nil { + return nil, err + } + var res []request.Volume + for _, service := range composeProject.Services { + for _, volume := range service.Volumes { + envArray := strings.Split(volume, ":") + source := envArray[0] + target := "" + if len(envArray) > 1 { + target = envArray[1] + } + res = append(res, request.Volume{ + Source: source, + Target: target, + }) + } + } + return res, nil +} diff --git a/agent/constant/runtime.go b/agent/constant/runtime.go index f2aa70e8a..28c0967c4 100644 --- a/agent/constant/runtime.go +++ b/agent/constant/runtime.go @@ -34,3 +34,16 @@ const ( RuntimeNpm = "npm" RuntimeYarn = "yarn" ) + +var GoDefaultVolumes = map[string]string{ + "${CODE_DIR}": "/app", + "./run.sh": "/run.sh", + "./.env": "/.env", + "./mod": "/go/pkg/mod", +} + +var RuntimeDefaultVolumes = map[string]string{ + "./run.sh": "/run.sh", + "./.env": "/.env", + "./mod": "/go/pkg/mod", +} diff --git a/agent/utils/docker/compose.go b/agent/utils/docker/compose.go index 82800b877..28e2bba3a 100644 --- a/agent/utils/docker/compose.go +++ b/agent/utils/docker/compose.go @@ -55,6 +55,7 @@ type ComposeProject struct { type Service struct { Image string `yaml:"image"` Environment []string `yaml:"environment"` + Volumes []string `json:"volumes"` } func replaceEnvVariables(input string, envVars map[string]string) string { diff --git a/agent/utils/nginx/components/location.go b/agent/utils/nginx/components/location.go index e41505305..0436905d0 100644 --- a/agent/utils/nginx/components/location.go +++ b/agent/utils/nginx/components/location.go @@ -234,11 +234,13 @@ func (l *Location) AddSubFilter(subFilters map[string]string) { } l.UpdateDirective("proxy_set_header", []string{"Accept-Encoding", `""`}) l.UpdateDirective("sub_filter_once", []string{"off"}) + l.UpdateDirective("sub_filter_types", []string{"*"}) } func (l *Location) RemoveSubFilter() { l.RemoveDirective("sub_filter", []string{}) l.RemoveDirective("proxy_set_header", []string{"Accept-Encoding", `""`}) l.RemoveDirective("sub_filter_once", []string{"off"}) + l.RemoveDirective("sub_filter_types", []string{"*"}) l.Replaces = nil } diff --git a/frontend/src/api/interface/runtime.ts b/frontend/src/api/interface/runtime.ts index a6dd49b15..4ae8861b6 100644 --- a/frontend/src/api/interface/runtime.ts +++ b/frontend/src/api/interface/runtime.ts @@ -40,6 +40,7 @@ export namespace Runtime { path?: string; exposedPorts?: ExposedPort[]; environments?: Environment[]; + volumes?: Volume[]; } export interface RuntimeCreate { @@ -58,6 +59,7 @@ export namespace Runtime { port?: number; exposedPorts?: ExposedPort[]; environments?: Environment[]; + volumes?: Volume[]; } export interface ExposedPort { @@ -69,6 +71,10 @@ export namespace Runtime { key: string; value: string; } + export interface Volume { + source: string; + target: string; + } export interface RuntimeUpdate { name: string; diff --git a/frontend/src/components/group/change.vue b/frontend/src/components/group/change.vue index 4ddc05735..5cebb7a0c 100644 --- a/frontend/src/components/group/change.vue +++ b/frontend/src/components/group/change.vue @@ -1,37 +1,22 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + - - {{ $t('commons.button.cancel') }} - - {{ $t('commons.button.confirm') }} - - + {{ $t('commons.button.cancel') }} + + {{ $t('commons.button.confirm') }} + - + @@ -40,7 +25,6 @@ import { ref, reactive } from 'vue'; import type { ElForm } from 'element-plus'; import { Rules } from '@/global/form-rules'; import { GetGroupList } from '@/api/modules/group'; -import DrawerHeader from '@/components/drawer-header/index.vue'; const loading = ref(); interface DialogProps { diff --git a/frontend/src/views/app-store/installed/index.vue b/frontend/src/views/app-store/installed/index.vue index 8116a5342..9351f47d7 100644 --- a/frontend/src/views/app-store/installed/index.vue +++ b/frontend/src/views/app-store/installed/index.vue @@ -62,7 +62,7 @@ - + - - - - + - - - - - - {{ $t('container.removeAll') }} - - - - - - - - - - + + + + {{ $t('container.removeAll') }} + + + + + + + + - - {{ $t('commons.button.cancel') }} - - {{ $t('commons.button.delete') }} - - + {{ $t('commons.button.cancel') }} + + {{ $t('commons.button.delete') }} + - + @@ -55,7 +40,6 @@ import { reactive, ref } from 'vue'; import { ElForm } from 'element-plus'; import { imageRemove } from '@/api/modules/container'; -import DrawerHeader from '@/components/drawer-header/index.vue'; import i18n from '@/lang'; const deleteVisible = ref(false); diff --git a/frontend/src/views/container/image/save/index.vue b/frontend/src/views/container/image/save/index.vue index b2ef32b2a..03d849921 100644 --- a/frontend/src/views/container/image/save/index.vue +++ b/frontend/src/views/container/image/save/index.vue @@ -1,55 +1,39 @@ - - - - + - - - - - - - - - - - - - - - - - .tar - - - - + + + + + + + + + + + + + + + .tar + + - - - - {{ $t('commons.button.cancel') }} - - - {{ $t('container.export') }} - - + + {{ $t('commons.button.cancel') }} + + + {{ $t('container.export') }} + - + diff --git a/frontend/src/views/website/website/config/basic/proxy/create/index.vue b/frontend/src/views/website/website/config/basic/proxy/create/index.vue index 381c8758c..a8208a260 100644 --- a/frontend/src/views/website/website/config/basic/proxy/create/index.vue +++ b/frontend/src/views/website/website/config/basic/proxy/create/index.vue @@ -97,7 +97,6 @@