@@ -93,7 +93,7 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e
9393 return nil , err
9494 }
9595 }
96-
96+ var hostPorts [] string
9797 switch create .Type {
9898 case constant .RuntimePHP :
9999 if create .Resource == constant .ResourceLocal {
@@ -116,17 +116,12 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e
116116 }
117117 create .Install = true
118118 for _ , export := range create .ExposedPorts {
119+ hostPorts = append (hostPorts , strconv .Itoa (export .HostPort ))
119120 if err := checkPortExist (export .HostPort ); err != nil {
120121 return nil , err
121122 }
122123 }
123124 }
124- portValue , _ := create .Params ["PANEL_APP_PORT_HTTP" ]
125- if portValue != nil {
126- if err := checkPortExist (int (portValue .(float64 ))); err != nil {
127- return nil , err
128- }
129- }
130125 containerName , ok := create .Params ["CONTAINER_NAME" ]
131126 if ! ok {
132127 return nil , buserr .New ("ErrContainerNameIsNull" )
@@ -159,7 +154,7 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e
159154 Resource : create .Resource ,
160155 Version : create .Version ,
161156 ContainerName : containerName .(string ),
162- Port : int ( portValue .( float64 ) ),
157+ Port : strings . Join ( hostPorts , "," ),
163158 }
164159
165160 switch create .Type {
@@ -352,34 +347,30 @@ func (r *RuntimeService) Get(id uint) (*response.RuntimeDTO, error) {
352347 return nil , err
353348 }
354349 for k , v := range envs {
355- switch k {
356- case "APP_PORT" , "PANEL_APP_PORT_HTTP" :
357- port , err := strconv .Atoi (v )
358- if err != nil {
359- return nil , err
360- }
361- res .Params [k ] = port
362- default :
363- if strings .Contains (k , "CONTAINER_PORT" ) || strings .Contains (k , "HOST_PORT" ) {
364- if strings .Contains (k , "CONTAINER_PORT" ) {
365- r := regexp .MustCompile (`_(\d+)$` )
366- matches := r .FindStringSubmatch (k )
367- containerPort , err := strconv .Atoi (v )
368- if err != nil {
369- return nil , err
370- }
371- hostPort , err := strconv .Atoi (envs [fmt .Sprintf ("HOST_PORT_%s" , matches [1 ])])
372- if err != nil {
373- return nil , err
374- }
375- res .ExposedPorts = append (res .ExposedPorts , request.ExposedPort {
376- ContainerPort : containerPort ,
377- HostPort : hostPort ,
378- })
350+ if strings .Contains (k , "CONTAINER_PORT" ) || strings .Contains (k , "HOST_PORT" ) {
351+ if strings .Contains (k , "CONTAINER_PORT" ) {
352+ r := regexp .MustCompile (`_(\d+)$` )
353+ matches := r .FindStringSubmatch (k )
354+ containerPort , err := strconv .Atoi (v )
355+ if err != nil {
356+ return nil , err
379357 }
380- } else {
381- res .Params [k ] = v
358+ hostPort , err := strconv .Atoi (envs [fmt .Sprintf ("HOST_PORT_%s" , matches [1 ])])
359+ if err != nil {
360+ return nil , err
361+ }
362+ hostIP := envs [fmt .Sprintf ("HOST_IP_%s" , matches [1 ])]
363+ if hostIP == "" {
364+ hostIP = "0.0.0.0"
365+ }
366+ res .ExposedPorts = append (res .ExposedPorts , request.ExposedPort {
367+ ContainerPort : containerPort ,
368+ HostPort : hostPort ,
369+ HostIP : hostIP ,
370+ })
382371 }
372+ } else {
373+ res .Params [k ] = v
383374 }
384375 }
385376 if v , ok := envs ["CONTAINER_PACKAGE_URL" ]; ok {
@@ -437,22 +428,17 @@ func (r *RuntimeService) Update(req request.RuntimeUpdate) error {
437428 }
438429 oldImage := runtime .Image
439430 oldEnv := runtime .Env
440- port := int ( req . Params [ "PANEL_APP_PORT_HTTP" ].( float64 ))
431+ var hostPorts [] string
441432 switch runtime .Type {
442433 case constant .RuntimePHP :
443434 exist , _ := runtimeRepo .GetFirst (runtimeRepo .WithImage (req .Name ), runtimeRepo .WithNotId (req .ID ))
444435 if exist != nil {
445436 return buserr .New ("ErrImageExist" )
446437 }
447438 case constant .RuntimeNode , constant .RuntimeJava , constant .RuntimeGo , constant .RuntimePython , constant .RuntimeDotNet :
448- if runtime .Port != port {
449- if err = checkPortExist (port ); err != nil {
450- return err
451- }
452- runtime .Port = port
453- }
454439 for _ , export := range req .ExposedPorts {
455- if err = checkPortExist (export .HostPort ); err != nil {
440+ hostPorts = append (hostPorts , strconv .Itoa (export .HostPort ))
441+ if err = checkRuntimePortExist (export .HostPort , false , runtime .ID ); err != nil {
456442 return err
457443 }
458444 }
@@ -522,7 +508,7 @@ func (r *RuntimeService) Update(req request.RuntimeUpdate) error {
522508 case constant .RuntimeNode , constant .RuntimeJava , constant .RuntimeGo , constant .RuntimePython , constant .RuntimeDotNet :
523509 runtime .Version = req .Version
524510 runtime .CodeDir = req .CodeDir
525- runtime .Port = port
511+ runtime .Port = strings . Join ( hostPorts , "," )
526512 runtime .Status = constant .RuntimeReCreating
527513 _ = runtimeRepo .Save (runtime )
528514 go reCreateRuntime (runtime )
0 commit comments