diff --git a/backend/app/repo/app_install.go b/backend/app/repo/app_install.go index e863eebd7..85ecd2e23 100644 --- a/backend/app/repo/app_install.go +++ b/backend/app/repo/app_install.go @@ -19,6 +19,7 @@ type IAppInstallRepo interface { WithAppIdsIn(appIds []uint) DBOption WithStatus(status string) DBOption WithServiceName(serviceName string) DBOption + WithContainerName(containerName string) DBOption WithPort(port int) DBOption WithIdNotInWebsite() DBOption ListBy(opts ...DBOption) ([]model.AppInstall, error) @@ -73,6 +74,12 @@ func (a *AppInstallRepo) WithServiceName(serviceName string) DBOption { } } +func (a *AppInstallRepo) WithContainerName(containerName string) DBOption { + return func(db *gorm.DB) *gorm.DB { + return db.Where("container_name = ?", containerName) + } +} + func (a *AppInstallRepo) WithPort(port int) DBOption { return func(db *gorm.DB) *gorm.DB { return db.Where("https_port = ? or http_port = ?", port, port) diff --git a/backend/app/service/app.go b/backend/app/service/app.go index 9aff52eb7..a7cdba379 100644 --- a/backend/app/service/app.go +++ b/backend/app/service/app.go @@ -290,6 +290,11 @@ func (a AppService) Install(ctx context.Context, req request.AppInstallCreate) ( containerName := constant.ContainerPrefix + app.Key + "-" + common.RandStr(4) if req.Advanced && req.ContainerName != "" { containerName = req.ContainerName + appInstalls, _ := appInstallRepo.ListBy(appInstallRepo.WithContainerName(containerName)) + if len(appInstalls) > 0 { + err = buserr.New(constant.ErrContainerName) + return + } } req.Params[constant.ContainerName] = containerName appInstall.ContainerName = containerName diff --git a/backend/app/service/cornjob.go b/backend/app/service/cornjob.go index 2b6bde169..bdec47962 100644 --- a/backend/app/service/cornjob.go +++ b/backend/app/service/cornjob.go @@ -190,7 +190,6 @@ func (u *CronjobService) StartJob(cronjob *model.Cronjob) (int, error) { if err != nil { return 0, err } - global.LOG.Debug(global.Cron.Entries()) return entryID, nil } diff --git a/backend/constant/errs.go b/backend/constant/errs.go index 35a37c5eb..aeae8ae78 100644 --- a/backend/constant/errs.go +++ b/backend/constant/errs.go @@ -58,6 +58,7 @@ var ( ErrCmdTimeout = "ErrCmdTimeout" ErrFileParse = "ErrFileParse" ErrInstallDirNotFound = "ErrInstallDirNotFound" + ErrContainerName = "ErrContainerName" ) // website diff --git a/backend/i18n/lang/en.yaml b/backend/i18n/lang/en.yaml index 0635281a6..c22011bf1 100644 --- a/backend/i18n/lang/en.yaml +++ b/backend/i18n/lang/en.yaml @@ -37,6 +37,7 @@ ErrFileNotFound: '{{.name}} file does not exist' ErrFileParseApp: 'Failed to parse {{.name}} file {{.err}}' ErrAppDirNull: 'version folder does not exist' LocalAppErr: "App {{.name}} sync failed! {{.err}}" +ErrContainerName: "ContainerName is already exist" #file ErrFileCanNotRead: "File can not read" diff --git a/backend/i18n/lang/zh.yaml b/backend/i18n/lang/zh.yaml index 7c91af7ed..d22cd8370 100644 --- a/backend/i18n/lang/zh.yaml +++ b/backend/i18n/lang/zh.yaml @@ -37,6 +37,7 @@ ErrFileNotFound: '{{.name}} 文件不存在' ErrFileParseApp: '{{.name}} 文件解析失败 {{.err}}' ErrAppDirNull: '版本文件夹不存在' LocalAppErr: "应用 {{.name}} 同步失败!{{.err}}" +ErrContainerName: "容器名称已存在" #file ErrFileCanNotRead: "此文件不支持预览"