Skip to content

Commit

Permalink
2.0 new feature
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamans committed Jan 29, 2019
1 parent aee9155 commit bde5898
Show file tree
Hide file tree
Showing 16 changed files with 450 additions and 35 deletions.
57 changes: 57 additions & 0 deletions model/deploy_apply.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2019 syncd Author. All Rights Reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package model

import(
"time"
)

type DeployApply struct {
ID int `gorm:"primary_key"`
SpaceId int `gorm:"type:int(11);not null;default:0"`
Project int `gorm:"type:int(11);not null;default:0"`
Name string `gorm:"type:varchar(100);not null;default:''"`
Description string `gorm:"type:varchar(500);not null;default:''"`
BranchName string `gorm:"type:varchar(100);not null;default:''"`
TagName string `gorm:"type:varchar(100);not null;default:''"`
Status int `gorm:"type:int(11);not null;default:0"`
}

func (m *Project) TableName() string {
return "syd_project"
}

func (m *Project) Create() bool {
m.Ctime = int(time.Now().Unix())
return Create(m)
}

func (m *Project) Update() bool {
return UpdateByPk(m)
}

func (m *Project) UpdateByFields(data map[string]interface{}, query QueryParam) bool {
return Update(m, data, query)
}

func (m *Project) List(query QueryParam) ([]Project, bool) {
var data []Project
ok := GetMulti(&data, query)
return data, ok
}

func (m *Project) Count(query QueryParam) (int, bool) {
var count int
ok := Count(m, &count, query)
return count, ok
}

func (m *Project) Delete() bool {
return DeleteByPk(m)
}

func (m *Project) Get(id int) bool {
return GetByPk(m, id)
}
13 changes: 7 additions & 6 deletions model/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ import(
)

type Project struct {
ID int `gorm:"primary_key"`
SpaceId int `gorm:"type:int(11);not null;default:0"`
ID int `gorm:"primary_key"`
SpaceId int `gorm:"type:int(11);not null;default:0"`
Name string `gorm:"type:varchar(100);not null;default:''"`
Description string `gorm:"type:varchar(500);not null;default:''"`
NeedAudit int `gorm:"type:int(11);not null;default:0"`
Status int `gorm:"type:int(11);not null;default:0"`
NeedAudit int `gorm:"type:int(11);not null;default:0"`
Status int `gorm:"type:int(11);not null;default:0"`
RepoUrl string `gorm:"type:varchar(500);not null;default:''"`
DeployMode int `gorm:"type:int(11);not null;default:0"`
RepoBranch string `gorm:"type:varchar(100);not null;default:''"`
PreReleaseCluster int `gorm:"type:int(11);not null;default:0"`
OnlineCluster string `gorm:"type:varchar(1000);not null;default:''"`
DeployUser string `gorm:"type:varchar(100);not null;default:''"`
DeployPath string `gorm:"type:varchar(500);not null;default:''"`
BuildScript string `gorm:"type:text;not null"`
DeployPath string `gorm:"type:varchar(500);not null;default:''"`
BuildScript string `gorm:"type:text;not null"`
PreDeployCmd string `gorm:"type:text;not null"`
AfterDeployCmd string `gorm:"type:text;not null"`
DeployTimeout int `gorm:"type:int(11);not null;default:0"`
Expand Down
27 changes: 27 additions & 0 deletions module/deploy/apply.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2019 syncd Author. All Rights Reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package deploy

import (
"errors"
"fmt"

"github.com/dreamans/syncd/model"
"github.com/dreamans/syncd/util/gostring"
)

type Apply struct {
ID int `json:"id"`
SpaceId int `json:"space_id"`
ProjectId int `json:"project_id"`
Name string `json:"name"`
Description string `json:"description"`
BranchName string `json:"branch_name"`
Status int `json:"status"`
}

func (a *Apply) Create() {

}
6 changes: 5 additions & 1 deletion module/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Project struct {
Status int `json:"status"`
RepoUrl string `json:"repo_url"`
RepoBranch string `json:"repo_branch"`
DeployMode int `json:"deploy_mode"`
PreReleaseCluster int `json:"pre_release_cluster"`
OnlineCluster []int `json:"online_cluster"`
DeployUser string `json:"deploy_user"`
Expand Down Expand Up @@ -66,6 +67,7 @@ func (p *Project) Detail() error {
p.NeedAudit = project.NeedAudit
p.Status = project.Status
p.RepoUrl = project.RepoUrl
p.DeployMode = project.DeployMode
p.RepoBranch = project.RepoBranch
p.PreReleaseCluster = project.PreReleaseCluster
p.OnlineCluster = gostring.StrSplit2IntSlice(project.OnlineCluster, ",")
Expand Down Expand Up @@ -143,6 +145,7 @@ func (p *Project) CreateOrUpdate() error {
Description: p.Description,
NeedAudit: p.NeedAudit,
RepoUrl: p.RepoUrl,
DeployMode: p.DeployMode,
RepoBranch: p.RepoBranch,
PreReleaseCluster: p.PreReleaseCluster,
OnlineCluster: gostring.JoinIntSlice2String(p.OnlineCluster, ","),
Expand All @@ -158,6 +161,7 @@ func (p *Project) CreateOrUpdate() error {
"description": p.Description,
"need_audit": p.NeedAudit,
"repo_url": p.RepoUrl,
"deploy_mode": p.DeployMode,
"repo_branch": p.RepoBranch,
"pre_release_cluster": p.PreReleaseCluster,
"online_cluster": gostring.JoinIntSlice2String(p.OnlineCluster, ","),
Expand Down Expand Up @@ -209,4 +213,4 @@ func (p *Project) parseWhereConds(keyword string, spaceId int) []model.WherePara
})
}
return where
}
}
60 changes: 60 additions & 0 deletions router/deploy/apply.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2019 syncd Author. All Rights Reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package deploy

