(req request.NginxBuildReq)
| 173 | } |
| 174 | |
| 175 | func (n NginxService) Build(req request.NginxBuildReq) error { |
| 176 | nginxInstall, err := getAppInstallByKey(constant.AppOpenresty) |
| 177 | if err != nil { |
| 178 | return err |
| 179 | } |
| 180 | taskName := task.GetTaskName(nginxInstall.Name, task.TaskBuild, task.TaskScopeApp) |
| 181 | if err = task.CheckTaskIsExecuting(taskName); err != nil { |
| 182 | return err |
| 183 | } |
| 184 | fileOp := files.NewFileOp() |
| 185 | buildPath := path.Join(nginxInstall.GetPath(), "build") |
| 186 | if !fileOp.Stat(buildPath) { |
| 187 | return buserr.New("ErrBuildDirNotFound") |
| 188 | } |
| 189 | moduleConfigPath := path.Join(buildPath, "module.json") |
| 190 | moduleContent, err := fileOp.GetContent(moduleConfigPath) |
| 191 | if err != nil { |
| 192 | return err |
| 193 | } |
| 194 | var ( |
| 195 | modules []dto.NginxModule |
| 196 | addModuleParams []string |
| 197 | addPackages []string |
| 198 | ) |
| 199 | if len(moduleContent) > 0 { |
| 200 | _ = json.Unmarshal(moduleContent, &modules) |
| 201 | bashFile, err := os.OpenFile(path.Join(buildPath, "tmp", "pre.sh"), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, constant.DirPerm) |
| 202 | if err != nil { |
| 203 | return err |
| 204 | } |
| 205 | defer bashFile.Close() |
| 206 | bashFileWriter := bufio.NewWriter(bashFile) |
| 207 | for _, module := range modules { |
| 208 | if !module.Enable { |
| 209 | continue |
| 210 | } |
| 211 | _, err = bashFileWriter.WriteString(module.Script + "\n") |
| 212 | if err != nil { |
| 213 | return err |
| 214 | } |
| 215 | addModuleParams = append(addModuleParams, module.Params) |
| 216 | addPackages = append(addPackages, module.Packages...) |
| 217 | } |
| 218 | err = bashFileWriter.Flush() |
| 219 | if err != nil { |
| 220 | return err |
| 221 | } |
| 222 | } |
| 223 | envs, err := gotenv.Read(nginxInstall.GetEnvPath()) |
| 224 | if err != nil { |
| 225 | return err |
| 226 | } |
| 227 | envs["CONTAINER_PACKAGE_URL"] = req.Mirror |
| 228 | envs["RESTY_CONFIG_OPTIONS_MORE"] = "" |
| 229 | envs["RESTY_ADD_PACKAGE_BUILDDEPS"] = "" |
| 230 | if len(addModuleParams) > 0 { |
| 231 | envs["RESTY_CONFIG_OPTIONS_MORE"] = strings.Join(addModuleParams, " ") |
| 232 | } |
nothing calls this directly
no test coverage detected