mirror of https://github.com/1Panel-dev/1Panel
feat: 创建应用容器名称增加校验 (#1204)
parent
0fa11213bb
commit
763f450f43
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ var (
|
|||
ErrCmdTimeout = "ErrCmdTimeout"
|
||||
ErrFileParse = "ErrFileParse"
|
||||
ErrInstallDirNotFound = "ErrInstallDirNotFound"
|
||||
ErrContainerName = "ErrContainerName"
|
||||
)
|
||||
|
||||
// website
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -37,6 +37,7 @@ ErrFileNotFound: '{{.name}} 文件不存在'
|
|||
ErrFileParseApp: '{{.name}} 文件解析失败 {{.err}}'
|
||||
ErrAppDirNull: '版本文件夹不存在'
|
||||
LocalAppErr: "应用 {{.name}} 同步失败!{{.err}}"
|
||||
ErrContainerName: "容器名称已存在"
|
||||
|
||||
#file
|
||||
ErrFileCanNotRead: "此文件不支持预览"
|
||||
|
|
Loading…
Reference in New Issue