A symlink backup number

This commit is contained in:
zhenorzz 2021-08-20 10:36:25 +08:00
parent 442b41becb
commit f9678c5831
8 changed files with 59 additions and 9 deletions

View File

@ -185,6 +185,7 @@ func (Project) Add(gp *core.Goploy) *core.Response {
Environment uint8 `json:"environment" validate:"required"`
Branch string `json:"branch" validate:"required"`
SymlinkPath string `json:"symlinkPath"`
SymlinkBackupNumber uint8 `json:"symlinkBackupNumber"`
Review uint8 `json:"review"`
ReviewURL string `json:"reviewURL"`
AfterPullScriptMode string `json:"afterPullScriptMode"`
@ -215,6 +216,7 @@ func (Project) Add(gp *core.Goploy) *core.Response {
Environment: reqData.Environment,
Branch: reqData.Branch,
SymlinkPath: reqData.SymlinkPath,
SymlinkBackupNumber: reqData.SymlinkBackupNumber,
Review: reqData.Review,
ReviewURL: reqData.ReviewURL,
AfterPullScriptMode: reqData.AfterPullScriptMode,
@ -278,6 +280,7 @@ func (Project) Edit(gp *core.Goploy) *core.Response {
URL string `json:"url"`
Path string `json:"path"`
SymlinkPath string `json:"symlinkPath"`
SymlinkBackupNumber uint8 `json:"symlinkBackupNumber"`
Review uint8 `json:"review"`
ReviewURL string `json:"reviewURL"`
Environment uint8 `json:"environment"`
@ -313,6 +316,7 @@ func (Project) Edit(gp *core.Goploy) *core.Response {
Environment: reqData.Environment,
Branch: reqData.Branch,
SymlinkPath: reqData.SymlinkPath,
SymlinkBackupNumber: reqData.SymlinkBackupNumber,
Review: reqData.Review,
ReviewURL: reqData.ReviewURL,
AfterPullScriptMode: reqData.AfterPullScriptMode,

View File

@ -19,6 +19,7 @@ type Project struct {
Environment uint8 `json:"environment"`
Branch string `json:"branch"`
SymlinkPath string `json:"symlinkPath"`
SymlinkBackupNumber uint8 `json:"symlinkBackupNumber"`
Review uint8 `json:"review"`
ReviewURL string `json:"reviewURL"`
AfterPullScriptMode string `json:"afterPullScriptMode"`
@ -77,6 +78,7 @@ func (p Project) AddRow() (int64, error) {
"environment",
"branch",
"symlink_path",
"symlink_backup_number",
"review",
"review_url",
"after_pull_script_mode",
@ -96,6 +98,7 @@ func (p Project) AddRow() (int64, error) {
p.Environment,
p.Branch,
p.SymlinkPath,
p.SymlinkBackupNumber,
p.Review,
p.ReviewURL,
p.AfterPullScriptMode,
@ -127,6 +130,7 @@ func (p Project) EditRow() error {
"environment": p.Environment,
"branch": p.Branch,
"symlink_path": p.SymlinkPath,
"symlink_backup_number": p.SymlinkBackupNumber,
"review": p.Review,
"review_url": p.ReviewURL,
"after_pull_script_mode": p.AfterPullScriptMode,
@ -240,6 +244,7 @@ func (p Project) GetList(pagination Pagination) (Projects, error) {
environment,
branch,
symlink_path,
symlink_backup_number,
review,
review_url,
after_pull_script_mode,
@ -287,6 +292,7 @@ func (p Project) GetList(pagination Pagination) (Projects, error) {
&project.Environment,
&project.Branch,
&project.SymlinkPath,
&project.SymlinkBackupNumber,
&project.Review,
&project.ReviewURL,
&project.AfterPullScriptMode,
@ -395,7 +401,32 @@ func (p Project) GetUserProjectList() (Projects, error) {
func (p Project) GetData() (Project, error) {
var project Project
err := sq.
Select("id, namespace_id, name, repo_type, url, path, environment, branch, symlink_path, review, review_url, after_pull_script_mode, after_pull_script, after_deploy_script_mode, after_deploy_script, rsync_option, auto_deploy, deploy_state, notify_type, notify_target, project.last_publish_token, insert_time, update_time").
Select(`
id,
namespace_id,
name,
repo_type,
url,
path,
environment,
branch,
symlink_path,
symlink_backup_number,
review,
review_url,
after_pull_script_mode,
after_pull_script,
after_deploy_script_mode,
after_deploy_script,
rsync_option,
auto_deploy,
deploy_state,
notify_type,
notify_target,
project.
last_publish_token,
insert_time,
update_time`).
From(projectTable).
Where(sq.Eq{"id": p.ID}).
RunWith(DB).
@ -410,6 +441,7 @@ func (p Project) GetData() (Project, error) {
&project.Environment,
&project.Branch,
&project.SymlinkPath,
&project.SymlinkBackupNumber,
&project.Review,
&project.ReviewURL,
&project.AfterPullScriptMode,

View File

@ -1,4 +1,5 @@
ALTER TABLE `goploy`.`project`
ADD COLUMN `repo_type` varchar(255) NOT NULL DEFAULT '' COMMENT 'git | svn' AFTER `name`;
ADD COLUMN `repo_type` varchar(255) NOT NULL DEFAULT '' COMMENT 'git | svn' AFTER `name`
ADD COLUMN `symlink_backup_number` tinyint UNSIGNED NOT NULL DEFAULT 0 COMMENT 'symlink backup number' AFTER `symlink_path`;
UPDATE `goploy`.`project` SET `repo_type` = 'git';
UPDATE `goploy`.`project` SET `repo_type` = 'git', `symlink_backup_number` = 10;

View File

@ -17,9 +17,11 @@ CREATE TABLE IF NOT EXISTS `project` (
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`namespace_id` int(10) UNSIGNED NOT NULL DEFAULT 0,
`name` varchar(255) NOT NULL DEFAULT '' COMMENT 'project name',
`repo_type` varchar(255) NOT NULL DEFAULT '' COMMENT 'repository type (git | svn)',
`url` varchar(255) NOT NULL DEFAULT '' COMMENT 'repository url',
`path` varchar(255) NOT NULL DEFAULT '' COMMENT 'project deploy path',
`symlink_path` varchar(255) NOT NULL DEFAULT '' COMMENT '(ln -sfn symlink_path/uuid project_path)',
`symlink_backup_number` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT '软链备份数量',
`environment` tinyint(4) UNSIGNED NOT NULL DEFAULT 0 COMMENT '1.production 2.pre-release 3.test 4.development',
`branch` varchar(255) NOT NULL DEFAULT 'master' COMMENT 'repository branch',
`review` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '0.disable 1.enable',

View File

@ -575,7 +575,7 @@ func removeExpiredBackup(project model.Project, projectServer model.ProjectServe
var sshOutbuf, sshErrbuf bytes.Buffer
session.Stdout = &sshOutbuf
session.Stderr = &sshErrbuf
if err = session.Run("cd " + project.SymlinkPath + ";ls -t | awk 'NR>10' | xargs rm -rf"); err != nil {
if err = session.Run("cd " + project.SymlinkPath + ";ls -t | awk 'NR>" + strconv.Itoa(int(project.SymlinkBackupNumber)) + "' | xargs rm -rf"); err != nil {
core.Log(core.ERROR, err.Error())
}
}

View File

@ -186,7 +186,7 @@
"publishReview": "Review",
"reviewFooterTips": "Only members deploy projects will trigger review\n1. Go to the Deploy page for review\n2. Push to URL:http(s)://domain?custom-param=1&callback=***\n3. Access the callback value\nRepeated access callback will only be published once",
"symlinkLabel": "Symlink deploy",
"symlinkHeaderTips": "The project synchronize to the specified directory(rsync /symlinkPath), and ln -s projectPath symlinkPath\nIt can prevent the project from external access that are being synchronized during the process of synchronizing files\nBack up the latest 10 deployment files for quick rollback\n",
"symlinkHeaderTips": "The project synchronize to the specified directory(rsync /symlinkPath), and ln -s projectPath symlinkPath\nIt can prevent the project from external access that are being synchronized during the process of synchronizing files\n",
"symlinkFooterTips": "If the deployment path already exists on the target server, please delete the directory manually(rm -rf projectPath), otherwise the symlink will fail\n",
"afterPullScriptLabel": "After pull script",
"afterPullScriptTips": "The script that runs on the host server after pull\nFor example: bash after-pull-script.sh",

View File

@ -181,7 +181,7 @@
"publishReview": "发布审核",
"reviewFooterTips": "只有成员构建项目才会触发审核\n审核方式\n1. 前往构建发布页面进行审核\n2. 推送到URL:http(s)://domain?custom-param=1&callback=***\n3. http get callback的值即可完成审核\n重复访问callback只会发布一次并且发布过不会再次发布",
"symlinkLabel": "软链部署(推荐)",
"symlinkHeaderTips": "项目先同步到指定目录(rsync 软链目录)然后ln -s 部署路径 软链目录\n可以避免项目在同步传输文件的过程中外部访问到部分正在同步的文件\n备份最近10次的部署文件以便快速回滚\n",
"symlinkHeaderTips": "项目先同步到指定目录(rsync 软链目录)然后ln -s 部署路径 软链目录\n可以避免项目在同步传输文件的过程中外部访问到部分正在同步的文件\n",
"symlinkFooterTips": "如果部署路径已存在在目标服务器请手动删除该目录rm -rf 部署路径,否则软链将会不成功\n",
"afterPullScriptLabel": "拉取后运行脚本",
"afterPullScriptTips": "拉取代码后在宿主服务器运行的脚本\n运行方式打包成一份脚本文件\n检查服务器是否安装该脚本类型(默认以bash运行)",

View File

@ -390,7 +390,7 @@
<el-row style="margin: 0 10px 18px; white-space: pre-line">
{{ $t('projectPage.symlinkHeaderTips') }}
</el-row>
<el-form-item label="Symlink" label-width="80px">
<el-form-item label="Symlink" label-width="120px">
<el-radio-group
v-model="formProps.symlink"
@change="handleSymlink"
@ -403,9 +403,19 @@
</el-form-item>
<el-form-item
v-show="formProps.symlink"
:label="$t('directory')"
label="Backup number"
label-width="120px"
>
<el-input-number
v-model="formData.symlinkBackupNumber"
:min="1"
/>
</el-form-item>
<el-form-item
v-show="formProps.symlink"
label="Directory"
prop="symlink_path"
label-width="80px"
label-width="120px"
>
<el-input v-model="formData.symlinkPath" readonly disabled>
<template #append>/uuid-version</template>
@ -727,6 +737,7 @@ export default defineComponent({
url: '',
path: '',
symlinkPath: '',
symlinkBackupNumber: 10,
afterPullScriptMode: '',
afterPullScript: '',
afterDeployScriptMode: '',