JCC-CSScheduler/magefiles/main.go

132 lines
2.2 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"
)
var Global = struct {
OS string
Arch string
}{}
// [配置项]设置编译平台为windows
func Win() {
Global.OS = "win"
}
// [配置项]设置编译平台为linux
func Linux() {
Global.OS = "linux"
}
// [配置项]设置编译架构为amd64
func AMD64() {
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 := Executor(); err != nil {
return err
}
return nil
}
func Scripts() error {
scriptsDir := "./common/assets/scripts"
info, err := os.Stat(scriptsDir)
if errors.Is(err, os.ErrNotExist) || !info.IsDir() {
return fmt.Errorf("script directory not exists or 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) || !info.IsDir() {
return fmt.Errorf("conf directory not exists or 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 Executor() error {
return magefiles.Build(magefiles.BuildArgs{
OutputName: "executor",
OutputDir: "executor",
AssetsDir: "assets",
EntryFile: "executor/main.go",
})
}