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: 增加 java 运行环境 #5576

Merged
merged 1 commit into from
Jun 26, 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
4 changes: 2 additions & 2 deletions backend/app/service/backup_website.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func handleWebsiteRecover(website *model.Website, recoverFile string, isRollback
if err != nil {
return err
}
if runtime.Type == constant.RuntimeNode {
if runtime.Type == constant.RuntimeNode || runtime.Type == constant.RuntimeJava {
if err := handleRuntimeRecover(runtime, fmt.Sprintf("%s/%s.runtime.tar.gz", tmpPath, website.Alias), true, ""); err != nil {
return err
}
Expand Down Expand Up @@ -225,7 +225,7 @@ func handleWebsiteBackup(website *model.Website, backupDir, fileName string, exc
if err != nil {
return err
}
if runtime.Type == constant.RuntimeNode {
if runtime.Type == constant.RuntimeNode || runtime.Type == constant.RuntimeJava {
if err := handleRuntimeBackup(runtime, tmpDir, fmt.Sprintf("%s.runtime.tar.gz", website.Alias), excludes, ""); err != nil {
return err
}
Expand Down
18 changes: 9 additions & 9 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:
case constant.RuntimeNode, constant.RuntimeJava:
if !fileOp.Stat(create.CodeDir) {
return nil, buserr.New(constant.ErrPathNotFound)
}
Expand Down Expand Up @@ -133,9 +133,9 @@ 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:
case constant.RuntimeNode, constant.RuntimeJava:
runtime.Port = create.Port
if err = handleNode(create, runtime, fileOp, appVersionDir); err != nil {
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:
case constant.RuntimeNode, constant.RuntimeJava:
if out, err := compose.Down(runtime.GetComposePath()); err != nil && !runtimeDelete.ForceDelete {
if out != "" {
return errors.New(out)
Expand Down Expand Up @@ -300,15 +300,15 @@ func (r *RuntimeService) Get(id uint) (*response.RuntimeDTO, error) {
}
}
res.AppParams = appParams
case constant.RuntimeNode:
case constant.RuntimeNode, constant.RuntimeJava:
res.Params = make(map[string]interface{})
envs, err := gotenv.Unmarshal(runtime.Env)
if err != nil {
return nil, err
}
for k, v := range envs {
switch k {
case "NODE_APP_PORT", "PANEL_APP_PORT_HTTP":
case "NODE_APP_PORT", "PANEL_APP_PORT_HTTP", "JAVA_APP_PORT":
port, err := strconv.Atoi(v)
if err != nil {
return nil, err
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:
case constant.RuntimeNode, constant.RuntimeJava:
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:
case constant.RuntimeNode, constant.RuntimeJava:
runtime.Version = req.Version
runtime.CodeDir = req.CodeDir
runtime.Port = req.Port
Expand Down Expand Up @@ -610,7 +610,7 @@ func (r *RuntimeService) SyncRuntimeStatus() error {
return err
}
for _, runtime := range runtimes {
if runtime.Type == constant.RuntimeNode {
if runtime.Type == constant.RuntimeNode || runtime.Type == constant.RuntimeJava {
_ = SyncRuntimeContainerStatus(&runtime)
}
}
Expand Down
23 changes: 19 additions & 4 deletions backend/app/service/runtime_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"gopkg.in/yaml.v3"
)

func handleNode(create request.RuntimeCreate, runtime *model.Runtime, fileOp files.FileOp, appVersionDir string) (err error) {
func handleNodeAndJava(create request.RuntimeCreate, runtime *model.Runtime, fileOp files.FileOp, appVersionDir string) (err error) {
runtimeDir := path.Join(constant.RuntimeDir, create.Type)
if err = fileOp.CopyDir(appVersionDir, runtimeDir); err != nil {
return
Expand Down Expand Up @@ -318,7 +318,15 @@ func handleParams(create request.RuntimeCreate, projectDir string) (composeConte
}
create.Params["CONTAINER_PACKAGE_URL"] = create.Source

composeContent, err = handleNodeCompose(env, composeContent, create, projectDir)
composeContent, err = handleCompose(env, composeContent, create, projectDir)
if err != nil {
return
}
case constant.RuntimeJava:
create.Params["CODE_DIR"] = create.CodeDir
create.Params["JAVA_VERSION"] = create.Version
create.Params["PANEL_APP_PORT_HTTP"] = create.Port
composeContent, err = handleCompose(env, composeContent, create, projectDir)
if err != nil {
return
}
Expand All @@ -341,7 +349,7 @@ func handleParams(create request.RuntimeCreate, projectDir string) (composeConte
return
}

func handleNodeCompose(env gotenv.Env, composeContent []byte, create request.RuntimeCreate, projectDir string) (composeByte []byte, err error) {
func handleCompose(env gotenv.Env, composeContent []byte, create request.RuntimeCreate, projectDir string) (composeByte []byte, err error) {
existMap := make(map[string]interface{})
composeMap := make(map[string]interface{})
if err = yaml.Unmarshal(composeContent, &composeMap); err != nil {
Expand All @@ -360,7 +368,14 @@ func handleNodeCompose(env gotenv.Env, composeContent []byte, create request.Run
_, ok := serviceValue["ports"].([]interface{})
if ok {
var ports []interface{}
ports = append(ports, "${HOST_IP}:${PANEL_APP_PORT_HTTP}:${NODE_APP_PORT}")

switch create.Type {
case constant.RuntimeNode:
ports = append(ports, "${HOST_IP}:${PANEL_APP_PORT_HTTP}:${NODE_APP_PORT}")
case constant.RuntimeJava:
ports = append(ports, "${HOST_IP}:${PANEL_APP_PORT_HTTP}:${JAVA_APP_PORT}")
}

for i, port := range create.ExposedPorts {
containerPortStr := fmt.Sprintf("CONTAINER_PORT_%d", i)
hostPortStr := fmt.Sprintf("HOST_PORT_%d", i)
Expand Down
8 changes: 3 additions & 5 deletions backend/app/service/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
}
website.Proxy = proxy
}
case constant.RuntimeNode:
case constant.RuntimeNode, constant.RuntimeJava:
website.Proxy = fmt.Sprintf("127.0.0.1:%d", runtime.Port)
}
}
Expand Down Expand Up @@ -540,9 +540,7 @@ func (w WebsiteService) CreateWebsiteDomain(create request.WebsiteDomainCreate)
}
for _, domain := range domainModels {
wafSite.Domains = append(wafSite.Domains, domain.Domain)
if domain.Port != 80 && domain.Port != 443 {
wafSite.Host = append(wafSite.Host, domain.Domain+":"+string(rune(domain.Port)))
}
wafSite.Host = append(wafSite.Host, domain.Domain+":"+strconv.Itoa(domain.Port))
}
if len(wafSite.Host) == 0 {
wafSite.Host = []string{}
Expand Down Expand Up @@ -634,7 +632,7 @@ func (w WebsiteService) DeleteWebsiteDomain(domainId uint) error {
oldHostArray := wafSite.Host
var newHostArray []string
for _, host := range oldHostArray {
if host == webSiteDomain.Domain+":"+string(rune(webSiteDomain.Port)) {
if host == webSiteDomain.Domain+":"+strconv.Itoa(webSiteDomain.Port) {
continue
}
newHostArray = append(newHostArray, host)
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:
case constant.RuntimeNode, constant.RuntimeJava:
proxy := fmt.Sprintf("http://127.0.0.1:%d", runtime.Port)
server.UpdateRootProxy([]string{proxy})
}
Expand Down
1 change: 1 addition & 0 deletions backend/constant/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (

RuntimePHP = "php"
RuntimeNode = "node"
RuntimeJava = "java"

RuntimeProxyUnix = "unix"
RuntimeProxyTcp = "tcp"
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2302,6 +2302,7 @@ const message = {
customScriptHelper: 'Please fill in the complete startup command, for example: npm run start',
portError: 'Cannot fill in the same port',
systemRestartHelper: 'Status description: Interruption - status acquisition failed due to system restart',
javaScriptHelper: 'Please fill in the complete startup command, for example: java -jar halo.jar',
},
process: {
pid: 'Process ID',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2138,6 +2138,7 @@ const message = {
customScriptHelper: '請填寫完整的啟動指令,例如:npm run start',
portError: '不能填寫相同連接埠',
systemRestartHelper: '狀態說明:中斷-系統重新啟動導致狀態取得失敗',
javaScriptHelper: '請填寫完整啟動指令,例如:java -jar halo.jar',
},
process: {
pid: '進程ID',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2141,6 +2141,7 @@ const message = {
customScriptHelper: '请填写完整的启动命令,例如:npm run start',
portError: '不能填写相同端口',
systemRestartHelper: '状态说明:中断-系统重启导致状态获取失败',
javaScriptHelper: '请填写完整启动命令,例如:java -jar halo.jar',
},
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 @@ -58,6 +58,16 @@ const webSiteRouter = {
requiresAuth: false,
},
},
{
path: '/websites/runtimes/java',
name: 'java',
hidden: true,
component: () => import('@/views/website/runtime/java/index.vue'),
meta: {
activeMenu: '/websites/runtimes/java',
requiresAuth: false,
},
},
],
};

Expand Down
3 changes: 3 additions & 0 deletions frontend/src/views/app-store/apps/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ const openInstall = (app: App.App) => {
case 'node':
router.push({ path: '/websites/runtimes/node' });
break;
case 'java':
router.push({ path: '/websites/runtimes/java' });
break;
default:
const params = {
app: app,
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 @@ -13,6 +13,10 @@ const buttons = [
label: 'PHP',
path: '/websites/runtimes/php',
},
{
label: 'Java',
path: '/websites/runtimes/java',
},
{
label: 'Node.js',
path: '/websites/runtimes/node',
Expand Down
Loading
Loading