-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: PHP runtime add php config #8922
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,8 @@ import ( | |
| "os/exec" | ||
| "path" | ||
| "path/filepath" | ||
| "regexp" | ||
| "strconv" | ||
| "strings" | ||
| "time" | ||
|
|
||
|
|
@@ -564,7 +566,14 @@ func handleCompose(env gotenv.Env, composeContent []byte, create request.Runtime | |
| create.Params[hostPortStr] = port.HostPort | ||
| create.Params[hostIPStr] = port.HostIP | ||
| } | ||
| if create.Type == constant.RuntimePHP { | ||
| ports = append(ports, fmt.Sprintf("127.0.0.1:${PANEL_APP_PORT_HTTP}:9000")) | ||
| } | ||
| serviceValue["ports"] = ports | ||
| } else { | ||
| if create.Type == constant.RuntimePHP { | ||
| serviceValue["ports"] = []interface{}{fmt.Sprintf("127.0.0.1:${PANEL_APP_PORT_HTTP}:9000")} | ||
| } | ||
| } | ||
| var environments []interface{} | ||
| for _, e := range create.Environments { | ||
|
|
@@ -581,6 +590,8 @@ func handleCompose(env gotenv.Env, composeContent []byte, create request.Runtime | |
| defaultVolumes = constant.RuntimeDefaultVolumes | ||
| case constant.RuntimeGo: | ||
| defaultVolumes = constant.GoDefaultVolumes | ||
| case constant.RuntimePHP: | ||
| defaultVolumes = constant.PHPDefaultVolumes | ||
| } | ||
| for k, v := range defaultVolumes { | ||
| volumes = append(volumes, fmt.Sprintf("%s:%s", k, v)) | ||
|
|
@@ -875,3 +886,76 @@ func RestartPHPRuntime() { | |
| }() | ||
| } | ||
| } | ||
|
|
||
| func handleRuntimeDTO(res *response.RuntimeDTO, runtime model.Runtime) error { | ||
| res.Params = make(map[string]interface{}) | ||
| envs, err := gotenv.Unmarshal(runtime.Env) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| for k, v := range envs { | ||
| if strings.Contains(k, "CONTAINER_PORT") || strings.Contains(k, "HOST_PORT") { | ||
| if strings.Contains(k, "CONTAINER_PORT") { | ||
| r := regexp.MustCompile(`_(\d+)$`) | ||
| matches := r.FindStringSubmatch(k) | ||
| containerPort, err := strconv.Atoi(v) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| hostPort, err := strconv.Atoi(envs[fmt.Sprintf("HOST_PORT_%s", matches[1])]) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| hostIP := envs[fmt.Sprintf("HOST_IP_%s", matches[1])] | ||
| if hostIP == "" { | ||
| hostIP = "0.0.0.0" | ||
| } | ||
| res.ExposedPorts = append(res.ExposedPorts, request.ExposedPort{ | ||
| ContainerPort: containerPort, | ||
| HostPort: hostPort, | ||
| HostIP: hostIP, | ||
| }) | ||
| } | ||
| } else { | ||
| res.Params[k] = v | ||
| } | ||
| } | ||
| if v, ok := envs["CONTAINER_PACKAGE_URL"]; ok { | ||
| res.Source = v | ||
| } | ||
| composeByte, err := files.NewFileOp().GetContent(runtime.GetComposePath()) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| res.Environments, err = getDockerComposeEnvironments(composeByte) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| volumes, err := getDockerComposeVolumes(composeByte) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| defaultVolumes := make(map[string]string) | ||
| switch runtime.Type { | ||
| case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimePython, constant.RuntimeDotNet: | ||
| defaultVolumes = constant.RuntimeDefaultVolumes | ||
| case constant.RuntimeGo: | ||
| defaultVolumes = constant.GoDefaultVolumes | ||
| case constant.RuntimePHP: | ||
| defaultVolumes = constant.PHPDefaultVolumes | ||
| } | ||
| 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 nil | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are several notable changes and improvements in the provided code:
Optimization Suggestions:
Overall, these changes make the code more robust and maintainable while ensuring consistent behavior across different execution contexts. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided code changes appear to focus on two main areas:
Changes in
GetMethodChanges in Methods for PHP-related Operations
Addition of New API Endpoint:
req) for a given runtime ID (req.ID). It includes checking port availability, environment variable updates, volume handling, and updating the Docker Compose file.Modification of Existing Logic:
UpdatePHPContainermethod creates a new instance ofcreate.RuntimeCreate, sets its fields based onreq, handles environments and volumes using helper functions likehandleRuntimeDTOandgetDockerComposeEnvironments, writes updated environment variables back to.envfile, and saves changes to the repository after re-starting the runtime withreCreateRuntime.Return Type of Updated Method:
Potential Issues
Concurrency Management: Ensure that concurrent calls to
UpdatePHPContainerdo not lead to errors, such as conflicting port assignments or duplicate environment definitions.Resource Leaks: Implement checks and resource management around file operations and data manipulation to prevent memory leaks.
Error Handling and Recovery: Add better error handling and retry mechanisms when dealing with external systems like Docker API and ensuring robustness against transient failures.
Scalability: Evaluate if this approach scales well with high number of concurrent requests and large projects without causing performance bottlenecks.
Testing: Ensure comprehensive testing for edge cases, particularly related to container name conflicts and invalid port configurations to catch bugs early.
Documentation and Validation: Provide clear documentation for all new endpoints and input parameters to ensure ease of use and reduce confusion among users.
Overall, these changes seem reasonable within the context but require careful evaluation of specific use case scenarios and implementation details to fully optimize and validate their effectiveness.