import (
"github.com/gin-gonic/gin"
"github.com/dreamans/syncd/render"
"github.com/dreamans/syncd/util/gostring"
"github.com/dreamans/syncd/module/project"
)

type ApplyFormBind struct {
ProjectId int `form:"project_id" binding:"required"`
SpaceId string `form:"space_id" binding:"required"`
Name string `form:"name" binding:"required"`
BranchName string `form:"branch_name"`
Description string `form:"description"`
}

func ApplySubmit(c *gin.Context) {
var form ApplyFormBind
if err := c.ShouldBind(&form); err != nil {
render.ParamError(c, err.Error())
return
}
apply := &deploy.Apply{
SpaceId: form.SpaceId,
ProjectId: form.ProjectId,
Name: form.Name,
Description: form.Description,
BranchName: form.BranchName,
}
apply.Create()
}

func ApplyProjectDetail(c *gin.Context) {
id := gostring.Str2Int(c.Query("id"))
if id == 0 {
render.ParamError(c, "id cannot be empty")
return
}
proj := &project.Project{
ID: id,
}
if err := proj.Detail(); err != nil {
render.AppError(c, err.Error())
return
}

restProj := map[string]interface{}{
"id": proj.ID,
"name": proj.Name,
"deploy_mode": proj.DeployMode,
"repo_branch": proj.RepoBranch,
}

render.JSON(c, restProj)
}
10 changes: 8 additions & 2 deletions router/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type ProjectFormBind struct {
NeedAudit int `form:"need_audit"`
RepoUrl string `form:"repo_url" binding:"required"`
RepoBranch string `form:"repo_branch"`
DeployMode int `form:"deploy_mode" binding:"required"`
PreReleaseCluster int `form:"pre_release_cluster"`
OnlineCluster []int `form:"online_cluster" binding:"required"`
DeployUser string `form:"deploy_user" binding:"required"`
Expand Down Expand Up @@ -173,14 +174,19 @@ func projectCreateOrUpdate(c *gin.Context) {
render.ParamError(c, "online_cluster cannot be empty")
return
}
repoBranch := projectForm.RepoBranch
if projectForm.DeployMode == 2 {
repoBranch = ""
}
proj := &project.Project{
ID: projectForm.ID,
SpaceId: projectForm.SpaceId,
Name: projectForm.Name,
Description: projectForm.Description,
NeedAudit: projectForm.NeedAudit,
RepoUrl: projectForm.RepoUrl,
RepoBranch: projectForm.RepoBranch,
DeployMode: projectForm.DeployMode,
RepoBranch: repoBranch,
PreReleaseCluster: projectForm.PreReleaseCluster,
OnlineCluster: onlineCluster,
DeployUser: projectForm.DeployUser,
Expand All @@ -194,4 +200,4 @@ func projectCreateOrUpdate(c *gin.Context) {
return
}
render.Success(c)
}
}
44 changes: 24 additions & 20 deletions router/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ package route
import (
"github.com/dreamans/syncd"
"github.com/dreamans/syncd/router/user"
"github.com/dreamans/syncd/router/server"
"github.com/dreamans/syncd/router/project"
"github.com/dreamans/syncd/router/server"
"github.com/dreamans/syncd/router/project"
"github.com/dreamans/syncd/router/deploy"
)

