Skip to content

Commit c6346b7

Browse files
feat(runtime): Optimize Runtime Module Components (#7548)
1 parent 18321d6 commit c6346b7

File tree

17 files changed

+358
-839
lines changed

17 files changed

+358
-839
lines changed

agent/app/dto/request/runtime.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ type RuntimeCreate struct {
2727
type NodeConfig struct {
2828
Install bool `json:"install"`
2929
Clean bool `json:"clean"`
30-
Port int `json:"port"`
3130
ExposedPorts []ExposedPort `json:"exposedPorts"`
3231
Environments []Environment `json:"environments"`
3332
Volumes []Volume `json:"volumes"`

agent/app/model/runtime.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
type Runtime struct {
1010
BaseModel
1111
Name string `gorm:"not null" json:"name"`
12-
AppDetailID uint `json:"appDetailId"`
12+
AppDetailID uint `json:"appDetailID"`
1313
Image string `json:"image"`
1414
WorkDir string `json:"workDir"`
1515
DockerCompose string `json:"dockerCompose"`

agent/app/service/runtime.go

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,26 +109,23 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e
109109
if exist != nil {
110110
return nil, buserr.New(constant.ErrImageExist)
111111
}
112-
portValue, _ := create.Params["PANEL_APP_PORT_HTTP"]
113-
if portValue != nil {
114-
if err := checkPortExist(int(portValue.(float64))); err != nil {
115-
return nil, err
116-
}
117-
}
118112
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython, constant.RuntimeDotNet:
119113
if !fileOp.Stat(create.CodeDir) {
120114
return nil, buserr.New(constant.ErrPathNotFound)
121115
}
122116
create.Install = true
123-
if err := checkPortExist(create.Port); err != nil {
124-
return nil, err
125-
}
126117
for _, export := range create.ExposedPorts {
127118
if err := checkPortExist(export.HostPort); err != nil {
128119
return nil, err
129120
}
130121
}
131122
}
123+
portValue, _ := create.Params["PANEL_APP_PORT_HTTP"]
124+
if portValue != nil {
125+
if err := checkPortExist(int(portValue.(float64))); err != nil {
126+
return nil, err
127+
}
128+
}
132129
containerName, ok := create.Params["CONTAINER_NAME"]
133130
if !ok {
134131
return nil, buserr.New("ErrContainerNameIsNull")
@@ -161,17 +158,16 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e
161158
Resource: create.Resource,
162159
Version: create.Version,
163160
ContainerName: containerName.(string),
161+
Port: int(portValue.(float64)),
164162
}
165163

166164
switch create.Type {
167165
case constant.RuntimePHP:
168-
runtime.Port = int(create.Params["PANEL_APP_PORT_HTTP"].(float64))
169166
if err = handlePHP(create, runtime, fileOp, appVersionDir); err != nil {
170167
return nil, err
171168
}
172169
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython, constant.RuntimeDotNet:
173-
runtime.Port = int(create.Params["port"].(float64))
174-
if err = handleNodeAndJava(create, runtime, fileOp, appVersionDir); err != nil {
170+
if err = handleRuntime(create, runtime, fileOp, appVersionDir); err != nil {
175171
return nil, err
176172
}
177173
}
@@ -356,7 +352,7 @@ func (r *RuntimeService) Get(id uint) (*response.RuntimeDTO, error) {
356352
}
357353
for k, v := range envs {
358354
switch k {
359-
case "NODE_APP_PORT", "PANEL_APP_PORT_HTTP", "JAVA_APP_PORT", "GO_APP_PORT", "APP_PORT", "port":
355+
case "APP_PORT", "PANEL_APP_PORT_HTTP":
360356
port, err := strconv.Atoi(v)
361357
if err != nil {
362358
return nil, err
@@ -440,19 +436,19 @@ func (r *RuntimeService) Update(req request.RuntimeUpdate) error {
440436
}
441437
oldImage := runtime.Image
442438
oldEnv := runtime.Env
443-
req.Port = int(req.Params["port"].(float64))
439+
port := int(req.Params["PANEL_APP_PORT_HTTP"].(float64))
444440
switch runtime.Type {
445441
case constant.RuntimePHP:
446442
exist, _ := runtimeRepo.GetFirst(runtimeRepo.WithImage(req.Name), runtimeRepo.WithNotId(req.ID))
447443
if exist != nil {
448444
return buserr.New(constant.ErrImageExist)
449445
}
450446
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython, constant.RuntimeDotNet:
451-
if runtime.Port != req.Port {
452-
if err = checkPortExist(req.Port); err != nil {
447+
if runtime.Port != port {
448+
if err = checkPortExist(port); err != nil {
453449
return err
454450
}
455-
runtime.Port = req.Port
451+
runtime.Port = port
456452
}
457453
for _, export := range req.ExposedPorts {
458454
if err = checkPortExist(export.HostPort); err != nil {
@@ -494,7 +490,6 @@ func (r *RuntimeService) Update(req request.RuntimeUpdate) error {
494490
CodeDir: req.CodeDir,
495491
Version: req.Version,
496492
NodeConfig: request.NodeConfig{
497-
Port: req.Port,
498493
Install: true,
499494
ExposedPorts: req.ExposedPorts,
500495
Environments: req.Environments,
@@ -526,7 +521,7 @@ func (r *RuntimeService) Update(req request.RuntimeUpdate) error {
526521
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython, constant.RuntimeDotNet:
527522
runtime.Version = req.Version
528523
runtime.CodeDir = req.CodeDir
529-
runtime.Port = req.Port
524+
runtime.Port = port
530525
runtime.Status = constant.RuntimeReCreating
531526
_ = runtimeRepo.Save(runtime)
532527
go reCreateRuntime(runtime)

agent/app/service/runtime_utils.go

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"time"
3131
)
3232

33-
func handleNodeAndJava(create request.RuntimeCreate, runtime *model.Runtime, fileOp files.FileOp, appVersionDir string) (err error) {
33+
func handleRuntime(create request.RuntimeCreate, runtime *model.Runtime, fileOp files.FileOp, appVersionDir string) (err error) {
3434
runtimeDir := path.Join(constant.RuntimeDir, create.Type)
3535
if err = fileOp.CopyDir(appVersionDir, runtimeDir); err != nil {
3636
return
@@ -356,48 +356,40 @@ func handleParams(create request.RuntimeCreate, projectDir string) (composeConte
356356
case constant.RuntimeNode:
357357
create.Params["CODE_DIR"] = create.CodeDir
358358
create.Params["NODE_VERSION"] = create.Version
359-
create.Params["PANEL_APP_PORT_HTTP"] = create.Port
360359
if create.NodeConfig.Install {
361360
create.Params["RUN_INSTALL"] = "1"
362361
} else {
363362
create.Params["RUN_INSTALL"] = "0"
364363
}
365364
create.Params["CONTAINER_PACKAGE_URL"] = create.Source
366-
create.Params["NODE_APP_PORT"] = create.Params["APP_PORT"]
367365
composeContent, err = handleCompose(env, composeContent, create, projectDir)
368366
if err != nil {
369367
return
370368
}
371369
case constant.RuntimeJava:
372370
create.Params["CODE_DIR"] = create.CodeDir
373371
create.Params["JAVA_VERSION"] = create.Version
374-
create.Params["PANEL_APP_PORT_HTTP"] = create.Port
375-
create.Params["JAVA_APP_PORT"] = create.Params["APP_PORT"]
376372
composeContent, err = handleCompose(env, composeContent, create, projectDir)
377373
if err != nil {
378374
return
379375
}
380376
case constant.RuntimeGo:
381377
create.Params["CODE_DIR"] = create.CodeDir
382378
create.Params["GO_VERSION"] = create.Version
383-
create.Params["PANEL_APP_PORT_HTTP"] = create.Port
384-
create.Params["GO_APP_PORT"] = create.Params["APP_PORT"]
385379
composeContent, err = handleCompose(env, composeContent, create, projectDir)
386380
if err != nil {
387381
return
388382
}
389383
case constant.RuntimePython:
390384
create.Params["CODE_DIR"] = create.CodeDir
391385
create.Params["PYTHON_VERSION"] = create.Version
392-
create.Params["PANEL_APP_PORT_HTTP"] = create.Port
393386
composeContent, err = handleCompose(env, composeContent, create, projectDir)
394387
if err != nil {
395388
return
396389
}
397390
case constant.RuntimeDotNet:
398391
create.Params["CODE_DIR"] = create.CodeDir
399392
create.Params["DOTNET_VERSION"] = create.Version
400-
create.Params["PANEL_APP_PORT_HTTP"] = create.Port
401393
composeContent, err = handleCompose(env, composeContent, create, projectDir)
402394
if err != nil {
403395
return
@@ -440,17 +432,7 @@ func handleCompose(env gotenv.Env, composeContent []byte, create request.Runtime
440432
_, ok := serviceValue["ports"].([]interface{})
441433
if ok {
442434
var ports []interface{}
443-
switch create.Type {
444-
case constant.RuntimeNode:
445-
ports = append(ports, "${HOST_IP}:${PANEL_APP_PORT_HTTP}:${NODE_APP_PORT}")
446-
case constant.RuntimeJava:
447-
ports = append(ports, "${HOST_IP}:${PANEL_APP_PORT_HTTP}:${JAVA_APP_PORT}")
448-
case constant.RuntimeGo:
449-
ports = append(ports, "${HOST_IP}:${PANEL_APP_PORT_HTTP}:${GO_APP_PORT}")
450-
case constant.RuntimePython, constant.RuntimeDotNet:
451-
ports = append(ports, "${HOST_IP}:${PANEL_APP_PORT_HTTP}:${APP_PORT}")
452-
453-
}
435+
ports = append(ports, "${HOST_IP}:${PANEL_APP_PORT_HTTP}:${APP_PORT}")
454436
for i, port := range create.ExposedPorts {
455437
containerPortStr := fmt.Sprintf("CONTAINER_PORT_%d", i)
456438
hostPortStr := fmt.Sprintf("HOST_PORT_%d", i)

frontend/src/lang/modules/zh.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2374,7 +2374,7 @@ const message = {
23742374
appPort: '应用端口',
23752375
externalPort: '外部映射端口',
23762376
packageManager: '包管理器',
2377-
codeDir: '源码目录',
2377+
codeDir: '项目目录',
23782378
appPortHelper: '应用端口是指容器内部的端口',
23792379
externalPortHelper: '外部映射端口是指容器对外暴露的端口',
23802380
runScript: '启动命令',
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<template>
2+
<el-form-item :label="$t('runtime.app')" prop="appID">
3+
<el-row :gutter="20">
4+
<el-col :span="12">
5+
<el-select
6+
v-model="runtime.appID"
7+
:disabled="mode === 'edit'"
8+
@change="changeApp(runtime.appID)"
9+
class="p-w-200"
10+
>
11+
<el-option v-for="(app, index) in apps" :key="index" :label="app.name" :value="app.id"></el-option>
12+
</el-select>
13+
</el-col>
14+
<el-col :span="12">
15+
<el-select
16+
v-model="runtime.version"
17+
:disabled="mode === 'edit'"
18+
@change="changeVersion()"
19+
class="p-w-200"
20+
>
21+
<el-option
22+
v-for="(version, index) in appVersions"
23+
:key="index"
24+
:label="version"
25+
:value="version"
26+
></el-option>
27+
</el-select>
28+
</el-col>
29+
</el-row>
30+
</el-form-item>
31+
</template>
32+
33+
<script setup lang="ts">
34+
import { App } from '@/api/interface/app';
35+
import { GetApp, GetAppDetail, SearchApp } from '@/api/modules/app';
36+
import { useVModel } from '@vueuse/core';
37+
import { defineProps } from 'vue';
38+
39+
const props = defineProps({
40+
mode: {
41+
type: String,
42+
required: true,
43+
},
44+
appKey: {
45+
type: String,
46+
required: true,
47+
},
48+
modelValue: {
49+
type: Object,
50+
required: true,
51+
},
52+
});
53+
const apps = ref<App.App[]>([]);
54+
const appVersions = ref<string[]>([]);
55+
const emit = defineEmits(['update:modelValue']);
56+
const runtime = useVModel(props, 'modelValue', emit);
57+
const appReq = reactive({
58+
type: props.appKey,
59+
page: 1,
60+
pageSize: 20,
61+
resource: 'remote',
62+
});
63+
64+
const changeApp = (appID: number) => {
65+
for (const app of apps.value) {
66+
if (app.id === appID) {
67+
getApp(app.key, props.mode);
68+
break;
69+
}
70+
}
71+
};
72+
73+
const changeVersion = async () => {
74+
try {
75+
const res = await GetAppDetail(runtime.value.appID, runtime.value.version, 'runtime');
76+
runtime.value.appDetailID = res.data.id;
77+
} catch (error) {}
78+
};
79+
80+
const getApp = async (appkey: string, mode: string) => {
81+
try {
82+
const res = await GetApp(appkey);
83+
appVersions.value = res.data.versions || [];
84+
if (res.data.versions.length > 0) {
85+
if (mode === 'create') {
86+
runtime.value.version = res.data.versions[0];
87+
changeVersion();
88+
}
89+
}
90+
} catch (error) {}
91+
};
92+
93+
const searchApp = async (appID: number) => {
94+
try {
95+
const res = await SearchApp(appReq);
96+
apps.value = res.data.items || [];
97+
if (res.data && res.data.items && res.data.items.length > 0) {
98+
if (appID == null) {
99+
runtime.value.appID = res.data.items[0].id;
100+
getApp(res.data.items[0].key, props.mode);
101+
} else {
102+
res.data.items.forEach((item) => {
103+
if (item.id === appID) {
104+
getApp(item.key, props.mode);
105+
}
106+
});
107+
}
108+
}
109+
} catch (error) {}
110+
};
111+
112+
onMounted(() => {
113+
if (props.mode === 'create') {
114+
searchApp(null);
115+
} else {
116+
searchApp(runtime.value.appID);
117+
}
118+
});
119+
</script>

0 commit comments

Comments
 (0)