Browse Source

合并仓库

gitlink
Sydonian 2 years ago
parent
commit
23dcbc813d
3 changed files with 169 additions and 0 deletions
  1. +10
    -0
      magefiles/go.mod
  2. +7
    -0
      magefiles/go.sum
  3. +152
    -0
      magefiles/main.go

+ 10
- 0
magefiles/go.mod View File

@@ -0,0 +1,10 @@
module magefiles

go 1.20

require (
github.com/magefile/mage v1.15.0
github.com/otiai10/copy v1.12.0
)

require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect

+ 7
- 0
magefiles/go.sum View File

@@ -0,0 +1,7 @@
github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/otiai10/copy v1.12.0 h1:cLMgSQnXBs1eehF0Wy/FAGsgDTDmAqFR7rQylBb1nDY=
github.com/otiai10/copy v1.12.0/go.mod h1:rSaLseMUsZFFbsFGc7wCJnnkTAvdc5L6VWxPE4308Ww=
github.com/otiai10/mint v1.5.1 h1:XaPLeE+9vGbuyEHem1JNk3bYc7KKqyI/na0/mLd/Kks=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

+ 152
- 0
magefiles/main.go View File

@@ -0,0 +1,152 @@
//go:build mage

package main

import (
"errors"
"fmt"
"os"
"path/filepath"

"github.com/magefile/mage/sh"
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 := Agent(); err != nil {
return err
}
if err := Client(); err != nil {
return err
}
if err := Coordinator(); err != nil {
return err
}
if err := Scanner(); err != nil {
return err
}

return nil
}

func Scripts() error {
scriptsDir := "./storage-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 := "./storage-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 Agent() error {
os.Chdir("./storage-agent")
defer os.Chdir("..")

return sh.RunV("mage", makeBuildMageArgeuments()...)
}

func Client() error {
os.Chdir("./storage-client")
defer os.Chdir("..")

return sh.RunV("mage", makeBuildMageArgeuments()...)
}

func Coordinator() error {
os.Chdir("./storage-coordinator")
defer os.Chdir("..")

return sh.RunV("mage", makeBuildMageArgeuments()...)
}

func Scanner() error {
os.Chdir("./storage-scanner")
defer os.Chdir("..")

return sh.RunV("mage", makeBuildMageArgeuments()...)
}

func makeBuildMageArgeuments() []string {
var args []string

if Global.OS != "" {
args = append(args, Global.OS)
}

if Global.Arch != "" {
args = append(args, Global.Arch)
}

args = append(args, "buildroot", "../build")

args = append(args, "build")

return args
}

Loading…
Cancel
Save