MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / handleRuntime

Function handleRuntime

agent/app/service/runtime_utils.go:42–82  ·  view source on GitHub ↗
(create request.RuntimeCreate, runtime *model.Runtime, fileOp files.FileOp, appVersionDir string)

Source from the content-addressed store, hash-verified

40)
41
42func handleRuntime(create request.RuntimeCreate, runtime *model.Runtime, fileOp files.FileOp, appVersionDir string) (err error) {
43 runtimeDir := path.Join(global.Dir.RuntimeDir, create.Type)
44 projectDir := path.Join(runtimeDir, create.Name)
45 if create.CodeDir != "" && isPathInsideOrEqual(projectDir, create.CodeDir) {
46 return buserr.New("ErrRuntimeProjectDirContainsCodeDir")
47 }
48 if err = fileOp.CopyDir(appVersionDir, runtimeDir); err != nil {
49 return
50 }
51 versionDir := path.Join(runtimeDir, filepath.Base(appVersionDir))
52 cleanupTarget := versionDir
53 defer func() {
54 if err != nil {
55 _ = fileOp.DeleteDir(cleanupTarget)
56 }
57 }()
58 if err = fileOp.Rename(versionDir, projectDir); err != nil {
59 return
60 }
61 cleanupTarget = projectDir
62 composeContent, envContent, _, err := handleParams(create, projectDir)
63 if err != nil {
64 return
65 }
66 runtime.DockerCompose = string(composeContent)
67 runtime.Env = string(envContent)
68 runtime.Status = constant.StatusCreating
69 runtime.CodeDir = create.CodeDir
70
71 nodeDetail, err := appDetailRepo.GetFirst(repo.WithByID(runtime.AppDetailID))
72 if err != nil {
73 return err
74 }
75
76 go func() {
77 RequestDownloadCallBack(nodeDetail.DownloadCallBackUrl)
78 }()
79 go startRuntime(runtime)
80
81 return
82}
83
84func isPathInsideOrEqual(baseDir, targetDir string) bool {
85 baseAbs := resolveRuntimePath(baseDir)

Callers 1

CreateMethod · 0.85

Calls 9

isPathInsideOrEqualFunction · 0.85
handleParamsFunction · 0.85
RequestDownloadCallBackFunction · 0.85
startRuntimeFunction · 0.85
CopyDirMethod · 0.80
DeleteDirMethod · 0.80
RenameMethod · 0.80
GetFirstMethod · 0.65
WithByIDMethod · 0.65

Tested by

no test coverage detected