(parentTask *task.Task)
| 603 | } |
| 604 | |
| 605 | func 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 { |
no test coverage detected