mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-08 13:39:53 +00:00
add deploy info
This commit is contained in:
parent
bae35536b8
commit
fb40caa25c
@ -19,6 +19,7 @@ import (
|
|||||||
type aliyun struct {
|
type aliyun struct {
|
||||||
client *cas20200407.Client
|
client *cas20200407.Client
|
||||||
option *DeployerOption
|
option *DeployerOption
|
||||||
|
infos []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAliyun(option *DeployerOption) (Deployer, error) {
|
func NewAliyun(option *DeployerOption) (Deployer, error) {
|
||||||
@ -26,6 +27,7 @@ func NewAliyun(option *DeployerOption) (Deployer, error) {
|
|||||||
json.Unmarshal([]byte(option.Access), access)
|
json.Unmarshal([]byte(option.Access), access)
|
||||||
a := &aliyun{
|
a := &aliyun{
|
||||||
option: option,
|
option: option,
|
||||||
|
infos: make([]string, 0),
|
||||||
}
|
}
|
||||||
client, err := a.createClient(access.AccessKeyId, access.AccessKeySecret)
|
client, err := a.createClient(access.AccessKeyId, access.AccessKeySecret)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -36,6 +38,10 @@ func NewAliyun(option *DeployerOption) (Deployer, error) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *aliyun) GetInfo() []string {
|
||||||
|
return a.infos
|
||||||
|
}
|
||||||
|
|
||||||
func (a *aliyun) Deploy(ctx context.Context) error {
|
func (a *aliyun) Deploy(ctx context.Context) error {
|
||||||
|
|
||||||
// 查询有没有对应的资源
|
// 查询有没有对应的资源
|
||||||
@ -44,24 +50,32 @@ func (a *aliyun) Deploy(ctx context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.infos = append(a.infos, toStr("查询对应的资源", resource))
|
||||||
|
|
||||||
// 查询有没有对应的联系人
|
// 查询有没有对应的联系人
|
||||||
contacts, err := a.contacts()
|
contacts, err := a.contacts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.infos = append(a.infos, toStr("查询联系人", contacts))
|
||||||
|
|
||||||
// 上传证书
|
// 上传证书
|
||||||
certId, err := a.uploadCert(&a.option.Certificate)
|
certId, err := a.uploadCert(&a.option.Certificate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.infos = append(a.infos, toStr("上传证书", certId))
|
||||||
|
|
||||||
// 部署证书
|
// 部署证书
|
||||||
jobId, err := a.deploy(resource, certId, contacts)
|
jobId, err := a.deploy(resource, certId, contacts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.infos = append(a.infos, toStr("创建部署证书任务", jobId))
|
||||||
|
|
||||||
// 等待部署成功
|
// 等待部署成功
|
||||||
err = a.updateDeployStatus(*jobId)
|
err = a.updateDeployStatus(*jobId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -80,10 +94,11 @@ func (a *aliyun) updateDeployStatus(jobId int64) error {
|
|||||||
JobId: tea.Int64(jobId),
|
JobId: tea.Int64(jobId),
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := a.client.UpdateDeploymentJobStatus(req)
|
resp, err := a.client.UpdateDeploymentJobStatus(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
a.infos = append(a.infos, toStr("查询对应的资源", resp))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
type AliyunCdn struct {
|
type AliyunCdn struct {
|
||||||
client *cdn20180510.Client
|
client *cdn20180510.Client
|
||||||
option *DeployerOption
|
option *DeployerOption
|
||||||
|
infos []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAliyunCdn(option *DeployerOption) (*AliyunCdn, error) {
|
func NewAliyunCdn(option *DeployerOption) (*AliyunCdn, error) {
|
||||||
@ -31,9 +32,14 @@ func NewAliyunCdn(option *DeployerOption) (*AliyunCdn, error) {
|
|||||||
return &AliyunCdn{
|
return &AliyunCdn{
|
||||||
client: client,
|
client: client,
|
||||||
option: option,
|
option: option,
|
||||||
|
infos: make([]string, 0),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *AliyunCdn) GetInfo() []string {
|
||||||
|
return a.infos
|
||||||
|
}
|
||||||
|
|
||||||
func (a *AliyunCdn) Deploy(ctx context.Context) error {
|
func (a *AliyunCdn) Deploy(ctx context.Context) error {
|
||||||
|
|
||||||
certName := fmt.Sprintf("%s-%s", a.option.Domain, a.option.DomainId)
|
certName := fmt.Sprintf("%s-%s", a.option.Domain, a.option.DomainId)
|
||||||
@ -49,11 +55,13 @@ func (a *AliyunCdn) Deploy(ctx context.Context) error {
|
|||||||
|
|
||||||
runtime := &util.RuntimeOptions{}
|
runtime := &util.RuntimeOptions{}
|
||||||
|
|
||||||
_, err := a.client.SetCdnDomainSSLCertificateWithOptions(setCdnDomainSSLCertificateRequest, runtime)
|
resp, err := a.client.SetCdnDomainSSLCertificateWithOptions(setCdnDomainSSLCertificateRequest, runtime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.infos = append(a.infos, toStr("cdn设置证书", resp))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package deployer
|
|||||||
import (
|
import (
|
||||||
"certimate/internal/applicant"
|
"certimate/internal/applicant"
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -31,6 +32,7 @@ type DeployerOption struct {
|
|||||||
|
|
||||||
type Deployer interface {
|
type Deployer interface {
|
||||||
Deploy(ctx context.Context) error
|
Deploy(ctx context.Context) error
|
||||||
|
GetInfo() []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func Get(record *models.Record, cert *applicant.Certificate) (Deployer, error) {
|
func Get(record *models.Record, cert *applicant.Certificate) (Deployer, error) {
|
||||||
@ -73,3 +75,11 @@ func getProduct(record *models.Record) string {
|
|||||||
}
|
}
|
||||||
return rs[1]
|
return rs[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func toStr(tag string, data any) string {
|
||||||
|
if data == nil {
|
||||||
|
return tag
|
||||||
|
}
|
||||||
|
byts, _ := json.Marshal(data)
|
||||||
|
return tag + ":" + string(byts)
|
||||||
|
}
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
type ssh struct {
|
type ssh struct {
|
||||||
option *DeployerOption
|
option *DeployerOption
|
||||||
|
infos []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type sshAccess struct {
|
type sshAccess struct {
|
||||||
@ -30,9 +31,14 @@ type sshAccess struct {
|
|||||||
func NewSSH(option *DeployerOption) (Deployer, error) {
|
func NewSSH(option *DeployerOption) (Deployer, error) {
|
||||||
return &ssh{
|
return &ssh{
|
||||||
option: option,
|
option: option,
|
||||||
|
infos: make([]string, 0),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ssh) GetInfo() []string {
|
||||||
|
return s.infos
|
||||||
|
}
|
||||||
|
|
||||||
func (s *ssh) Deploy(ctx context.Context) error {
|
func (s *ssh) Deploy(ctx context.Context) error {
|
||||||
access := &sshAccess{}
|
access := &sshAccess{}
|
||||||
if err := json.Unmarshal([]byte(s.option.Access), access); err != nil {
|
if err := json.Unmarshal([]byte(s.option.Access), access); err != nil {
|
||||||
@ -45,6 +51,8 @@ func (s *ssh) Deploy(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
|
|
||||||
|
s.infos = append(s.infos, toStr("ssh连接成功", nil))
|
||||||
|
|
||||||
// 上传
|
// 上传
|
||||||
session, err := client.NewSession()
|
session, err := client.NewSession()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -52,16 +60,22 @@ func (s *ssh) Deploy(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
defer session.Close()
|
defer session.Close()
|
||||||
|
|
||||||
|
s.infos = append(s.infos, toStr("ssh创建session成功", nil))
|
||||||
|
|
||||||
// 上传证书
|
// 上传证书
|
||||||
if err := s.upload(client, s.option.Certificate.Certificate, access.CertPath); err != nil {
|
if err := s.upload(client, s.option.Certificate.Certificate, access.CertPath); err != nil {
|
||||||
return fmt.Errorf("failed to upload certificate: %w", err)
|
return fmt.Errorf("failed to upload certificate: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.infos = append(s.infos, toStr("ssh上传证书成功", nil))
|
||||||
|
|
||||||
// 上传私钥
|
// 上传私钥
|
||||||
if err := s.upload(client, s.option.Certificate.PrivateKey, access.KeyPath); err != nil {
|
if err := s.upload(client, s.option.Certificate.PrivateKey, access.KeyPath); err != nil {
|
||||||
return fmt.Errorf("failed to upload private key: %w", err)
|
return fmt.Errorf("failed to upload private key: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.infos = append(s.infos, toStr("ssh上传私钥成功", nil))
|
||||||
|
|
||||||
// 执行命令
|
// 执行命令
|
||||||
var stdoutBuf bytes.Buffer
|
var stdoutBuf bytes.Buffer
|
||||||
session.Stdout = &stdoutBuf
|
session.Stdout = &stdoutBuf
|
||||||
@ -72,6 +86,8 @@ func (s *ssh) Deploy(ctx context.Context) error {
|
|||||||
return fmt.Errorf("failed to run command: %w, stdout: %s, stderr: %s", err, stdoutBuf.String(), stderrBuf.String())
|
return fmt.Errorf("failed to run command: %w, stdout: %s, stderr: %s", err, stdoutBuf.String(), stderrBuf.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.infos = append(s.infos, toStr("ssh执行命令成功", []string{stdoutBuf.String()}))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
type tencentCdn struct {
|
type tencentCdn struct {
|
||||||
option *DeployerOption
|
option *DeployerOption
|
||||||
credential *common.Credential
|
credential *common.Credential
|
||||||
|
infos []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTencentCdn(option *DeployerOption) (Deployer, error) {
|
func NewTencentCdn(option *DeployerOption) (Deployer, error) {
|
||||||
@ -34,9 +35,14 @@ func NewTencentCdn(option *DeployerOption) (Deployer, error) {
|
|||||||
return &tencentCdn{
|
return &tencentCdn{
|
||||||
option: option,
|
option: option,
|
||||||
credential: credential,
|
credential: credential,
|
||||||
|
infos: make([]string, 0),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *tencentCdn) GetInfo() []string {
|
||||||
|
return t.infos
|
||||||
|
}
|
||||||
|
|
||||||
func (t *tencentCdn) Deploy(ctx context.Context) error {
|
func (t *tencentCdn) Deploy(ctx context.Context) error {
|
||||||
|
|
||||||
// 查询有没有对应的资源
|
// 查询有没有对应的资源
|
||||||
@ -45,11 +51,14 @@ func (t *tencentCdn) Deploy(ctx context.Context) error {
|
|||||||
return fmt.Errorf("failed to get resource: %w", err)
|
return fmt.Errorf("failed to get resource: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.infos = append(t.infos, toStr("查询对应的资源", resource))
|
||||||
|
|
||||||
// 上传证书
|
// 上传证书
|
||||||
certId, err := t.uploadCert()
|
certId, err := t.uploadCert()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to upload certificate: %w", err)
|
return fmt.Errorf("failed to upload certificate: %w", err)
|
||||||
}
|
}
|
||||||
|
t.infos = append(t.infos, toStr("上传证书", certId))
|
||||||
|
|
||||||
if err := t.deploy(resource, certId); err != nil {
|
if err := t.deploy(resource, certId); err != nil {
|
||||||
return fmt.Errorf("failed to deploy: %w", err)
|
return fmt.Errorf("failed to deploy: %w", err)
|
||||||
@ -100,11 +109,12 @@ func (t *tencentCdn) deploy(resource *tag.ResourceTagMapping, certId string) err
|
|||||||
request.Status = common.Int64Ptr(1)
|
request.Status = common.Int64Ptr(1)
|
||||||
|
|
||||||
// 返回的resp是一个DeployCertificateInstanceResponse的实例,与请求对象对应
|
// 返回的resp是一个DeployCertificateInstanceResponse的实例,与请求对象对应
|
||||||
_, err = client.DeployCertificateInstance(request)
|
resp, err := client.DeployCertificateInstance(request)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to deploy certificate: %w", err)
|
return fmt.Errorf("failed to deploy certificate: %w", err)
|
||||||
}
|
}
|
||||||
|
t.infos = append(t.infos, toStr("部署证书", resp.Response))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,15 +21,21 @@ type hookData struct {
|
|||||||
|
|
||||||
type webhook struct {
|
type webhook struct {
|
||||||
option *DeployerOption
|
option *DeployerOption
|
||||||
|
infos []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWebhook(option *DeployerOption) (Deployer, error) {
|
func NewWebhook(option *DeployerOption) (Deployer, error) {
|
||||||
|
|
||||||
return &webhook{
|
return &webhook{
|
||||||
option: option,
|
option: option,
|
||||||
|
infos: make([]string, 0),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *webhook) GetInfo() []string {
|
||||||
|
return w.infos
|
||||||
|
}
|
||||||
|
|
||||||
func (w *webhook) Deploy(ctx context.Context) error {
|
func (w *webhook) Deploy(ctx context.Context) error {
|
||||||
access := &webhookAccess{}
|
access := &webhookAccess{}
|
||||||
if err := json.Unmarshal([]byte(w.option.Access), access); err != nil {
|
if err := json.Unmarshal([]byte(w.option.Access), access); err != nil {
|
||||||
@ -44,12 +50,14 @@ func (w *webhook) Deploy(ctx context.Context) error {
|
|||||||
|
|
||||||
body, _ := json.Marshal(data)
|
body, _ := json.Marshal(data)
|
||||||
|
|
||||||
_, err := xhttp.Req(access.Url, http.MethodPost, bytes.NewReader(body), map[string]string{
|
resp, err := xhttp.Req(access.Url, http.MethodPost, bytes.NewReader(body), map[string]string{
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to send hook request: %w", err)
|
return fmt.Errorf("failed to send hook request: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.infos = append(w.infos, toStr("webhook response", string(resp)))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -27,16 +27,17 @@ func deploy(ctx context.Context, record *models.Record) error {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
var certificate *applicant.Certificate
|
var certificate *applicant.Certificate
|
||||||
currRecord, err := app.GetApp().Dao().FindRecordById("domains", record.Id)
|
|
||||||
history := NewHistory(record)
|
history := NewHistory(record)
|
||||||
defer history.commit()
|
defer history.commit()
|
||||||
|
|
||||||
// ############1.检查域名配置
|
// ############1.检查域名配置
|
||||||
history.record(checkPhase, "开始检查", nil)
|
history.record(checkPhase, "开始检查", nil)
|
||||||
|
|
||||||
|
currRecord, err := app.GetApp().Dao().FindRecordById("domains", record.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.GetApp().Logger().Error("获取记录失败", "err", err)
|
app.GetApp().Logger().Error("获取记录失败", "err", err)
|
||||||
history.record(checkPhase, "获取域名配置失败", err)
|
history.record(checkPhase, "获取域名配置失败", &RecordInfo{Err: err})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
history.record(checkPhase, "获取记录成功", nil)
|
history.record(checkPhase, "获取记录成功", nil)
|
||||||
@ -48,7 +49,7 @@ func deploy(ctx context.Context, record *models.Record) error {
|
|||||||
}
|
}
|
||||||
err = errors.Join(errList...)
|
err = errors.Join(errList...)
|
||||||
app.GetApp().Logger().Error("展开记录失败", "err", err)
|
app.GetApp().Logger().Error("展开记录失败", "err", err)
|
||||||
history.record(checkPhase, "获取授权信息失败", err)
|
history.record(checkPhase, "获取授权信息失败", &RecordInfo{Err: err})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
history.record(checkPhase, "获取授权信息成功", nil)
|
history.record(checkPhase, "获取授权信息成功", nil)
|
||||||
@ -56,9 +57,11 @@ func deploy(ctx context.Context, record *models.Record) error {
|
|||||||
cert := currRecord.GetString("certificate")
|
cert := currRecord.GetString("certificate")
|
||||||
expiredAt := currRecord.GetDateTime("expiredAt").Time()
|
expiredAt := currRecord.GetDateTime("expiredAt").Time()
|
||||||
|
|
||||||
if cert != "" && time.Until(expiredAt) > time.Hour*24 && currRecord.GetBool("deployed") {
|
if cert != "" && time.Until(expiredAt) > time.Hour*24*10 && currRecord.GetBool("deployed") {
|
||||||
app.GetApp().Logger().Info("证书在有效期内")
|
app.GetApp().Logger().Info("证书在有效期内")
|
||||||
history.record(checkPhase, "证书在有效期内且已部署,跳过", nil, true)
|
history.record(checkPhase, "证书在有效期内且已部署,跳过", &RecordInfo{
|
||||||
|
Info: []string{fmt.Sprintf("证书有效期至 %s", expiredAt.Format("2006-01-02"))},
|
||||||
|
}, true)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
history.record(checkPhase, "检查通过", nil, true)
|
history.record(checkPhase, "检查通过", nil, true)
|
||||||
@ -67,21 +70,25 @@ func deploy(ctx context.Context, record *models.Record) error {
|
|||||||
history.record(applyPhase, "开始申请", nil)
|
history.record(applyPhase, "开始申请", nil)
|
||||||
|
|
||||||
if cert != "" && time.Until(expiredAt) > time.Hour*24 {
|
if cert != "" && time.Until(expiredAt) > time.Hour*24 {
|
||||||
history.record(applyPhase, "证书在有效期内,跳过", nil)
|
history.record(applyPhase, "证书在有效期内,跳过", &RecordInfo{
|
||||||
|
Info: []string{fmt.Sprintf("证书有效期至 %s", expiredAt.Format("2006-01-02"))},
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
applicant, err := applicant.Get(currRecord)
|
applicant, err := applicant.Get(currRecord)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
history.record(applyPhase, "获取applicant失败", err)
|
history.record(applyPhase, "获取applicant失败", &RecordInfo{Err: err})
|
||||||
app.GetApp().Logger().Error("获取applicant失败", "err", err)
|
app.GetApp().Logger().Error("获取applicant失败", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
certificate, err = applicant.Apply()
|
certificate, err = applicant.Apply()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
history.record(applyPhase, "申请证书失败", err)
|
history.record(applyPhase, "申请证书失败", &RecordInfo{Err: err})
|
||||||
app.GetApp().Logger().Error("申请证书失败", "err", err)
|
app.GetApp().Logger().Error("申请证书失败", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
history.record(applyPhase, "申请证书成功", nil)
|
history.record(applyPhase, "申请证书成功", &RecordInfo{
|
||||||
|
Info: []string{fmt.Sprintf("证书地址: %s", certificate.CertUrl)},
|
||||||
|
})
|
||||||
history.setCert(certificate)
|
history.setCert(certificate)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +98,7 @@ func deploy(ctx context.Context, record *models.Record) error {
|
|||||||
history.record(deployPhase, "开始部署", nil, false)
|
history.record(deployPhase, "开始部署", nil, false)
|
||||||
deployer, err := deployer.Get(currRecord, certificate)
|
deployer, err := deployer.Get(currRecord, certificate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
history.record(deployPhase, "获取deployer失败", err)
|
history.record(deployPhase, "获取deployer失败", &RecordInfo{Err: err})
|
||||||
app.GetApp().Logger().Error("获取deployer失败", "err", err)
|
app.GetApp().Logger().Error("获取deployer失败", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -99,12 +106,14 @@ func deploy(ctx context.Context, record *models.Record) error {
|
|||||||
if err = deployer.Deploy(ctx); err != nil {
|
if err = deployer.Deploy(ctx); err != nil {
|
||||||
|
|
||||||
app.GetApp().Logger().Error("部署失败", "err", err)
|
app.GetApp().Logger().Error("部署失败", "err", err)
|
||||||
history.record(deployPhase, "部署失败", err)
|
history.record(deployPhase, "部署失败", &RecordInfo{Err: err, Info: deployer.GetInfo()})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
app.GetApp().Logger().Info("部署成功")
|
app.GetApp().Logger().Info("部署成功")
|
||||||
history.record(deployPhase, "部署成功", nil, true)
|
history.record(deployPhase, "部署成功", &RecordInfo{
|
||||||
|
Info: deployer.GetInfo(),
|
||||||
|
}, true)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,12 @@ type historyItem struct {
|
|||||||
Time string `json:"time"`
|
Time string `json:"time"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
|
Info []string `json:"info"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RecordInfo struct {
|
||||||
|
Err error `json:"err"`
|
||||||
|
Info []string `json:"info"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type history struct {
|
type history struct {
|
||||||
@ -34,21 +40,25 @@ func NewHistory(record *models.Record) *history {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *history) record(phase Phase, msg string, err error, pass ...bool) {
|
func (a *history) record(phase Phase, msg string, info *RecordInfo, pass ...bool) {
|
||||||
|
if info == nil {
|
||||||
|
info = &RecordInfo{}
|
||||||
|
}
|
||||||
a.Phase = phase
|
a.Phase = phase
|
||||||
if len(pass) > 0 {
|
if len(pass) > 0 {
|
||||||
a.PhaseSuccess = pass[0]
|
a.PhaseSuccess = pass[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
errMsg := ""
|
errMsg := ""
|
||||||
if err != nil {
|
if info.Err != nil {
|
||||||
errMsg = err.Error()
|
errMsg = info.Err.Error()
|
||||||
a.PhaseSuccess = false
|
a.PhaseSuccess = false
|
||||||
}
|
}
|
||||||
|
|
||||||
a.Log[phase] = append(a.Log[phase], historyItem{
|
a.Log[phase] = append(a.Log[phase], historyItem{
|
||||||
Message: msg,
|
Message: msg,
|
||||||
Error: errMsg,
|
Error: errMsg,
|
||||||
|
Info: info.Info,
|
||||||
Time: xtime.BeijingTimeStr(),
|
Time: xtime.BeijingTimeStr(),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
2
ui/dist/index.html
vendored
2
ui/dist/index.html
vendored
@ -5,7 +5,7 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Certimate - Your Trusted SSL Automation Partner</title>
|
<title>Certimate - Your Trusted SSL Automation Partner</title>
|
||||||
<script type="module" crossorigin src="/assets/index-B6xIlnQB.js"></script>
|
<script type="module" crossorigin src="/assets/index-D3t3IJ9L.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-VYJgHfoP.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-VYJgHfoP.css">
|
||||||
</head>
|
</head>
|
||||||
<body class="bg-background">
|
<body class="bg-background">
|
||||||
|
@ -24,6 +24,7 @@ export type Log = {
|
|||||||
time: string;
|
time: string;
|
||||||
message: string;
|
message: string;
|
||||||
error: string;
|
error: string;
|
||||||
|
info?: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DeploymentListReq = {
|
export type DeploymentListReq = {
|
||||||
|
@ -187,7 +187,7 @@ export default function Dashboard() {
|
|||||||
href="https://github.com/usual2970/certimate/releases"
|
href="https://github.com/usual2970/certimate/releases"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
>
|
>
|
||||||
Certimate v0.0.7
|
Certimate v0.0.8
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -147,6 +147,14 @@ const History = () => {
|
|||||||
<div>[{item.time}]</div>
|
<div>[{item.time}]</div>
|
||||||
<div className="ml-2">{item.message}</div>
|
<div className="ml-2">{item.message}</div>
|
||||||
</div>
|
</div>
|
||||||
|
{item.info &&
|
||||||
|
item.info.map((info: string) => {
|
||||||
|
return (
|
||||||
|
<div className="mt-1 text-green-600">
|
||||||
|
{info}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
{item.error && (
|
{item.error && (
|
||||||
<div className="mt-1 text-red-600">
|
<div className="mt-1 text-red-600">
|
||||||
{item.error}
|
{item.error}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user