1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-03-13 17:24:44 +08:00

feat: 升级应用增加备份选项 (#1750)

Refs https://github.com/1Panel-dev/1Panel/issues/1742
This commit is contained in:
zhengkunwang 2023-07-25 17:22:20 +08:00 committed by GitHub
parent 3b9f92e03f
commit b05e5736a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 22 additions and 6 deletions

View File

@ -58,6 +58,7 @@ type AppInstalledOperate struct {
ForceDelete bool `json:"forceDelete"`
DeleteBackup bool `json:"deleteBackup"`
DeleteDB bool `json:"deleteDB"`
Backup bool `json:"backup"`
}
type AppInstalledUpdate struct {

View File

@ -236,7 +236,7 @@ func (a *AppInstallService) Operate(req request.AppInstalledOperate) error {
case constant.Sync:
return syncById(install.ID)
case constant.Upgrade:
return upgradeInstall(install.ID, req.DetailId)
return upgradeInstall(install.ID, req.DetailId, req.Backup)
default:
return errors.New("operate not support")
}

View File

@ -227,7 +227,7 @@ func deleteLink(ctx context.Context, install *model.AppInstall, deleteDB bool, f
return appInstallResourceRepo.DeleteBy(ctx, appInstallResourceRepo.WithAppInstallId(install.ID))
}
func upgradeInstall(installId uint, detailId uint) error {
func upgradeInstall(installId uint, detailId uint, backup bool) error {
install, err := appInstallRepo.GetFirst(commonRepo.WithByID(installId))
if err != nil {
return err
@ -239,13 +239,14 @@ func upgradeInstall(installId uint, detailId uint) error {
if install.Version == detail.Version {
return errors.New("two version is same")
}
if err := NewIBackupService().AppBackup(dto.CommonBackup{Name: install.App.Key, DetailName: install.Name}); err != nil {
return err
}
install.Status = constant.Upgrading
go func() {
if backup {
if err = NewIBackupService().AppBackup(dto.CommonBackup{Name: install.App.Key, DetailName: install.Name}); err != nil {
global.LOG.Errorf(i18n.GetMsgWithMap("ErrAppBackup", map[string]interface{}{"name": install.Name, "err": err.Error()}))
}
}
var upErr error
defer func() {
if upErr != nil {

View File

@ -44,6 +44,7 @@ ErrNoSuchHost: "Network connection failed"
ErrImagePullTimeOut: 'Image pull timeout'
ErrContainerNotFound: '{{ .name }} container does not exist'
ErrContainerMsg: '{{ .name }} container is abnormal, please check the log on the container page for details'
ErrAppBackup: '{{ .name }} application backup failed err {{.err}}'
#file
ErrFileCanNotRead: "File can not read"

View File

@ -44,6 +44,7 @@ ErrNoSuchHost: "網路連接失敗"
ErrImagePullTimeOut: "鏡像拉取超時"
ErrContainerNotFound: '{{ .name }} 容器不存在'
ErrContainerMsg: '{{ .name }} 容器異常,具體請在容器頁面查看日誌'
ErrAppBackup: '{{ .name }} 應用備份失敗 err {{.err}}'
#file
ErrFileCanNotRead: "此文件不支持預覽"

View File

@ -44,6 +44,7 @@ ErrNoSuchHost: "网络连接失败"
ErrImagePullTimeOut: '镜像拉取超时'
ErrContainerNotFound: '{{ .name }} 容器不存在'
ErrContainerMsg: '{{ .name }} 容器异常,具体请在容器页面查看日志'
ErrAppBackup: '{{ .name }} 应用备份失败 err {{.err}}'
#file
ErrFileCanNotRead: "此文件不支持预览"

View File

@ -1221,6 +1221,8 @@ const message = {
cancelIgnore: 'Cancel ignore',
ignoreList: 'ignore list',
appHelper: 'Please view the installation instructions of some applications on the application details page',
backupApp: 'Backup application before upgrade',
backupAppHelper: 'If the upgrade fails, you can use the application backup to roll back',
},
website: {
website: 'Website',

View File

@ -1166,6 +1166,8 @@ const message = {
cancelIgnore: '取消忽略',
ignoreList: '忽略列表',
appHelper: '部分應用的安裝使用說明請在應用詳情頁查看',
backupApp: '升級前備份應用',
backupAppHelper: '升級失敗可以使用應用備份回滾',
},
website: {
website: '網站',

View File

@ -1166,6 +1166,8 @@ const message = {
cancelIgnore: '取消忽略',
ignoreList: '忽略列表',
appHelper: '部分应用的安装使用说明请在应用详情页查看',
backupApp: '升级前备份应用',
backupAppHelper: '升级失败可以使用应用备份回滚',
},
website: {
website: '网站',

View File

@ -27,6 +27,10 @@
></el-option>
</el-select>
</el-form-item>
<el-form-item prop="backup" v-if="operateReq.operate === 'upgrade'">
<el-checkbox v-model="operateReq.backup" :label="$t('app.backupApp')" />
<span class="input-help">{{ $t('app.backupAppHelper') }}</span>
</el-form-item>
</el-form>
</el-col>
</el-row>
@ -59,6 +63,7 @@ const operateReq = reactive({
detailId: 0,
operate: 'upgrade',
installId: 0,
backup: true,
});
const resourceName = ref('');
const rules = ref<any>({