func RegisterRoute() {
Expand Down Expand Up @@ -37,24 +38,27 @@ func RegisterRoute() {
api.POST("/user/update", user.UserUpdate)
api.GET("/user/list", user.UserList)
api.GET("/user/exists", user.UserExists)
api.GET("/user/detail", user.UserDetail)
api.POST("/user/delete", user.UserDelete)
api.GET("/user/detail", user.UserDetail)
api.POST("/user/delete", user.UserDelete)

api.POST("/project/space/add", project.SpaceAdd)
api.POST("/project/space/update", project.SpaceUpdate)
api.GET("/project/space/list", project.SpaceList)
api.GET("/project/space/detail", project.SpaceDetail)
api.POST("/project/space/delete", project.SpaceDelete)
api.GET("/project/member/search", project.MemberSearch)
api.POST("/project/member/add", project.MemberAdd)
api.GET("/project/member/list", project.MemberList)
api.POST("/project/member/remove", project.MemberRemove)
api.POST("/project/add", project.ProjectAdd)
api.POST("/project/update", project.ProjectUpdate)
api.GET("/project/list", project.ProjectList)
api.POST("/project/switchstatus", project.ProjectSwitchStatus)
api.GET("/project/detail", project.ProjectDetail)
api.POST("/project/delete", project.ProjectDelete)
api.POST("/project/buildscript", project.ProjectBuildScript)
api.POST("/project/space/add", project.SpaceAdd)
api.POST("/project/space/update", project.SpaceUpdate)
api.GET("/project/space/list", project.SpaceList)
api.GET("/project/space/detail", project.SpaceDetail)
api.POST("/project/space/delete", project.SpaceDelete)
api.GET("/project/member/search", project.MemberSearch)
api.POST("/project/member/add", project.MemberAdd)
api.GET("/project/member/list", project.MemberList)
api.POST("/project/member/remove", project.MemberRemove)
api.POST("/project/add", project.ProjectAdd)
api.POST("/project/update", project.ProjectUpdate)
api.GET("/project/list", project.ProjectList)
api.POST("/project/switchstatus", project.ProjectSwitchStatus)
api.GET("/project/detail", project.ProjectDetail)
api.POST("/project/delete", project.ProjectDelete)
api.POST("/project/buildscript", project.ProjectBuildScript)

api.GET("/deploy/apply/project/detail", deploy.ApplyProjectDetail)
api.POST("/deploy/apply/submit", deploy.ApplySubmit)
}
}
2 changes: 1 addition & 1 deletion web/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_1024174_lgaxpapigfi.css">
<link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_1024174_hw0erplt4st.css">
<title>web</title>
</head>
<body>
Expand Down
9 changes: 9 additions & 0 deletions web/src/api/deploy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {get, post} from '@/lib/fetch.js'

export function applyProjectDetailApi(params) {
return get('/deploy/apply/project/detail', params)
}

export function applySubmitApi(data) {
return post('/deploy/apply/submit', data)
}
24 changes: 23 additions & 1 deletion web/src/lang/zh_cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default {
'open': '开启',
'close': '关闭',
'repo_setting': '仓库设置',
'if_not_need_to_assign_branch_name': '若不指定,需要在发起上线时手动填写分支(或Tag)名称',
'if_not_need_to_assign_branch_name': '若不指定,需要在发起上线时手动填写分支名称',
'deploy_setting': '部署设置',
'selected_cluster_list': '已选集群列表',
'view_project_info': '查看项目信息',
Expand All @@ -158,4 +158,26 @@ export default {
'build_script_tips': '脚本会在代码下载完成后执行,构建脚本支持的变量',
'build_script_env_workspace': '代码仓库本地副本目录',
'build_script_env_pack_file': '打包文件绝对地址,构建完成后将需要部署到线上的代码打包到此文件中,必须使用 <span class="code">tar -zcf</span> 命令进行打包。部署模块会将此压缩包分发到目标主机并解压缩到指定目录,请按照要求打包,否则会部署失败。',
'select_project': '选择项目',
'project_space_cannot_empty': '项目空间不能为空',
'project_cannot_empty': '项目不能为空',
'input_apply_order': '填写上线单',
'input_deploy_apply': '填写上线申请',
'deploy_mode': '上线模式',
'deploy_mode_cannot_empty': '上线模式不能为空',
'branch_deploy': '分支上线',
'tag_deploy': 'Tag上线',
'deploy_mode_tips': '测试环境推荐分支上线,生产环境推荐tag上线',
'apply_name': '上线单名称',
'please_input_apply_name': '请输入上线单名称',
'tag_name': 'Tag名称',
'tag_name_cannot_empty': 'Tag名称不能为空',
'please_input_tag_name': '请输入Tag名称',
'branch_name_cannot_empty': '分支名称不能为空',
'please_input_branch_name': '请输入分支名称',
'branch_name': '分支名称',
'deploy_illustrate': '上线说明',
'please_input_deploy_illustrate': '请详细填写上线说明',
'deploy_illustrate_cannot_empty': '上线说明不能为空',
'commit_version': '选择上线版本',
}
6 changes: 3 additions & 3 deletions web/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ const routerMap = [
meta: {
title: i18n.t('submit_deploy_apply'),
},
component: _import('Dashboard'),
component: _import('deploy/Apply'),
},
{
path: 'deploy',
name: 'deployDeploy',
meta: {
title: i18n.t('deploy_manage'),
},
component: _import('Dashboard'),
component: _import('deploy/Deploy'),
},
{
path: 'release',
Expand All @@ -65,7 +65,7 @@ const routerMap = [
title: i18n.t('deploying_deploy'),
hide: true,
},
component: _import('Dashboard'),
component: _import('deploy/Release'),
},
],
},
Expand Down
2 changes: 1 addition & 1 deletion web/src/scss/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ html, body {
}

// reset element css
.el-checkbox {
.el-checkbox, .el-radio {
font-weight: 400;
}

Expand Down
Loading

0 comments on commit bde5898

Please sign in to comment.