You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.go 2.6 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //go:build mage
  2. package main
  3. import (
  4. "errors"
  5. "fmt"
  6. "os"
  7. "path/filepath"
  8. "github.com/magefile/mage/sh"
  9. cp "github.com/otiai10/copy"
  10. )
  11. const (
  12. BuildDir = "./build"
  13. )
  14. var Global = struct {
  15. OS string
  16. Arch string
  17. }{}
  18. // [配置项]设置编译平台为windows
  19. func Win() {
  20. Global.OS = "win"
  21. }
  22. // [配置项]设置编译平台为linux
  23. func Linux() {
  24. Global.OS = "linux"
  25. }
  26. // [配置项]设置编译架构为amd64
  27. func AMD64() {
  28. Global.Arch = "amd64"
  29. }
  30. func All() error {
  31. if err := Bin(); err != nil {
  32. return err
  33. }
  34. if err := Scripts(); err != nil {
  35. return err
  36. }
  37. if err := Confs(); err != nil {
  38. return err
  39. }
  40. return nil
  41. }
  42. func Bin() error {
  43. if err := Agent(); err != nil {
  44. return err
  45. }
  46. if err := Client(); err != nil {
  47. return err
  48. }
  49. if err := Coordinator(); err != nil {
  50. return err
  51. }
  52. if err := Scanner(); err != nil {
  53. return err
  54. }
  55. return nil
  56. }
  57. func Scripts() error {
  58. scriptsDir := "./storage-common/assets/scripts"
  59. info, err := os.Stat(scriptsDir)
  60. if errors.Is(err, os.ErrNotExist) || !info.IsDir() {
  61. return fmt.Errorf("script directory not exists or is not a directory")
  62. }
  63. fullDirPath, err := filepath.Abs(filepath.Join(BuildDir, "scripts"))
  64. if err != nil {
  65. return err
  66. }
  67. fmt.Printf("copying scripts to %s\n", fullDirPath)
  68. return cp.Copy(scriptsDir, fullDirPath)
  69. }
  70. func Confs() error {
  71. confDir := "./storage-common/assets/confs"
  72. info, err := os.Stat(confDir)
  73. if errors.Is(err, os.ErrNotExist) || !info.IsDir() {
  74. return fmt.Errorf("conf directory not exists or is not a directory")
  75. }
  76. fullDirPath, err := filepath.Abs(filepath.Join(BuildDir, "confs"))
  77. if err != nil {
  78. return err
  79. }
  80. fmt.Printf("copying confs to %s\n", fullDirPath)
  81. return cp.Copy(confDir, fullDirPath)
  82. }
  83. func Agent() error {
  84. os.Chdir("./storage-agent")
  85. defer os.Chdir("..")
  86. return sh.RunV("mage", makeBuildMageArgeuments()...)
  87. }
  88. func Client() error {
  89. os.Chdir("./storage-client")
  90. defer os.Chdir("..")
  91. return sh.RunV("mage", makeBuildMageArgeuments()...)
  92. }
  93. func Coordinator() error {
  94. os.Chdir("./storage-coordinator")
  95. defer os.Chdir("..")
  96. return sh.RunV("mage", makeBuildMageArgeuments()...)
  97. }
  98. func Scanner() error {
  99. os.Chdir("./storage-scanner")
  100. defer os.Chdir("..")
  101. return sh.RunV("mage", makeBuildMageArgeuments()...)
  102. }
  103. func makeBuildMageArgeuments() []string {
  104. var args []string
  105. if Global.OS != "" {
  106. args = append(args, Global.OS)
  107. }
  108. if Global.Arch != "" {
  109. args = append(args, Global.Arch)
  110. }
  111. args = append(args, "buildroot", "../build")
  112. args = append(args, "build")
  113. return args
  114. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。