Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 增加 Python 运行环境 #6681

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions backend/app/service/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e
if exist != nil {
return nil, buserr.New(constant.ErrImageExist)
}
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo:
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython:
if !fileOp.Stat(create.CodeDir) {
return nil, buserr.New(constant.ErrPathNotFound)
}
Expand Down Expand Up @@ -133,7 +133,7 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e
if err = handlePHP(create, runtime, fileOp, appVersionDir); err != nil {
return nil, err
}
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo:
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython:
runtime.Port = create.Port
if err = handleNodeAndJava(create, runtime, fileOp, appVersionDir); err != nil {
return nil, err
Expand Down Expand Up @@ -217,7 +217,7 @@ func (r *RuntimeService) Delete(runtimeDelete request.RuntimeDelete) error {
global.LOG.Errorf("delete image id [%s] error %v", imageID, err)
}
}
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo:
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython:
if out, err := compose.Down(runtime.GetComposePath()); err != nil && !runtimeDelete.ForceDelete {
if out != "" {
return errors.New(out)
Expand Down Expand Up @@ -300,7 +300,7 @@ func (r *RuntimeService) Get(id uint) (*response.RuntimeDTO, error) {
}
}
res.AppParams = appParams
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo:
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython:
res.Params = make(map[string]interface{})
envs, err := gotenv.Unmarshal(runtime.Env)
if err != nil {
Expand Down Expand Up @@ -361,7 +361,7 @@ func (r *RuntimeService) Update(req request.RuntimeUpdate) error {
if exist != nil {
return buserr.New(constant.ErrImageExist)
}
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo:
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython:
if runtime.Port != req.Port {
if err = checkPortExist(req.Port); err != nil {
return err
Expand Down Expand Up @@ -441,7 +441,7 @@ func (r *RuntimeService) Update(req request.RuntimeUpdate) error {
return err
}
go buildRuntime(runtime, imageID, req.Rebuild)
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo:
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython:
runtime.Version = req.Version
runtime.CodeDir = req.CodeDir
runtime.Port = req.Port
Expand Down
11 changes: 10 additions & 1 deletion backend/app/service/runtime_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,14 @@ func handleParams(create request.RuntimeCreate, projectDir string) (composeConte
if err != nil {
return
}
case constant.RuntimePython:
create.Params["CODE_DIR"] = create.CodeDir
create.Params["PYTHON_VERSION"] = create.Version
create.Params["PANEL_APP_PORT_HTTP"] = create.Port
composeContent, err = handleCompose(env, composeContent, create, projectDir)
if err != nil {
return
}
}

newMap := make(map[string]string)
Expand Down Expand Up @@ -384,7 +392,8 @@ func handleCompose(env gotenv.Env, composeContent []byte, create request.Runtime
ports = append(ports, "${HOST_IP}:${PANEL_APP_PORT_HTTP}:${JAVA_APP_PORT}")
case constant.RuntimeGo:
ports = append(ports, "${HOST_IP}:${PANEL_APP_PORT_HTTP}:${GO_APP_PORT}")

case constant.RuntimePython:
ports = append(ports, "${HOST_IP}:${PANEL_APP_PORT_HTTP}:${APP_PORT}")
}

for i, port := range create.ExposedPorts {
Expand Down
2 changes: 1 addition & 1 deletion backend/app/service/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
}
website.Proxy = proxy
}
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo:
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython:
website.Proxy = fmt.Sprintf("127.0.0.1:%d", runtime.Port)
}
}
Expand Down
2 changes: 1 addition & 1 deletion backend/app/service/website_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func configDefaultNginx(website *model.Website, domains []model.WebsiteDomain, a
server.UpdateRoot(rootIndex)
server.UpdatePHPProxy([]string{website.Proxy}, "")
}
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo:
case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython:
proxy := fmt.Sprintf("http://127.0.0.1:%d", runtime.Port)
server.UpdateRootProxy([]string{proxy})
}
Expand Down
9 changes: 5 additions & 4 deletions backend/constant/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ const (
RuntimeUnhealthy = "unhealthy"
RuntimeCreating = "creating"

RuntimePHP = "php"
RuntimeNode = "node"
RuntimeJava = "java"
RuntimeGo = "go"
RuntimePHP = "php"
RuntimeNode = "node"
RuntimeJava = "java"
RuntimeGo = "go"
RuntimePython = "python"

RuntimeProxyUnix = "unix"
RuntimeProxyTcp = "tcp"
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lang/modules/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2388,6 +2388,8 @@ const message = {
javaDirHelper: 'The directory must contain jar files, subdirectories are also acceptable',
goHelper: 'Please provide a complete start command, for example: go run main.go or ./main',
goDirHelper: 'The directory must contain go files or binary files, subdirectories are also acceptable',
pythonHelper:
'Please fill in the complete startup command, for example: pip install -r requirements.txt && python manage.py runserver 0.0.0.0:5000',
},
process: {
pid: 'Process ID',
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lang/modules/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2214,6 +2214,8 @@ const message = {
javaDirHelper: '目錄中要包含 jar 包,子目錄中包含也可',
goHelper: '請填寫完整啟動命令,例如:go run main.go 或 ./main',
goDirHelper: '目錄中要包含 go 文件或者二進制文件,子目錄中包含也可',
pythonHelper:
'請填入完整啟動指令,例如:pip install -r requirements.txt && python manage.py runserver 0.0.0.0:5000',
},
process: {
pid: '進程ID',
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lang/modules/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2217,6 +2217,8 @@ const message = {
javaDirHelper: '目录中要包含 jar 包,子目录中包含也可',
goHelper: '请填写完整启动命令,例如:go run main.go 或 ./main',
goDirHelper: '目录中要包含 go 文件或者二进制文件,子目录中包含也可',
pythonHelper:
'请填写完整启动命令,例如:pip install -r requirements.txt && python manage.py runserver 0.0.0.0:5000',
},
process: {
pid: '进程ID',
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/routers/modules/website.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ const webSiteRouter = {
requiresAuth: false,
},
},
{
path: '/websites/runtimes/python',
name: 'python',
hidden: true,
component: () => import('@/views/website/runtime/python/index.vue'),
meta: {
activeMenu: '/websites/runtimes/python',
requiresAuth: false,
},
},
],
};

Expand Down
9 changes: 2 additions & 7 deletions frontend/src/views/app-store/apps/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,11 @@ const search = async (req: App.AppReq) => {
const openInstall = (app: App.App) => {
switch (app.type) {
case 'php':
router.push({ path: '/websites/runtimes/php' });
break;
case 'node':
router.push({ path: '/websites/runtimes/node' });
break;
case 'java':
router.push({ path: '/websites/runtimes/java' });
break;
case 'go':
router.push({ path: '/websites/runtimes/go' });
case 'python':
router.push({ path: '/websites/runtimes/' + app.type });
break;
default:
const params = {
Expand Down
9 changes: 2 additions & 7 deletions frontend/src/views/app-store/detail/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,11 @@ const toLink = (link: string) => {
const openInstall = () => {
switch (app.value.type) {
case 'php':
router.push({ path: '/websites/runtimes/php' });
break;
case 'node':
router.push({ path: '/websites/runtimes/node' });
break;
case 'java':
router.push({ path: '/websites/runtimes/java' });
break;
case 'go':
router.push({ path: '/websites/runtimes/go' });
case 'python':
router.push({ path: '/websites/runtimes/' + app.value.type });
break;
default:
const params = {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/views/website/runtime/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ const buttons = [
label: 'Go',
path: '/websites/runtimes/go',
},
{
label: 'Python',
path: '/websites/runtimes/python',
},
];
</script>
Loading
Loading