Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/app/dto/request/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion backend/app/service/app_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
11 changes: 6 additions & 5 deletions backend/app/service/app_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions backend/i18n/lang/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions backend/i18n/lang/zh-Hant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ ErrNoSuchHost: "網路連接失敗"
ErrImagePullTimeOut: "鏡像拉取超時"
ErrContainerNotFound: '{{ .name }} 容器不存在'
ErrContainerMsg: '{{ .name }} 容器異常,具體請在容器頁面查看日誌'
ErrAppBackup: '{{ .name }} 應用備份失敗 err {{.err}}'

#file
ErrFileCanNotRead: "此文件不支持預覽"
Expand Down
1 change: 1 addition & 0 deletions backend/i18n/lang/zh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ ErrNoSuchHost: "网络连接失败"
ErrImagePullTimeOut: '镜像拉取超时'
ErrContainerNotFound: '{{ .name }} 容器不存在'
ErrContainerMsg: '{{ .name }} 容器异常,具体请在容器页面查看日志'
ErrAppBackup: '{{ .name }} 应用备份失败 err {{.err}}'

#file
ErrFileCanNotRead: "此文件不支持预览"
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lang/modules/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,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',
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lang/modules/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,8 @@ const message = {
cancelIgnore: '取消忽略',
ignoreList: '忽略列表',
appHelper: '部分應用的安裝使用說明請在應用詳情頁查看',
backupApp: '升級前備份應用',
backupAppHelper: '升級失敗可以使用應用備份回滾',
},
website: {
website: '網站',
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lang/modules/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,8 @@ const message = {
cancelIgnore: '取消忽略',
ignoreList: '忽略列表',
appHelper: '部分应用的安装使用说明请在应用详情页查看',
backupApp: '升级前备份应用',
backupAppHelper: '升级失败可以使用应用备份回滚',
},
website: {
website: '网站',
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/views/app-store/installed/upgrade/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -59,6 +63,7 @@ const operateReq = reactive({
detailId: 0,
operate: 'upgrade',
installId: 0,
backup: true,
});
const resourceName = ref('');
const rules = ref<any>({
Expand Down