mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-02 11:47:36 +08:00
[REV] add process of service building from source code
This commit is contained in:
parent
f16f05ccb5
commit
5bdc8601c6
@ -41,7 +41,6 @@ import (
|
||||
"github.com/goodrain/rainbond/pkg/builder/discover"
|
||||
"github.com/goodrain/rainbond/pkg/builder/exector"
|
||||
"github.com/goodrain/rainbond/pkg/api/handler"
|
||||
"github.com/goodrain/rainbond/pkg/db"
|
||||
"github.com/goodrain/rainbond/pkg/db/config"
|
||||
"github.com/goodrain/rainbond/pkg/event"
|
||||
"os"
|
||||
@ -63,10 +62,6 @@ func Run(s *option.Builder) error {
|
||||
EtcdEndPoints: s.Config.EtcdEndPoints,
|
||||
EtcdTimeout: s.Config.EtcdTimeout,
|
||||
}
|
||||
if err := db.CreateManager(dbconfig); err != nil {
|
||||
return err
|
||||
}
|
||||
defer db.CloseManager()
|
||||
if err := event.NewManager(event.EventConfig{EventLogServers: s.Config.EventLogServers}); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -75,14 +70,6 @@ func Run(s *option.Builder) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := handler.CreateServiceManger(api_option.Config{
|
||||
DBType: dbconfig.DBType,
|
||||
DBConnectionInfo: dbconfig.MysqlConnectionInfo,
|
||||
EtcdEndpoint: dbconfig.EtcdEndPoints,
|
||||
}); err != nil {
|
||||
logrus.Errorf("create servie manager error, %v", err)
|
||||
return err
|
||||
}
|
||||
if err := exec.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -19,14 +19,54 @@
|
||||
package apiHandler
|
||||
|
||||
import (
|
||||
"github.com/goodrain/rainbond/pkg/api/handler"
|
||||
"github.com/pquerna/ffjson/ffjson"
|
||||
"os"
|
||||
"strings"
|
||||
"net/http"
|
||||
"fmt"
|
||||
"bytes"
|
||||
"strconv"
|
||||
"github.com/goodrain/rainbond/pkg/worker/discover/model"
|
||||
)
|
||||
|
||||
//UpgradeService 滚动升级
|
||||
func UpgradeService(upgradeTask *model.RollingUpgradeTaskBody) error {
|
||||
if err := handler.GetServiceManager().ServiceUpgrade(upgradeTask); err != nil {
|
||||
func UpgradeService(tenantName, serviceAlias string ,ru *model.RollingUpgradeTaskBody) error {
|
||||
url := fmt.Sprintf("http://127.0.0.1:8888/v2/tenants/%s/services/%s/upgrade", tenantName, serviceAlias)
|
||||
version, err := strconv.Atoi(ru.CurrentDeployVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
raw := struct {
|
||||
DeployVersion int `json:"deploy_version"`
|
||||
EventID string `json:"event_id"`
|
||||
}{
|
||||
DeployVersion:version,
|
||||
EventID:ru.EventID,
|
||||
}
|
||||
rawBody, err := ffjson.Marshal(raw)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return publicRequest("post", url,rawBody)
|
||||
}
|
||||
|
||||
func publicRequest(method, url string, body...[]byte) error {
|
||||
client := &http.Client{}
|
||||
var rawBody *bytes.Buffer
|
||||
if len(body) != 0 {
|
||||
rawBody = bytes.NewBuffer(body[0])
|
||||
}else {
|
||||
rawBody = nil
|
||||
}
|
||||
request, _ := http.NewRequest(strings.ToUpper(method), url, rawBody)
|
||||
token := os.Getenv("TOKEN")
|
||||
if token != "" {
|
||||
request.Header.Set("Authorization", "Token "+token)
|
||||
}
|
||||
response, _ := client.Do(request)
|
||||
if response.StatusCode == 200 {
|
||||
//body, _ := ioutil.ReadAll(response.Body)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("send upgrade mission error")
|
||||
}
|
@ -96,7 +96,7 @@ func (i *ImageBuildItem) Run(timeout time.Duration) error {
|
||||
logrus.Errorf("storage version info error, ignor it: %s", err.Error())
|
||||
}
|
||||
i.Logger.Info("应用同步完成,开始启动应用", map[string]string{"step": "build-exector"})
|
||||
if err := apiHandler.UpgradeService(i.CreateUpgradeTaskBody()); err != nil {
|
||||
if err := apiHandler.UpgradeService(i.TenantName, i.ServiceAlias, i.CreateUpgradeTaskBody()); err != nil {
|
||||
i.Logger.Error("启动应用失败,请手动启动", map[string]string{"step": "callback", "status": "failure"})
|
||||
logrus.Errorf("rolling update service error, %s", err.Error())
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ func (i *SourceCodeBuildItem) Run(timeout time.Duration) error {
|
||||
|
||||
}
|
||||
i.Logger.Info("应用同步完成,开始启动应用", map[string]string{"step": "build-exector"})
|
||||
if err := apiHandler.UpgradeService(i.CreateUpgradeTaskBody()); err != nil {
|
||||
if err := apiHandler.UpgradeService(i.TenantName, i.ServiceAlias, i.CreateUpgradeTaskBody()); err != nil {
|
||||
i.Logger.Error("启动应用失败,请手动启动", map[string]string{"step": "callback", "status": "failure"})
|
||||
logrus.Errorf("rolling update service error, %s", err.Error())
|
||||
}
|
||||
@ -196,7 +196,7 @@ func (i *SourceCodeBuildItem) buildImage() error {
|
||||
}
|
||||
|
||||
i.Logger.Info("应用同步完成,开始启动应用", map[string]string{"step": "build-exector"})
|
||||
if err := apiHandler.UpgradeService(i.CreateUpgradeTaskBody()); err != nil {
|
||||
if err := apiHandler.UpgradeService(i.TenantName, i.ServiceAlias, i.CreateUpgradeTaskBody()); err != nil {
|
||||
i.Logger.Error("启动应用失败,请手动启动", map[string]string{"step": "callback", "status": "failure"})
|
||||
logrus.Errorf("rolling update service error, %s", err.Error())
|
||||
}
|
||||
|
@ -69,8 +69,6 @@ func NewManager(conf config.Config) (Manager, error) {
|
||||
type exectorManager struct {
|
||||
DockerClient *client.Client
|
||||
EtcdCli *clientv3.Client
|
||||
|
||||
|
||||
}
|
||||
|
||||
//TaskType:
|
||||
|
Loading…
Reference in New Issue
Block a user