[REV] add process of service building from source code

This commit is contained in:
pujielan 2018-01-30 18:02:08 +08:00
parent f16f05ccb5
commit 5bdc8601c6
5 changed files with 47 additions and 22 deletions

View File

@ -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
}

View File

@ -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")
}

View File

@ -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())
}

View File

@ -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())
}

View File

@ -69,8 +69,6 @@ func NewManager(conf config.Config) (Manager, error) {
type exectorManager struct {
DockerClient *client.Client
EtcdCli *clientv3.Client
}
//TaskType: