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

Method Create

agent/app/service/runtime.go:85–195  ·  view source on GitHub ↗
(create request.RuntimeCreate)

Source from the content-addressed store, hash-verified

83}
84
85func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, error) {
86 var (
87 opts []repo.DBOption
88 )
89 if create.Name != "" {
90 opts = append(opts, repo.WithByName(create.Name))
91 }
92 if create.Type != "" {
93 opts = append(opts, repo.WithByType(create.Type))
94 }
95 exist, _ := runtimeRepo.GetFirst(context.Background(), opts...)
96 if exist != nil {
97 return nil, buserr.New("ErrNameIsExist")
98 }
99 fileOp := files.NewFileOp()
100
101 runtimeDir := path.Join(global.Dir.RuntimeDir, create.Type)
102 if !fileOp.Stat(runtimeDir) {
103 if err := fileOp.CreateDir(runtimeDir, constant.DirPerm); err != nil {
104 return nil, err
105 }
106 }
107 var hostPorts []string
108 switch create.Type {
109 case constant.RuntimePHP:
110 if create.Resource == constant.ResourceLocal {
111 runtime := &model.Runtime{
112 Name: create.Name,
113 Resource: create.Resource,
114 Type: create.Type,
115 Version: create.Version,
116 Status: constant.StatusNormal,
117 Remark: create.Remark,
118 }
119 return nil, runtimeRepo.Create(context.Background(), runtime)
120 }
121 exist, _ = runtimeRepo.GetFirst(context.Background(), runtimeRepo.WithImage(create.Image))
122 if exist != nil {
123 return nil, buserr.New("ErrImageExist")
124 }
125 fpmPort, ok := create.Params["PANEL_APP_PORT_HTTP"]
126 if !ok {
127 return nil, buserr.New("ErrPortNotFound")
128 }
129 hostPorts = append(hostPorts, fmt.Sprintf("%.0f", fpmPort.(float64)))
130 if err := checkPortExist(int(fpmPort.(float64))); err != nil {
131 return nil, err
132 }
133 case constant.RuntimeNode, constant.RuntimeJava, constant.RuntimeGo, constant.RuntimePython, constant.RuntimeDotNet:
134 if !fileOp.Stat(create.CodeDir) {
135 return nil, buserr.New("ErrPathNotFound")
136 }
137 create.Install = true
138 for _, export := range create.ExposedPorts {
139 hostPorts = append(hostPorts, strconv.Itoa(export.HostPort))
140 if err := checkPortExist(export.HostPort); err != nil {
141 return nil, err
142 }

Callers

nothing calls this directly

Calls 13

StatMethod · 0.95
CreateDirMethod · 0.95
checkPortExistFunction · 0.85
downloadAppFunction · 0.85
handlePHPFunction · 0.85
handleRuntimeFunction · 0.85
GetAppResourcePathMethod · 0.80
checkContainerNameFunction · 0.70
WithByTypeMethod · 0.65
GetFirstMethod · 0.65
CreateMethod · 0.65
WithImageMethod · 0.65

Tested by

no test coverage detected