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

Function buildNginx

agent/app/service/app_utils.go:605–673  ·  view source on GitHub ↗
(parentTask *task.Task)

Source from the content-addressed store, hash-verified

603}
604
605func buildNginx(parentTask *task.Task) error {
606 nginxInstall, err := getAppInstallByKey(constant.AppOpenresty)
607 if err != nil {
608 return err
609 }
610 fileOp := files.NewFileOp()
611 buildPath := path.Join(nginxInstall.GetPath(), "build")
612 if !fileOp.Stat(buildPath) {
613 return buserr.New("ErrBuildDirNotFound")
614 }
615 moduleConfigPath := path.Join(buildPath, "module.json")
616 moduleContent, err := fileOp.GetContent(moduleConfigPath)
617 if err != nil {
618 return err
619 }
620 var (
621 modules []dto.NginxModule
622 addModuleParams []string
623 addPackages []string
624 )
625 if len(moduleContent) > 0 {
626 _ = json.Unmarshal(moduleContent, &modules)
627 bashFile, err := os.OpenFile(path.Join(buildPath, "tmp", "pre.sh"), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, constant.DirPerm)
628 if err != nil {
629 return err
630 }
631 defer bashFile.Close()
632 bashFileWriter := bufio.NewWriter(bashFile)
633 for _, module := range modules {
634 if !module.Enable {
635 continue
636 }
637 _, err = bashFileWriter.WriteString(module.Script + "\n")
638 if err != nil {
639 return err
640 }
641 addModuleParams = append(addModuleParams, module.Params)
642 addPackages = append(addPackages, module.Packages...)
643 }
644 err = bashFileWriter.Flush()
645 if err != nil {
646 return err
647 }
648 }
649 envs, err := gotenv.Read(nginxInstall.GetEnvPath())
650 if err != nil {
651 return err
652 }
653 envs["RESTY_CONFIG_OPTIONS_MORE"] = ""
654 envs["RESTY_ADD_PACKAGE_BUILDDEPS"] = ""
655 if len(addModuleParams) > 0 {
656 envs["RESTY_CONFIG_OPTIONS_MORE"] = strings.Join(addModuleParams, " ")
657 }
658 if len(addPackages) > 0 {
659 envs["RESTY_ADD_PACKAGE_BUILDDEPS"] = strings.Join(addPackages, " ")
660 }
661 _ = gotenv.Write(envs, nginxInstall.GetEnvPath())
662 if len(addModuleParams) == 0 && len(addPackages) == 0 {

Callers 1

upgradeInstallFunction · 0.70

Calls 14

StatMethod · 0.95
GetContentMethod · 0.95
getAppInstallByKeyFunction · 0.85
OpenFileMethod · 0.80
CloseMethod · 0.65
RunMethod · 0.65
GetPathMethod · 0.45
FlushMethod · 0.45
ReadMethod · 0.45
GetEnvPathMethod · 0.45
WriteMethod · 0.45
LogStartMethod · 0.45

Tested by

no test coverage detected