2018-03-14 14:12:26 +08:00
|
|
|
// Copyright (C) 2014-2018 Goodrain Co., Ltd.
|
2017-11-20 17:29:39 +08:00
|
|
|
// RAINBOND, Application Management Platform
|
2018-03-14 14:33:31 +08:00
|
|
|
|
2017-11-20 17:29:39 +08:00
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version. For any non-GPL usage of Rainbond,
|
|
|
|
// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd.
|
|
|
|
// must be obtained first.
|
2018-03-14 14:33:31 +08:00
|
|
|
|
2017-11-20 17:29:39 +08:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
2018-03-14 14:33:31 +08:00
|
|
|
|
2017-11-20 17:29:39 +08:00
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package model
|
|
|
|
|
2018-09-19 18:51:16 +08:00
|
|
|
import (
|
2019-06-24 16:48:43 +08:00
|
|
|
"fmt"
|
2019-08-16 06:53:16 +08:00
|
|
|
"time"
|
2019-06-24 16:48:43 +08:00
|
|
|
|
2018-09-19 18:51:16 +08:00
|
|
|
"github.com/docker/distribution/reference"
|
2020-11-25 16:39:38 +08:00
|
|
|
"github.com/sirupsen/logrus"
|
2018-09-19 18:51:16 +08:00
|
|
|
)
|
|
|
|
|
2023-09-04 13:44:55 +08:00
|
|
|
// VersionInfo version info struct
|
2017-11-20 17:29:39 +08:00
|
|
|
type VersionInfo struct {
|
|
|
|
Model
|
2019-08-22 14:20:08 +08:00
|
|
|
BuildVersion string `gorm:"column:build_version;size:40" json:"build_version"` //唯一
|
2022-11-28 20:57:28 +08:00
|
|
|
EventID string `gorm:"column:event_id;size:40;index:event_id" json:"event_id"`
|
|
|
|
ServiceID string `gorm:"column:service_id;size:40;index:service_id" json:"service_id"`
|
2019-08-22 14:20:08 +08:00
|
|
|
Kind string `gorm:"column:kind;size:40" json:"kind"` //kind
|
2018-09-01 19:32:35 +08:00
|
|
|
//DeliveredType app version delivered type
|
|
|
|
//image: this is a docker image
|
|
|
|
//slug: this is a source code tar file
|
2019-08-22 14:20:08 +08:00
|
|
|
DeliveredType string `gorm:"column:delivered_type;size:40" json:"delivered_type"` //kind
|
|
|
|
DeliveredPath string `gorm:"column:delivered_path;size:250" json:"delivered_path"` //交付物path
|
|
|
|
ImageName string `gorm:"column:image_name;size:250" json:"image_name"` //运行镜像名称
|
2020-08-09 13:08:36 +08:00
|
|
|
Cmd string `gorm:"column:cmd;size:2048" json:"cmd"` //启动命令
|
2020-07-14 17:17:37 +08:00
|
|
|
RepoURL string `gorm:"column:repo_url;size:2047" json:"repo_url"`
|
2019-08-22 14:20:08 +08:00
|
|
|
CodeVersion string `gorm:"column:code_version;size:40" json:"code_version"`
|
2019-08-27 11:29:23 +08:00
|
|
|
CodeBranch string `gorm:"column:code_branch;size:40" json:"code_branch"`
|
2020-12-02 21:06:48 +08:00
|
|
|
CommitMsg string `gorm:"column:code_commit_msg;size:1024" json:"code_commit_msg"`
|
2019-08-22 14:20:08 +08:00
|
|
|
Author string `gorm:"column:code_commit_author;size:40" json:"code_commit_author"`
|
2018-09-01 19:32:35 +08:00
|
|
|
//FinalStatus app version status
|
|
|
|
//success: version available
|
|
|
|
//failure: build failure
|
|
|
|
//lost: there is no delivered
|
2019-08-22 14:20:08 +08:00
|
|
|
FinalStatus string `gorm:"column:final_status;size:40" json:"final_status"`
|
|
|
|
FinishTime time.Time `gorm:"column:finish_time;" json:"finish_time"`
|
2023-09-04 13:44:55 +08:00
|
|
|
PlanVersion string `gorm:"column:plan_version;size:250" json:"plan_version"`
|
2017-11-20 17:29:39 +08:00
|
|
|
}
|
|
|
|
|
2023-09-04 13:44:55 +08:00
|
|
|
// VersionInfoCount VersionInfoCount
|
|
|
|
type VersionInfoCount struct {
|
|
|
|
ServiceID string
|
|
|
|
Count uint
|
|
|
|
}
|
|
|
|
|
|
|
|
// TableName 表名
|
2017-11-20 17:29:39 +08:00
|
|
|
func (t *VersionInfo) TableName() string {
|
2018-11-22 14:33:29 +08:00
|
|
|
return "tenant_service_version"
|
2017-11-20 17:29:39 +08:00
|
|
|
}
|
2018-09-19 18:51:16 +08:00
|
|
|
|
2023-09-04 13:44:55 +08:00
|
|
|
// CreateShareImage create share image name
|
2018-09-19 18:51:16 +08:00
|
|
|
func (t *VersionInfo) CreateShareImage(hubURL, namespace, appVersion string) (string, error) {
|
|
|
|
_, err := reference.ParseAnyReference(t.DeliveredPath)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Errorf("reference image error: %s", err.Error())
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
image := ParseImage(t.DeliveredPath)
|
|
|
|
if hubURL != "" {
|
|
|
|
image.Host = hubURL
|
|
|
|
}
|
|
|
|
if namespace != "" {
|
|
|
|
image.Namespace = namespace
|
|
|
|
}
|
2019-06-24 16:48:43 +08:00
|
|
|
image.Name = fmt.Sprintf("%s:%s", t.ServiceID, t.BuildVersion)
|
2018-09-19 18:51:16 +08:00
|
|
|
return image.String(), nil
|
|
|
|
}
|