forked from JointCloud/JCC-CSScheduler
161 lines
2.7 KiB
Go
161 lines
2.7 KiB
Go
//go:build mage
|
|
|
|
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"gitlink.org.cn/cloudream/common/magefiles"
|
|
|
|
cp "github.com/otiai10/copy"
|
|
)
|
|
|
|
const (
|
|
BuildDir = "./build"
|
|
)
|
|
|
|
// [配置项]设置编译平台为windows
|
|
func Win() {
|
|
magefiles.Global.OS = "win"
|
|
}
|
|
|
|
// [配置项]设置编译平台为linux
|
|
func Linux() {
|
|
magefiles.Global.OS = "linux"
|
|
}
|
|
|
|
// [配置项]设置编译架构为amd64
|
|
func AMD64() {
|
|
magefiles.Global.Arch = "amd64"
|
|
}
|
|
|
|
func All() error {
|
|
if err := Bin(); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := Scripts(); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := Confs(); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func Bin() error {
|
|
if err := Client(); err != nil {
|
|
return err
|
|
}
|
|
if err := Collector(); err != nil {
|
|
return err
|
|
}
|
|
if err := Advisor(); err != nil {
|
|
return err
|
|
}
|
|
if err := Executor(); err != nil {
|
|
return err
|
|
}
|
|
if err := Manager(); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func Scripts() error {
|
|
scriptsDir := "./common/assets/scripts"
|
|
|
|
info, err := os.Stat(scriptsDir)
|
|
if errors.Is(err, os.ErrNotExist) {
|
|
fmt.Printf("no scripts.\n")
|
|
return nil
|
|
}
|
|
|
|
if !info.IsDir() {
|
|
return fmt.Errorf("scripts is not a directory")
|
|
}
|
|
|
|
fullDirPath, err := filepath.Abs(filepath.Join(BuildDir, "scripts"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Printf("copying scripts to %s\n", fullDirPath)
|
|
|
|
return cp.Copy(scriptsDir, fullDirPath)
|
|
}
|
|
|
|
func Confs() error {
|
|
confDir := "./common/assets/confs"
|
|
|
|
info, err := os.Stat(confDir)
|
|
if errors.Is(err, os.ErrNotExist) {
|
|
fmt.Printf("no confs.\n")
|
|
return nil
|
|
}
|
|
|
|
if !info.IsDir() {
|
|
return fmt.Errorf("confs is not a directory")
|
|
}
|
|
|
|
fullDirPath, err := filepath.Abs(filepath.Join(BuildDir, "confs"))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Printf("copying confs to %s\n", fullDirPath)
|
|
|
|
return cp.Copy(confDir, fullDirPath)
|
|
}
|
|
|
|
func Client() error {
|
|
return magefiles.Build(magefiles.BuildArgs{
|
|
OutputName: "client",
|
|
OutputDir: "client",
|
|
AssetsDir: "assets",
|
|
EntryFile: "client/main.go",
|
|
})
|
|
}
|
|
|
|
func Collector() error {
|
|
return magefiles.Build(magefiles.BuildArgs{
|
|
OutputName: "collector",
|
|
OutputDir: "collector",
|
|
AssetsDir: "assets",
|
|
EntryFile: "collector/main.go",
|
|
})
|
|
}
|
|
|
|
func Advisor() error {
|
|
return magefiles.Build(magefiles.BuildArgs{
|
|
OutputName: "advisor",
|
|
OutputDir: "advisor",
|
|
AssetsDir: "assets",
|
|
EntryFile: "advisor/main.go",
|
|
})
|
|
}
|
|
|
|
func Executor() error {
|
|
return magefiles.Build(magefiles.BuildArgs{
|
|
OutputName: "executor",
|
|
OutputDir: "executor",
|
|
AssetsDir: "assets",
|
|
EntryFile: "executor/main.go",
|
|
})
|
|
}
|
|
|
|
func Manager() error {
|
|
return magefiles.Build(magefiles.BuildArgs{
|
|
OutputName: "manager",
|
|
OutputDir: "manager",
|
|
AssetsDir: "assets",
|
|
EntryFile: "manager/main.go",
|
|
})
|
|
}
|