Commit 8c4ae233 authored by duanjinfei's avatar duanjinfei

add Dockerfile

parent 142a2d16
FROM golang:1.20-alpine AS build
# Install dependencies
RUN apk update && \
apk upgrade && \
apk add --no-cache bash git openssh make build-base
RUN go env -w CGO_ENABLED="1"
WORKDIR /build
RUN git clone https://code.wuban.net.cn/odysseus/power-node && \
git clone https://code.wuban.net.cn/odysseus/odysseus-protocol
RUN cd /build/power-node && sh start.sh && cp build/powerNode /powerNode
FROM alpine
WORKDIR /root
COPY --from=build /powerNode /usr/bin/powerNode
ENTRYPOINT [ "powerNode" ]
\ No newline at end of file
package main
import "runtime"
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
Execute()
}
package main
import (
"fmt"
"example.com/m/conf"
"example.com/m/log"
"github.com/ethereum/go-ethereum/common"
"github.com/spf13/cobra"
)
var versionDetail bool
var (
rewardAddr string
isSetReward bool
)
func init() {
RootCmd.AddCommand(versionCmd)
versionDetail = *versionCmd.Flags().BoolP("detail", "d", true, "Print detail version info")
RootCmd.AddCommand(paramCmd)
rewardAddr = *paramCmd.Flags().StringP("reward", "r", "", "Print detail version info")
}
// versionCmd represents the base command when called without any subcommands
var versionCmd = &cobra.Command{
Use: "version",
var paramCmd = &cobra.Command{
Use: "param",
Short: "Print version number",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
if versionDetail {
fmt.Println("detail version:v1.0.0")
} else {
fmt.Println("version:v1.0.0")
if rewardAddr != "" && common.IsHexAddress(rewardAddr) {
isSetReward = conf.GetConfig().SetRewardAddress(rewardAddr)
if !isSetReward {
log.Error("Please set right reward address")
}
}
},
}
package main
import (
"encoding/json"
"example.com/m/conf"
"example.com/m/log"
"example.com/m/nm"
"example.com/m/utils"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/astaxie/beego"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"io/ioutil"
"os"
)
var (
routineCount uint
_cfg *conf.Config = nil
)
// RootCmd represents the base command when called without any subcommands
var RootCmd = &cobra.Command{
Use: "Miner",
Use: "miner",
Short: "The miner command-line interface",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
nm.StartMonitor()
if isSetReward {
log.InitLog(log.LogConfig{Path: "logs", Level: "debug", Save: 3})
go nm.StartMonitor()
beego.Run()
}
},
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
}
func init() {
cobra.OnInitialize(initConfig)
//cobra.OnInitialize(initConfig)
RootCmd.PersistentFlags().UintVar(&routineCount, "routine", 2, "routine count for corrupt do task")
}
// initConfig reads in conf file and ENV variables if set.
func initConfig() {
// 设置配置文件的名称(不包含扩展名)
viper.SetConfigName("config")
// 设置配置文件的类型
viper.SetConfigType("json")
// 设置配置文件所在的目录
viper.AddConfigPath("./")
// 读取配置文件
if err := viper.ReadInConfig(); err != nil {
fmt.Println("Error reading config file:", err)
return
}
configFilePath := viper.ConfigFileUsed()
if configFilePath == "" {
// handle error
log.Error("config file path is empty")
panic("config file path is empty")
}
data, err := ioutil.ReadFile(configFilePath)
if err != nil {
// handle error
log.Error("Read cfg file error:", err)
panic("Read cfg file error")
}
err = json.Unmarshal(data, &_cfg)
if err != nil {
// handle error
log.Error("Json unmarshal cfg error:", err)
panic("Json unmarshal cfg error")
}
_cfg.HeartRespTimeMillis = _cfg.HeartRespTimeSecond * 60 * 60 * 1000
prvKey, err := utils.GetPrv()
if err != nil {
panic("get prv error or delete keystore after restart")
}
_cfg.SignPrivateKey = prvKey
ecdsaPub := prvKey.PublicKey
_cfg.SignPub = common.Bytes2Hex(crypto.FromECDSAPub(&ecdsaPub))
log.Info("PublicKey", _cfg.SignPub)
publicAddr := crypto.PubkeyToAddress(ecdsaPub)
log.Info("publicAddr:", publicAddr)
_cfg.SignPublicAddress = publicAddr
}
func Execute() {
if err := RootCmd.Execute(); err != nil {
log.Error("root cmd execute failed", err)
......
appname = node-server
httpport = 8888
httpport = 9090
runmode = dev
autorender = false
copyrequestbody = true
\ No newline at end of file
......@@ -26,6 +26,7 @@ type Config struct {
ContainerNum int64 `json:"container_num"`
NodeManagerNum int64 `json:"node_manager_num"`
ChainID int64 `json:"chain_id"`
ApiUrl string `json:"api_url"`
}
var _cfg *Config = nil
......
......@@ -2,6 +2,7 @@
"nm_seed": "192.168.1.241:10001",
"sign_prv": "0e80b06d24d7543b3e2520c91d25997bcf5e0e9e6361910cea6ab268c2db3600",
"docker_server": "tcp://192.168.1.120:2375",
"api_url": "http://192.168.1.8:8087/api/task/taskheat",
"benefit_address": "0x84A3175be614F5886f99Da506dF08682DF530739",
"node_manager_num": 1,
"heart_response": 30,
......
package main
import (
"example.com/m/log"
"example.com/m/nm"
_ "example.com/m/routers"
"github.com/astaxie/beego"
_ "net/http/pprof"
"github.com/consensys/gnark-crypto/field/goff/cmd"
"runtime"
)
func main() {
log.InitLog(log.LogConfig{Path: "logs", Level: "debug", Save: 3})
//go func() {
// log.Println(http.ListenAndServe("localhost:6060", nil))
//}()
//runtime.SetBlockProfileRate(1) // 开启对阻塞操作的跟踪,block
//runtime.SetMutexProfileFraction(1) // 开启对锁调用的跟踪,mutex
go nm.StartMonitor()
beego.Run()
runtime.GOMAXPROCS(runtime.NumCPU())
cmd.Execute()
}
......@@ -3,6 +3,7 @@ package nm
import (
"bytes"
"encoding/json"
"example.com/m/conf"
"example.com/m/log"
"example.com/m/models"
"example.com/m/operate"
......@@ -15,12 +16,12 @@ import (
func monitorModelInfo(dockerOp *operate.DockerOp) {
client := &http.Client{}
ticker := time.NewTicker(time.Second * 1)
ticker := time.NewTicker(time.Second * 20)
for {
select {
case <-ticker.C:
modelInfosResp := make([]*models.ModelInfo, 0)
modelResp, err := client.Get("http://192.168.1.8:8087/api/task/taskheat")
modelResp, err := client.Get(conf.GetConfig().ApiUrl)
if err != nil {
log.Error("Error getting model info from client failed:", err)
continue
......
......@@ -11,7 +11,7 @@ import (
)
func monitorNodeManagerSeed() {
ticker := time.NewTicker(time.Second * 1)
ticker := time.NewTicker(time.Second * 20)
for {
select {
case <-ticker.C:
......
......@@ -7,4 +7,6 @@ import (
func init() {
beego.Router("/power/node/get/nm", &controllers.NodeController{}, "post:GetNodeManagers")
beego.Router("/power/node/set/nm/seed", &controllers.NodeController{}, "post:SetNmSeed")
beego.Router("/power/node/set/rewardAddr", &controllers.NodeController{}, "post:SetRewardAddress")
}
......@@ -4,7 +4,5 @@ rm -rf node node.log mydb
echo "rm data successful"
go get
echo "go get successful"
go build -o node
echo "build successful"
nohup ./node > node.log 2>&1 &
echo "running successful"
\ No newline at end of file
go build -o powerNode
echo "build successful"
\ No newline at end of file
package win
import (
"example.com/m/log"
"github.com/kardianos/service"
"os"
"time"
)
type program struct{}
func Run() {
srvConfig := &service.Config{
Name: "NodeService",
DisplayName: "NodeServiceRun",
Description: "The service is miner for node",
}
prg := &program{}
s, err := service.New(prg, srvConfig)
if err != nil {
log.Error("New service failed: ", err)
return
}
if len(os.Args) > 1 {
serviceAction := os.Args[1]
switch serviceAction {
case "install":
err := s.Install()
if err != nil {
log.Error("安装服务失败: ", err.Error())
} else {
log.Info("安装服务成功")
}
return
case "uninstall":
err := s.Uninstall()
if err != nil {
log.Error("卸载服务失败: ", err.Error())
} else {
log.Info("卸载服务成功")
}
return
case "start":
err := s.Start()
if err != nil {
log.Error("运行服务失败: ", err.Error())
} else {
log.Info("运行服务成功")
}
return
case "stop":
err := s.Stop()
if err != nil {
log.Error("停止服务失败: ", err.Error())
} else {
log.Info("停止服务成功")
}
return
}
}
}
func (p *program) Start(s service.Service) error {
log.Info("service start...")
go p.run()
return nil
}
func (p *program) run() {
for {
time.Sleep(time.Second)
log.Info("running")
}
}
func (p *program) Stop(s service.Service) error {
err := s.Stop()
if err != nil {
log.Error("service stop...", err.Error())
return err
}
return nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment