|
|
@ -20,7 +20,6 @@ import (
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/global"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/global"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/utils/common"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/utils/common"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/utils/docker"
|
|
|
|
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/utils/files"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/utils/files"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -34,7 +33,7 @@ type IAppService interface {
|
|
|
|
GetApp(key string) (*response.AppDTO, error)
|
|
|
|
GetApp(key string) (*response.AppDTO, error)
|
|
|
|
GetAppDetail(appId uint, version string) (response.AppDetailDTO, error)
|
|
|
|
GetAppDetail(appId uint, version string) (response.AppDetailDTO, error)
|
|
|
|
Install(ctx context.Context, req request.AppInstallCreate) (*model.AppInstall, error)
|
|
|
|
Install(ctx context.Context, req request.AppInstallCreate) (*model.AppInstall, error)
|
|
|
|
SyncInstalled(installId uint) error
|
|
|
|
//SyncInstalled(installId uint) error
|
|
|
|
SyncAppList() error
|
|
|
|
SyncAppList() error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -259,94 +258,94 @@ func (a AppService) Install(ctx context.Context, req request.AppInstallCreate) (
|
|
|
|
return &appInstall, nil
|
|
|
|
return &appInstall, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (a AppService) SyncInstalled(installId uint) error {
|
|
|
|
//func (a AppService) SyncInstalled(installId uint) error {
|
|
|
|
appInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(installId))
|
|
|
|
// appInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(installId))
|
|
|
|
if err != nil {
|
|
|
|
// if err != nil {
|
|
|
|
return err
|
|
|
|
// return err
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
containerNames, err := getContainerNames(appInstall)
|
|
|
|
// containerNames, err := getContainerNames(appInstall)
|
|
|
|
if err != nil {
|
|
|
|
// if err != nil {
|
|
|
|
return err
|
|
|
|
// return err
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
cli, err := docker.NewClient()
|
|
|
|
// cli, err := docker.NewClient()
|
|
|
|
if err != nil {
|
|
|
|
// if err != nil {
|
|
|
|
return err
|
|
|
|
// return err
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
containers, err := cli.ListContainersByName(containerNames)
|
|
|
|
// containers, err := cli.ListContainersByName(containerNames)
|
|
|
|
if err != nil {
|
|
|
|
// if err != nil {
|
|
|
|
return err
|
|
|
|
// return err
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
var (
|
|
|
|
// var (
|
|
|
|
errorContainers []string
|
|
|
|
// errorContainers []string
|
|
|
|
notFoundContainers []string
|
|
|
|
// notFoundContainers []string
|
|
|
|
runningContainers []string
|
|
|
|
// runningContainers []string
|
|
|
|
)
|
|
|
|
// )
|
|
|
|
|
|
|
|
//
|
|
|
|
for _, n := range containers {
|
|
|
|
// for _, n := range containers {
|
|
|
|
if n.State != "running" {
|
|
|
|
// if n.State != "running" {
|
|
|
|
errorContainers = append(errorContainers, n.Names[0])
|
|
|
|
// errorContainers = append(errorContainers, n.Names[0])
|
|
|
|
} else {
|
|
|
|
// } else {
|
|
|
|
runningContainers = append(runningContainers, n.Names[0])
|
|
|
|
// runningContainers = append(runningContainers, n.Names[0])
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
for _, old := range containerNames {
|
|
|
|
// for _, old := range containerNames {
|
|
|
|
exist := false
|
|
|
|
// exist := false
|
|
|
|
for _, new := range containers {
|
|
|
|
// for _, new := range containers {
|
|
|
|
if common.ExistWithStrArray(old, new.Names) {
|
|
|
|
// if common.ExistWithStrArray(old, new.Names) {
|
|
|
|
exist = true
|
|
|
|
// exist = true
|
|
|
|
break
|
|
|
|
// break
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
if !exist {
|
|
|
|
// if !exist {
|
|
|
|
notFoundContainers = append(notFoundContainers, old)
|
|
|
|
// notFoundContainers = append(notFoundContainers, old)
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
containerCount := len(containers)
|
|
|
|
// containerCount := len(containers)
|
|
|
|
errCount := len(errorContainers)
|
|
|
|
// errCount := len(errorContainers)
|
|
|
|
notFoundCount := len(notFoundContainers)
|
|
|
|
// notFoundCount := len(notFoundContainers)
|
|
|
|
normalCount := len(containerNames)
|
|
|
|
// normalCount := len(containerNames)
|
|
|
|
runningCount := len(runningContainers)
|
|
|
|
// runningCount := len(runningContainers)
|
|
|
|
|
|
|
|
//
|
|
|
|
if containerCount == 0 {
|
|
|
|
// if containerCount == 0 {
|
|
|
|
appInstall.Status = constant.Error
|
|
|
|
// appInstall.Status = constant.ContainerNotFound
|
|
|
|
appInstall.Message = "container is not found"
|
|
|
|
// appInstall.Message = "container is not found"
|
|
|
|
return appInstallRepo.Save(&appInstall)
|
|
|
|
// return appInstallRepo.Save(&appInstall)
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
if errCount == 0 && notFoundCount == 0 {
|
|
|
|
// if errCount == 0 && notFoundCount == 0 {
|
|
|
|
appInstall.Status = constant.Running
|
|
|
|
// appInstall.Status = constant.Running
|
|
|
|
return appInstallRepo.Save(&appInstall)
|
|
|
|
// return appInstallRepo.Save(&appInstall)
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
if errCount == normalCount {
|
|
|
|
// if errCount == normalCount {
|
|
|
|
appInstall.Status = constant.Error
|
|
|
|
// appInstall.Status = constant.Error
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
if notFoundCount == normalCount {
|
|
|
|
// if notFoundCount == normalCount {
|
|
|
|
appInstall.Status = constant.Stopped
|
|
|
|
// appInstall.Status = constant.Stopped
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
if runningCount < normalCount {
|
|
|
|
// if runningCount < normalCount {
|
|
|
|
appInstall.Status = constant.UnHealthy
|
|
|
|
// appInstall.Status = constant.UnHealthy
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
var errMsg strings.Builder
|
|
|
|
// var errMsg strings.Builder
|
|
|
|
if errCount > 0 {
|
|
|
|
// if errCount > 0 {
|
|
|
|
errMsg.Write([]byte(string(rune(errCount)) + " error containers:"))
|
|
|
|
// errMsg.Write([]byte(string(rune(errCount)) + " error containers:"))
|
|
|
|
for _, e := range errorContainers {
|
|
|
|
// for _, e := range errorContainers {
|
|
|
|
errMsg.Write([]byte(e))
|
|
|
|
// errMsg.Write([]byte(e))
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
errMsg.Write([]byte("\n"))
|
|
|
|
// errMsg.Write([]byte("\n"))
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
if notFoundCount > 0 {
|
|
|
|
// if notFoundCount > 0 {
|
|
|
|
errMsg.Write([]byte(string(rune(notFoundCount)) + " not found containers:"))
|
|
|
|
// errMsg.Write([]byte(string(rune(notFoundCount)) + " not found containers:"))
|
|
|
|
for _, e := range notFoundContainers {
|
|
|
|
// for _, e := range notFoundContainers {
|
|
|
|
errMsg.Write([]byte(e))
|
|
|
|
// errMsg.Write([]byte(e))
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
errMsg.Write([]byte("\n"))
|
|
|
|
// errMsg.Write([]byte("\n"))
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
appInstall.Message = errMsg.String()
|
|
|
|
// appInstall.Message = errMsg.String()
|
|
|
|
return appInstallRepo.Save(&appInstall)
|
|
|
|
// return appInstallRepo.Save(&appInstall)
|
|
|
|
}
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
func (a AppService) GetAppUpdate() (*response.AppUpdateRes, error) {
|
|
|
|
func (a AppService) GetAppUpdate() (*response.AppUpdateRes, error) {
|
|
|
|
res := &response.AppUpdateRes{
|
|
|
|
res := &response.AppUpdateRes{
|
|
|
|