You've already forked CasaOS
mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-07-12 23:50:14 +02:00
✨ New Feature
- [Apps] This is a feature that has been highly requested by the community. Import the original Docker application into CasaOS. Now it's easy to import with just a few clicks! - [Apps] App list supports a custom sorting function! You can arrange apps in different orders by dragging the icons. - [Apps] App custom installation supports Docker Compose configuration import in YAML format. - [Files] Added thumbnail preview function for image files. - [Connect] Multiple CasaConenct devices in the LAN will be transmitted through the LAN network. - [System] Added a switch for auto-mounting USB disk devices. 🎈 Enhancement - [System] Optimized the system update alert, you will see the new version update log from the next version. - [Apps] Added live preview for icons in custom installed apps. - [Apps] Optimized the input of WebUI. - [Files] Completely updated the image preview, now it supports switching all images in the same folder, as well as dragging, zooming, rotating and resetting. - [Widgets] Added color levels for CPU and RAM charts. - [Conenct] Optimized the display of the right-click menu of the Connect friends list. 🎈 Changed - [Files] Change the initial display directory to /DATA 🐞 Fixed - [System] Fixed an issue with Raspberry Pi devices failing to boot using USB disks. (Achieved by disabling USB disk auto-mount) - [Apps] Fixed the issue that some Docker CLI commands failed to import. - [Apps] Fixed the issue that the app is not easily recognized in /DATA/AppData directory and docker command line after installation, it will be shown as the app name. (Newly installed apps only) - [Apps] Fixed the issue that Pi-hole cannot be launched after installation in the app store. - [Apps] Fixed the issue that apps cannot be updated with WatchTower. - [Files] Fixed the issue that when there is an upload task, the task status is lost after closing Files.
This commit is contained in:
161
service/app.go
161
service/app.go
@ -21,15 +21,17 @@ import (
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
client2 "github.com/docker/docker/client"
|
||||
"github.com/pkg/errors"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type AppService interface {
|
||||
CreateApplication(m model2.ApplicationModel)
|
||||
CreateApplication(m model2.ApplicationModel) model2.ApplicationModel
|
||||
GetApplicationList() (m []model2.ApplicationModel)
|
||||
GetApplicationById(id string) (m model2.ApplicationModel)
|
||||
UpdateApplicationIndexById(id string, index int)
|
||||
UpdateApplicationOrderById(id string, order int)
|
||||
GetMyList(index, size int, position bool) (*[]model2.MyAppList, *[]model2.MyAppList)
|
||||
GetCasaOSCount() int
|
||||
SaveContainer(m model2.AppListDBModel)
|
||||
GetUninstallInfo(id string) model2.AppListDBModel
|
||||
DeleteApp(id string)
|
||||
@ -38,7 +40,7 @@ type AppService interface {
|
||||
UpdateApp(m model2.AppListDBModel)
|
||||
GetSimpleContainerInfo(name string) (types.Container, error)
|
||||
DelAppConfigDir(path string)
|
||||
GetSystemAppList() *[]model2.MyAppList
|
||||
GetSystemAppList() []types.Container
|
||||
GetHardwareUsageSteam()
|
||||
GetHardwareUsage() []model.DockerStatsModel
|
||||
GetAppStats(id string) string
|
||||
@ -57,12 +59,13 @@ func (a *appStruct) GetApplicationById(id string) (m model2.ApplicationModel) {
|
||||
return
|
||||
}
|
||||
|
||||
func (a *appStruct) UpdateApplicationIndexById(id string, index int) {
|
||||
a.db.Model(&model2.ApplicationModel{}).Where("id = ?", id).Update("index", index)
|
||||
func (a *appStruct) UpdateApplicationOrderById(id string, order int) {
|
||||
a.db.Model(&model2.ApplicationModel{}).Where("id = ?", id).Update("order", order)
|
||||
}
|
||||
|
||||
func (a *appStruct) CreateApplication(m model2.ApplicationModel) {
|
||||
func (a *appStruct) CreateApplication(m model2.ApplicationModel) model2.ApplicationModel {
|
||||
a.db.Create(&m)
|
||||
return m
|
||||
}
|
||||
func (a *appStruct) GetApplicationList() (m []model2.ApplicationModel) {
|
||||
a.db.Find(&m)
|
||||
@ -99,6 +102,8 @@ func (a *appStruct) ImportApplications(casaApp bool) {
|
||||
info.Config.Labels["web"] = app.PortMap
|
||||
info.Config.Labels["icon"] = app.Icon
|
||||
info.Config.Labels["desc"] = app.Description
|
||||
info.Config.Labels["index"] = app.Index
|
||||
info.Config.Labels["custom_id"] = app.CustomId
|
||||
info.Name = app.Title
|
||||
container_id, err := MyService.Docker().DockerContainerCopyCreate(info)
|
||||
if err != nil {
|
||||
@ -122,6 +127,8 @@ func (a *appStruct) ImportApplications(casaApp bool) {
|
||||
info.Config.Labels["web"] = ""
|
||||
info.Config.Labels["icon"] = ""
|
||||
info.Config.Labels["desc"] = ""
|
||||
info.Config.Labels["index"] = ""
|
||||
info.Config.Labels["custom_id"] = uuid.NewV4().String()
|
||||
|
||||
_, err = MyService.Docker().DockerContainerCopyCreate(info)
|
||||
if err != nil {
|
||||
@ -131,6 +138,46 @@ func (a *appStruct) ImportApplications(casaApp bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// allcontainer := MyService.Docker().DockerContainerList()
|
||||
// for _, app := range allcontainer {
|
||||
// info, err := MyService.Docker().DockerContainerInfo(app.ID)
|
||||
// if err != nil {
|
||||
// continue
|
||||
// }
|
||||
// MyService.Docker().DockerContainerStop(app.ID)
|
||||
// MyService.Docker().DockerContainerRemove(app.ID, false)
|
||||
// //info.NetworkSettings
|
||||
// info.Config.Labels["custom_id"] = uuid.NewV4().String()
|
||||
// container_id, err := MyService.Docker().DockerContainerCopyCreate(info)
|
||||
// if err != nil {
|
||||
// fmt.Println(err)
|
||||
// continue
|
||||
// }
|
||||
// MyService.Docker().DockerContainerStart(container_id)
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
func (a *appStruct) GetCasaOSCount() int {
|
||||
//获取docker应用
|
||||
cli, err := client2.NewClientWithOpts(client2.FromEnv, client2.WithTimeout(time.Second*5))
|
||||
if err != nil {
|
||||
a.log.Error("初始化client失败", "app.getmylist", "line:36", err)
|
||||
return 0
|
||||
}
|
||||
defer cli.Close()
|
||||
fts := filters.NewArgs()
|
||||
fts.Add("label", "casaos=casaos")
|
||||
//fts.Add("label", "casaos:casaos")
|
||||
|
||||
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{Filters: fts, Limit: 200})
|
||||
if err != nil {
|
||||
a.log.Error("获取docker容器失败", "app.getmylist", "line:42", err)
|
||||
return 0
|
||||
}
|
||||
|
||||
systemApp := MyService.App().GetApplicationList()
|
||||
return len(containers) + len(systemApp)
|
||||
}
|
||||
|
||||
//获取我的应用列表
|
||||
@ -154,51 +201,59 @@ func (a *appStruct) GetMyList(index, size int, position bool) (*[]model2.MyAppLi
|
||||
unTranslation := []model2.MyAppList{}
|
||||
|
||||
list := []model2.MyAppList{}
|
||||
for _, m := range containers {
|
||||
_, newVersion := NewVersionApp[m.ID]
|
||||
|
||||
systemApp := MyService.App().GetApplicationList()
|
||||
for _, v := range systemApp {
|
||||
list = append(list, model2.MyAppList{
|
||||
Name: v.Name,
|
||||
Icon: v.Icon,
|
||||
State: strconv.Itoa(v.State),
|
||||
Id: strconv.Itoa(v.Id),
|
||||
CustomId: strconv.Itoa(v.Id),
|
||||
Port: "",
|
||||
//Order: strconv.Itoa(v.Order),
|
||||
Index: "/",
|
||||
Image: "",
|
||||
Type: v.Type,
|
||||
NewVersion: false,
|
||||
})
|
||||
}
|
||||
|
||||
for _, m := range containers {
|
||||
if m.Labels["casaos"] == "casaos" {
|
||||
if m.Labels["origin"] == "system" {
|
||||
continue
|
||||
}
|
||||
_, newVersion := NewVersionApp[m.ID]
|
||||
list = append(list, model2.MyAppList{
|
||||
Name: m.Names[0],
|
||||
Name: strings.ReplaceAll(m.Names[0], "/", ""),
|
||||
Icon: m.Labels["icon"],
|
||||
State: m.State,
|
||||
CustomId: m.ID,
|
||||
CustomId: m.Labels["custom_id"],
|
||||
Id: m.ID,
|
||||
Port: m.Labels["web"],
|
||||
Index: m.Labels["index"],
|
||||
//UpTime: tm,
|
||||
//Order: m.Labels["order"],
|
||||
Image: m.Image,
|
||||
NewVersion: newVersion,
|
||||
Type: m.Labels["origin"],
|
||||
//Slogan: m.Slogan,
|
||||
//Rely: m.Rely,
|
||||
})
|
||||
} else {
|
||||
unTranslation = append(unTranslation, model2.MyAppList{
|
||||
Name: m.Names[0],
|
||||
Name: strings.ReplaceAll(m.Names[0], "/", ""),
|
||||
Icon: "",
|
||||
State: m.State,
|
||||
CustomId: m.ID,
|
||||
Id: m.ID,
|
||||
Port: "",
|
||||
NewVersion: newVersion,
|
||||
NewVersion: false,
|
||||
Image: m.Image,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
systemApp := MyService.App().GetApplicationList()
|
||||
for _, v := range systemApp {
|
||||
list = append(list, model2.MyAppList{
|
||||
Name: "/" + v.Name,
|
||||
Icon: v.Icon,
|
||||
State: strconv.Itoa(v.State),
|
||||
CustomId: strconv.Itoa(v.Id),
|
||||
Port: "",
|
||||
Index: strconv.Itoa(v.Index),
|
||||
Image: "",
|
||||
Type: v.Type,
|
||||
NewVersion: false,
|
||||
})
|
||||
}
|
||||
|
||||
//lMap := make(map[string]interface{})
|
||||
// for _, dbModel := range lm {
|
||||
// if position {
|
||||
@ -245,7 +300,7 @@ func (a *appStruct) GetMyList(index, size int, position bool) (*[]model2.MyAppLi
|
||||
}
|
||||
|
||||
//system application list
|
||||
func (a *appStruct) GetSystemAppList() *[]model2.MyAppList {
|
||||
func (a *appStruct) GetSystemAppList() []types.Container {
|
||||
//获取docker应用
|
||||
cli, err := client2.NewClientWithOpts(client2.FromEnv)
|
||||
if err != nil {
|
||||
@ -261,46 +316,16 @@ func (a *appStruct) GetSystemAppList() *[]model2.MyAppList {
|
||||
|
||||
//获取本地数据库应用
|
||||
|
||||
var lm []model2.AppListDBModel
|
||||
a.db.Table(model2.CONTAINERTABLENAME).Select("title,icon,port_map,`index`,container_id,position,label,slogan,image,volumes").Find(&lm)
|
||||
// var lm []model2.AppListDBModel
|
||||
// a.db.Table(model2.CONTAINERTABLENAME).Select("title,icon,port_map,`index`,container_id,position,label,slogan,image,volumes").Find(&lm)
|
||||
|
||||
list := []model2.MyAppList{}
|
||||
lMap := make(map[string]interface{})
|
||||
for _, dbModel := range lm {
|
||||
lMap[dbModel.ContainerId] = dbModel
|
||||
}
|
||||
for _, container := range containers {
|
||||
//list := []model2.MyAppList{}
|
||||
//lMap := make(map[string]interface{})
|
||||
// for _, dbModel := range lm {
|
||||
// lMap[dbModel.ContainerId] = dbModel
|
||||
// }
|
||||
|
||||
if lMap[container.ID] != nil {
|
||||
m := lMap[container.ID].(model2.AppListDBModel)
|
||||
if len(m.Label) == 0 {
|
||||
m.Label = m.Title
|
||||
}
|
||||
|
||||
info, err := cli.ContainerInspect(context.Background(), container.ID)
|
||||
var tm string
|
||||
if err != nil {
|
||||
tm = time.Now().String()
|
||||
} else {
|
||||
tm = info.State.StartedAt
|
||||
}
|
||||
list = append(list, model2.MyAppList{
|
||||
Name: m.Label,
|
||||
Icon: m.Icon,
|
||||
State: container.State,
|
||||
CustomId: strings.ReplaceAll(container.Names[0], "/", ""),
|
||||
Port: m.PortMap,
|
||||
Index: m.Index,
|
||||
UpTime: tm,
|
||||
Image: m.Image,
|
||||
Slogan: m.Slogan,
|
||||
//Volumes: m.Volumes,
|
||||
//Rely: m.Rely,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return &list
|
||||
return containers
|
||||
|
||||
}
|
||||
func (a *appStruct) GetAllDBApps() []model2.AppListDBModel {
|
||||
@ -471,7 +496,7 @@ func (a *appStruct) GetHardwareUsageSteam() {
|
||||
}
|
||||
dockerStats.Data = data
|
||||
dockerStats.Icon = v.Labels["icon"]
|
||||
dockerStats.Title = v.Names[0]
|
||||
dockerStats.Title = strings.ReplaceAll(v.Names[0], "/", "")
|
||||
dataStats.Store(v.ID, dockerStats)
|
||||
if i == 99 {
|
||||
stats.Body.Close()
|
||||
|
Reference in New Issue
Block a user