mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-11-30 10:48:15 +08:00
[REV] Update checking result
This commit is contained in:
parent
9774210a6d
commit
c489691d1b
@ -84,5 +84,8 @@ func (s *ServiceAction) GetServiceCheckInfo(uuid string)(*exector.ServiceCheckRe
|
||||
if err := ffjson.Unmarshal(v, &si); err != nil {
|
||||
return nil, util.CreateAPIHandleError(500, err)
|
||||
}
|
||||
if si.CheckStatus == "" {
|
||||
si.CheckStatus = "Checking"
|
||||
}
|
||||
return &si, nil
|
||||
}
|
@ -316,7 +316,23 @@ func (e *exectorManager) appBuild(in []byte) {
|
||||
func (e *exectorManager)slugShare(in []byte) {
|
||||
i := NewSlugShareItem(in)
|
||||
i.Logger.Info("开始分享新版本应用", map[string]string{"step": "builder-exector", "status": "starting"})
|
||||
|
||||
go func(){
|
||||
logrus.Debugf("start slug share")
|
||||
defer event.GetManager().ReleaseLogger(i.Logger)
|
||||
for n:=0; n< 3; n++ {
|
||||
err := i.Run(time.Minute * 30)
|
||||
if err != nil {
|
||||
logrus.Errorf("slug share error: %s", err.Error())
|
||||
if n < 2 {
|
||||
i.Logger.Error("应用分享失败,开始重试", map[string]string{"step":"build-exector", "status":"failure"})
|
||||
}else {
|
||||
i.Logger.Error("分享应用任务执行失败", map[string]string{"step":"build-exector", "status":"failure"})
|
||||
}
|
||||
}else {
|
||||
break
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (e *exectorManager)imageShare(in []byte) {
|
||||
|
@ -21,18 +21,11 @@ package exector
|
||||
|
||||
|
||||
import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
"time"
|
||||
"fmt"
|
||||
"github.com/goodrain/rainbond/pkg/event"
|
||||
"github.com/tidwall/gjson"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/goodrain/rainbond/pkg/builder/sources"
|
||||
"github.com/akkuman/parseConfig"
|
||||
"github.com/goodrain/rainbond/pkg/db"
|
||||
"github.com/goodrain/rainbond/pkg/worker/discover/model"
|
||||
"github.com/goodrain/rainbond/pkg/builder/apiHandler"
|
||||
)
|
||||
|
||||
//ImageShareItem ImageShareItem
|
||||
@ -49,122 +42,67 @@ type ImageShareItem struct {
|
||||
TenantID string
|
||||
ServiceID string
|
||||
DeployVersion string
|
||||
Dest string
|
||||
ShareID string
|
||||
ImageConf ImageConf
|
||||
}
|
||||
|
||||
//ImageConf ImageConf
|
||||
type ImageConf struct {
|
||||
InnerRegistry string
|
||||
OuterRegistry string
|
||||
}
|
||||
|
||||
|
||||
//NewImageShareItem 创建实体
|
||||
func NewImageShareItem(in []byte) *ImageShareItem {
|
||||
eventID := gjson.GetBytes(in, "event_id").String()
|
||||
logger := event.GetManager().GetLogger(eventID)
|
||||
ic := ImageConf {
|
||||
InnerRegistry: gjson.GetBytes(in, "share_conf.inner_registry").String(),
|
||||
OuterRegistry: gjson.GetBytes(in, "share_conf.outer_registry").String(),
|
||||
}
|
||||
return &ImageShareItem{
|
||||
Namespace: gjson.GetBytes(in, "namespace").String(),
|
||||
TenantName: gjson.GetBytes(in, "tenant_name").String(),
|
||||
ServiceAlias: gjson.GetBytes(in, "service_alias").String(),
|
||||
Image: gjson.GetBytes(in, "image").String(),
|
||||
Dest: gjson.GetBytes(in, "dest").String(),
|
||||
DeployVersion: gjson.GetBytes(in, "deploy_version").String(),
|
||||
Logger: logger,
|
||||
EventID: eventID,
|
||||
ShareID: gjson.GetBytes(in, "share_id").String(),
|
||||
Config: GetBuilderConfig(),
|
||||
ImageConf: ic,
|
||||
}
|
||||
}
|
||||
|
||||
//Run Run
|
||||
func (i *ImageShareItem) Run(timeout time.Duration) error {
|
||||
_, err := sources.ImagePull(i.DockerClient, i.Image, types.ImagePullOptions{}, i.Logger, 3)
|
||||
if err != nil {
|
||||
logrus.Errorf("pull image %s error: %s", i.Image, err.Error())
|
||||
i.Logger.Error(fmt.Sprintf("拉取镜像: %s失败, %s", i.Image, err.Error()), map[string]string{"step": "builder-exector", "status":"failure"})
|
||||
switch i.Dest {
|
||||
case "ys":
|
||||
if err := i.ShareToYS(); err != nil {
|
||||
return err
|
||||
}
|
||||
localImageURL := i.ImageNameHandler(i.Image)
|
||||
if err := sources.ImageTag(i.DockerClient, i.Image, localImageURL, i.Logger, 1); err != nil {
|
||||
logrus.Errorf("change image tag error: %s", err.Error())
|
||||
i.Logger.Error(fmt.Sprintf("修改镜像tag: %s -> %s 失败", i.Image, localImageURL), map[string]string{"step": "builder-exector", "status": "failure"})
|
||||
case "yb":
|
||||
if err := i.ShareToYB(); err != nil {
|
||||
return err
|
||||
}
|
||||
err = sources.ImagePush(i.DockerClient, localImageURL, types.ImagePushOptions{}, i.Logger, 2)
|
||||
if err != nil {
|
||||
logrus.Errorf("push image into registry error: %s", err.Error())
|
||||
i.Logger.Error("推送镜像至镜像仓库失败", map[string]string{"step": "builder-exector", "status":"failure"})
|
||||
default:
|
||||
if err := i.ShareToYS(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := i.StorageLocalImageURL(localImageURL); err != nil {
|
||||
logrus.Errorf("storage image url error: %s", err.Error())
|
||||
i.Logger.Error("存储镜像信息失败", map[string]string{"step":"builder-exector", "status":"failure"})
|
||||
return err
|
||||
}
|
||||
if err := i.StorageVersionInfo(localImageURL); err != nil {
|
||||
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.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())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//ImageNameHandler 根据平台配置处理镜像名称
|
||||
func (i *ImageShareItem) ImageNameHandler(source string) string {
|
||||
currRegistry := i.Config.Get("publish > image > curr_registry").(string)
|
||||
allRegistry := i.Config.Get("publish > image > all_registry").(string)
|
||||
logrus.Debugf("curr all resigtry is %s, %s", currRegistry, allRegistry)
|
||||
imageModel := sources.ImageNameHandle(source)
|
||||
localImageURL := fmt.Sprintf("%s/%s:%s_%s", currRegistry, imageModel.Name, imageModel.Tag, i.ServiceAlias)
|
||||
return localImageURL
|
||||
}
|
||||
|
||||
//StorageLocalImageURL 修改的镜像名称存库
|
||||
func (i *ImageShareItem) StorageLocalImageURL(imageURL string) error {
|
||||
tenant, err := db.GetManager().TenantDao().GetTenantIDByName(i.TenantName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
service, err := db.GetManager().TenantServiceDao().GetServiceByTenantIDAndServiceAlias(tenant.UUID, i.ServiceAlias)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
service.ImageName = imageURL
|
||||
if err := db.GetManager().TenantServiceDao().UpdateModel(service); err != nil {
|
||||
return err
|
||||
}
|
||||
i.TenantID = tenant.UUID
|
||||
i.ServiceID = service.ServiceID
|
||||
//ShareToYS ShareToYS
|
||||
func (i *ImageShareItem) ShareToYS() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//StorageVersionInfo 存储version信息
|
||||
func (i *ImageShareItem) StorageVersionInfo(imageURL string) error {
|
||||
version, err := db.GetManager().VersionInfoDao().GetVersionByEventID(i.EventID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
version.DeliveredType = "image"
|
||||
version.DeliveredPath = imageURL
|
||||
if err := db.GetManager().VersionInfoDao().UpdateModel(version); err != nil {
|
||||
return err
|
||||
}
|
||||
//ShareToYB ShareToYB
|
||||
func (i *ImageShareItem) ShareToYB() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//CreateUpgradeTaskBody 构造消息体
|
||||
func (i *ImageShareItem) CreateUpgradeTaskBody() *model.RollingUpgradeTaskBody{
|
||||
return &model.RollingUpgradeTaskBody{
|
||||
TenantID: i.TenantID,
|
||||
ServiceID: i.ServiceID,
|
||||
NewDeployVersion: i.DeployVersion,
|
||||
EventID: i.EventID,
|
||||
}
|
||||
}
|
||||
|
||||
//UpdateVersionInfo 更新任务执行结果
|
||||
func (i *ImageShareItem) UpdateVersionInfo(status string) error {
|
||||
version,err :=db.GetManager().VersionInfoDao().GetVersionByEventID(i.EventID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
version.FinalStatus = status
|
||||
if err := db.GetManager().VersionInfoDao().UpdateModel(version); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
@ -21,6 +21,7 @@ package exector
|
||||
|
||||
|
||||
import (
|
||||
"github.com/goodrain/rainbond/pkg/builder/sources"
|
||||
"time"
|
||||
"fmt"
|
||||
"os"
|
||||
@ -50,12 +51,29 @@ type SlugShareItem struct {
|
||||
EventID string
|
||||
IsOuter string
|
||||
Config parseConfig.Config
|
||||
FTPConf SlugFTPConf
|
||||
}
|
||||
|
||||
//SlugFTPConf SlugFTPConf
|
||||
type SlugFTPConf struct {
|
||||
Username string
|
||||
Password string
|
||||
Host string
|
||||
Port int
|
||||
FTPNamespace string
|
||||
}
|
||||
|
||||
//NewSlugShareItem 创建实体
|
||||
func NewSlugShareItem(in []byte) *SlugShareItem {
|
||||
eventID := gjson.GetBytes(in, "event_id").String()
|
||||
logger := event.GetManager().GetLogger(eventID)
|
||||
sf := SlugFTPConf {
|
||||
Username: gjson.GetBytes(in, "share_conf.ftp_username").String(),
|
||||
Password: gjson.GetBytes(in, "share_conf.ftp_username").String(),
|
||||
Host: gjson.GetBytes(in, "share_conf.ftp_host").String(),
|
||||
Port: int(gjson.GetBytes(in, "share_conf.ftp_port").Int()),
|
||||
FTPNamespace: gjson.GetBytes(in, "share_conf.ftp_namespace").String(),
|
||||
}
|
||||
return &SlugShareItem{
|
||||
Namespace: gjson.GetBytes(in, "tenant_id").String(),
|
||||
TenantName: gjson.GetBytes(in, "tenant_name").String(),
|
||||
@ -63,9 +81,11 @@ func NewSlugShareItem(in []byte) *SlugShareItem {
|
||||
ServiceID: gjson.GetBytes(in, "service_id").String(),
|
||||
Action: gjson.GetBytes(in, "action").String(),
|
||||
DeployVersion: gjson.GetBytes(in, "deploy_version").String(),
|
||||
ShareID: gjson.GetBytes(in, "share_id").String(),
|
||||
Logger: logger,
|
||||
EventID: eventID,
|
||||
Config: GetBuilderConfig(),
|
||||
FTPConf: sf,
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,7 +100,7 @@ func (i *SlugShareItem) Run(timeout time.Duration) error {
|
||||
}
|
||||
switch i.Dest {
|
||||
case "ys":
|
||||
if err := i.ShareToYS(); err != nil {
|
||||
if err := i.ShareToYS(packageName); err != nil {
|
||||
return err
|
||||
}
|
||||
case "yb":
|
||||
@ -88,7 +108,7 @@ func (i *SlugShareItem) Run(timeout time.Duration) error {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
if err := i.ShareToYS(); err != nil {
|
||||
if err := i.ShareToYS(packageName); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -115,8 +135,19 @@ func (i *SlugShareItem)ShareToYB()error {
|
||||
}
|
||||
|
||||
//ShareToYS ShareToYS
|
||||
func (i *SlugShareItem)ShareToYS()error {
|
||||
|
||||
func (i *SlugShareItem)ShareToYS(file string)error {
|
||||
i.Logger.Info("开始分享云市", map[string]string{"step":"slug-share"})
|
||||
if err:= i.UploadFtp(i.FTPConf.FTPNamespace, file); err != nil {
|
||||
return err
|
||||
}
|
||||
md5, err := createMD5(file)
|
||||
if err != nil {
|
||||
i.Logger.Error("生成md5失败", map[string]string{"step":"slug-share", "status":"success"})
|
||||
}
|
||||
if err := i.UploadFtp(i.FTPConf.FTPNamespace, md5); err != nil {
|
||||
return err
|
||||
}
|
||||
i.Logger.Info("分享云市完成", map[string]string{"step":"slug-share", "status":"success"})
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -126,7 +157,14 @@ func (i *SlugShareItem)ShareInfoData() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//UploadFtp UploadFtp
|
||||
func (i *SlugShareItem)UploadFtp() error {
|
||||
//UploadFtp UploadFt
|
||||
func (i *SlugShareItem)UploadFtp(path, file string) error {
|
||||
i.Logger.Info(fmt.Sprintf("开始上传代码包: %s", file), map[string]string{"step":"slug-share"})
|
||||
ftp := sources.NewFTPManager(i.FTPConf.Username, i.FTPConf.Password, i.FTPConf.Host)
|
||||
err := ftp.UploadFile(path, file, i.Logger)
|
||||
if err != nil {
|
||||
i.Logger.Error(fmt.Sprintf("上传代码包%s失败", file), map[string]string{"step":"slug-share", "status":"failure"})
|
||||
}
|
||||
i.Logger.Info("代码包上传完成", map[string]string{"step":"slug-share", "status":"success"})
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user