改进编译脚本

This commit is contained in:
GoEdgeLab
2020-10-14 14:46:22 +08:00
parent 2c9fffa4db
commit 8c206d997e
7 changed files with 202 additions and 33 deletions

87
build/build.sh Executable file
View File

@@ -0,0 +1,87 @@
#!/usr/bin/env bash
function build() {
ROOT=$(dirname $0)
NAME="edge-admin"
DIST=$ROOT/"../dist/${NAME}"
OS=${1}
ARCH=${2}
if [ -z $OS ]; then
echo "usage: build.sh OS ARCH"
exit
fi
if [ -z $ARCH ]; then
echo "usage: build.sh OS ARCH"
exit
fi
VERSION=$(lookup-version $ROOT/../internal/const/const.go)
ZIP="${NAME}-${OS}-${ARCH}-v${VERSION}.zip"
# check edge-api
APINodeVersion=$(lookup-version $ROOT"/../../EdgeAPI/internal/const/const.go")
echo "building edge-api v${APINodeVersion} ..."
EDGE_API_BUILD_SCRIPT=$ROOT"/../../EdgeAPI/build/build.sh"
if [ ! -f $EDGE_API_BUILD_SCRIPT ]; then
echo "unable to find edge-api build script 'EdgeAPI/build/build.sh'"
exit
fi
cd $ROOT"/../../EdgeAPI/build"
echo "=============================="
./build.sh $OS $ARCH
echo "=============================="
cd -
# create dir & copy files
echo "copying ..."
if [ ! -d $DIST ]; then
mkdir $DIST
mkdir $DIST/bin
mkdir $DIST/configs
mkdir $DIST/logs
fi
cp -R $ROOT/../web $DIST/
rm -f $DIST/web/tmp/*
cp $ROOT/configs/server.template.yaml $DIST/configs/
EDGE_API_ZIP_FILE=$ROOT"/../../EdgeAPI/dist/edge-api-${OS}-${ARCH}-v${APINodeVersion}.zip"
cp $EDGE_API_ZIP_FILE $DIST/
cd $DIST/
unzip -q $(basename $EDGE_API_ZIP_FILE)
rm -f $(basename $EDGE_API_ZIP_FILE)
cd -
# build
echo "building "${NAME}" ..."
env GOOS=$OS GOARCH=$GOARCH go build -ldflags="-s -w" -o $DIST/bin/${NAME} $ROOT/../cmd/edge-admin/main.go
# zip
echo "zip files ..."
cd "${DIST}/../" || exit
if [ -f "${ZIP}" ]; then
rm -f "${ZIP}"
fi
zip -r -X -q "${ZIP}" ${NAME}/
rm -rf ${NAME}
cd - || exit
echo "[done]"
}
function lookup-version() {
FILE=$1
VERSION_DATA=$(cat $FILE)
re="Version[ ]+=[ ]+\"([0-9.]+)\""
if [[ $VERSION_DATA =~ $re ]]; then
VERSION=${BASH_REMATCH[1]}
echo $VERSION
else
echo "could not match version"
exit
fi
}
build $1 $2

View File

@@ -3,15 +3,9 @@ package main
import ( import (
"github.com/TeaOSLab/EdgeAdmin/internal/apps" "github.com/TeaOSLab/EdgeAdmin/internal/apps"
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const" teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
"github.com/TeaOSLab/EdgeAdmin/internal/nodes"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web" _ "github.com/TeaOSLab/EdgeAdmin/internal/web"
"github.com/iwind/TeaGo"
"github.com/iwind/TeaGo/Tea"
_ "github.com/iwind/TeaGo/bootstrap" _ "github.com/iwind/TeaGo/bootstrap"
"github.com/iwind/TeaGo/logs"
"github.com/iwind/TeaGo/rands"
"github.com/iwind/TeaGo/sessions"
"os"
"os/exec"
) )
func main() { func main() {
@@ -21,29 +15,7 @@ func main() {
Usage(teaconst.ProcessName + " [-v|start|stop|restart]") Usage(teaconst.ProcessName + " [-v|start|stop|restart]")
app.Run(func() { app.Run(func() {
// 启动管理界面 adminNode := nodes.NewAdminNode()
secret := rands.String(32) adminNode.Run()
// 测试环境下设置一个固定的key方便我们调试
if Tea.IsTesting() {
secret = "8f983f4d69b83aaa0d74b21a212f6967"
}
// 启动API节点
_, err := os.Stat(Tea.Root + "/edge-api/configs/api.yaml")
if err == nil {
logs.Println("start edge-api")
err = exec.Command(Tea.Root + "/edge-api/bin/edge-api").Start()
if err != nil {
logs.Println("[ERROR]start edge-api failed: " + err.Error())
}
}
server := TeaGo.NewServer(false).
AccessLog(false).
EndAll().
Session(sessions.NewFileSessionManager(86400, secret))
server.Start()
}) })
} }

View File

@@ -0,0 +1,103 @@
package nodes
import (
"github.com/TeaOSLab/EdgeAdmin/internal/errors"
"github.com/iwind/TeaGo"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/logs"
"github.com/iwind/TeaGo/rands"
"github.com/iwind/TeaGo/sessions"
"io/ioutil"
"os"
"os/exec"
)
type AdminNode struct {
}
func NewAdminNode() *AdminNode {
return &AdminNode{}
}
func (this *AdminNode) Run() {
// 启动管理界面
secret := rands.String(32)
// 测试环境下设置一个固定的key方便我们调试
if Tea.IsTesting() {
secret = "8f983f4d69b83aaa0d74b21a212f6967"
}
// 检查server配置
err := this.checkServer()
if err != nil {
return
}
// 启动API节点
this.startAPINode()
server := TeaGo.NewServer(false).
AccessLog(false).
EndAll().
Session(sessions.NewFileSessionManager(86400, secret))
server.Start()
}
// 检查Server配置
func (this *AdminNode) checkServer() error {
configFile := Tea.ConfigFile("server.yaml")
_, err := os.Stat(configFile)
if err == nil {
return nil
}
if os.IsNotExist(err) {
// 创建文件
templateFile := Tea.ConfigFile("server.template.yaml")
data, err := ioutil.ReadFile(templateFile)
if err == nil {
err = ioutil.WriteFile(configFile, data, 0666)
if err != nil {
return errors.New("create config file failed: " + err.Error())
}
} else {
templateYAML := `# environment code
env: prod
# http
http:
"on": true
listen: [ "0.0.0.0:7788" ]
# https
https:
"on": false
listen: [ "0.0.0.0:443"]
cert: ""
key: ""
`
err = ioutil.WriteFile(configFile, []byte(templateYAML), 0666)
if err != nil {
return errors.New("create config file failed: " + err.Error())
}
}
} else {
return errors.New("can not read config from 'configs/server.yaml': " + err.Error())
}
return nil
}
// 启动API节点
func (this AdminNode) startAPINode() {
_, err := os.Stat(Tea.Root + "/edge-api/configs/api.yaml")
if err == nil {
logs.Println("start edge-api")
err = exec.Command(Tea.Root + "/edge-api/bin/edge-api").Start()
if err != nil {
logs.Println("[ERROR]start edge-api failed: " + err.Error())
}
}
}

View File

@@ -7,6 +7,7 @@ import (
var isConfigured bool var isConfigured bool
// 判断系统是否已经配置过 // 判断系统是否已经配置过
// TODO 检查节点版本和数据库版本是否一致,如果不一致则跳转到升级页面
func IsConfigured() bool { func IsConfigured() bool {
if isConfigured { if isConfigured {
return true return true

View File

@@ -370,6 +370,9 @@ body.expanded .main {
.main .tab-menu .item .icon { .main .tab-menu .item .icon {
margin-left: 0.6em; margin-left: 0.6em;
} }
.main .tab-menu .item.active {
background: #f8f8f9 !important;
}
.main .tab-menu::-webkit-scrollbar { .main .tab-menu::-webkit-scrollbar {
height: 4px; height: 4px;
} }

File diff suppressed because one or more lines are too long

View File

@@ -342,7 +342,6 @@ body.expanded .main {
} }
.main { .main {
.tab-menu { .tab-menu {
margin-top: 1em !important; margin-top: 1em !important;
margin-bottom: 0 !important; margin-bottom: 0 !important;
@@ -365,6 +364,10 @@ body.expanded .main {
margin-left: 0.6em; margin-left: 0.6em;
} }
} }
.item.active {
background: #f8f8f9 !important;
}
} }
.tab-menu::-webkit-scrollbar { .tab-menu::-webkit-scrollbar {