New App Store

Add App Store for installation
Fix favicon display in dark mode
This commit is contained in:
link 2021-11-03 17:07:46 +08:00
parent cad7af13af
commit a5fee0ee97
18 changed files with 224 additions and 147 deletions

2
UI

@ -1 +1 @@
Subproject commit fff9cdeb483d4d01d106641eb1a1c266fd7aa19b Subproject commit 4fe7dc775653c7b853cf3b98857b23225d6e1f22

View File

@ -15,12 +15,14 @@ type ServerAppList struct {
Icon string `json:"icon"` Icon string `json:"icon"`
ScreenshotLink Strings `gorm:"type:json" json:"screenshot_link"` ScreenshotLink Strings `gorm:"type:json" json:"screenshot_link"`
Category string `json:"category"` Category string `json:"category"`
TcpPort uint `json:"tcp_port"` PortMap string `json:"port_map"`
PortMap uint `json:"port_map"`
ImageVersion string `json:"image_version"` ImageVersion string `json:"image_version"`
Tip string `json:"tip"` Tip string `json:"tip"`
Configures configures `gorm:"type:json" json:"configures"` Envs EnvArray `json:"envs"`
NetworkModel string `json:"network_mode"` Ports PortArray `json:"ports"`
Volumes PathArray `json:"volumes"`
Devices PathArray `json:"devices"`
NetworkModel string `json:"network_model"`
Image string `json:"image"` Image string `json:"image"`
Index string `json:"index"` Index string `json:"index"`
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
@ -33,6 +35,7 @@ type ServerAppList struct {
Thumbnail string `json:"thumbnail"` Thumbnail string `json:"thumbnail"`
Healthy string `json:"healthy"` Healthy string `json:"healthy"`
Plugins Strings `json:"plugins"` Plugins Strings `json:"plugins"`
Origin string `json:"origin"`
} }
type Ports struct { type Ports struct {

View File

@ -17,20 +17,22 @@ type UdpPorts struct {
/*******************使用gorm支持json************************************/ /*******************使用gorm支持json************************************/
type PortMap struct { type PortMap struct {
ContainerPort string `json:"container,omitempty"` ContainerPort string `json:"container"`
CommendPort string `json:"host,omitempty"` CommendPort string `json:"host"`
Protocol string `json:"protocol"` Protocol string `json:"protocol"`
Desc string `json:"desc"`
Type int `json:"type"`
} }
type PortArrey []PortMap type PortArray []PortMap
// Value 实现方法 // Value 实现方法
func (p PortArrey) Value() (driver.Value, error) { func (p PortArray) Value() (driver.Value, error) {
return json.Marshal(p) return json.Marshal(p)
} }
// Scan 实现方法 // Scan 实现方法
func (p *PortArrey) Scan(input interface{}) error { func (p *PortArray) Scan(input interface{}) error {
return json.Unmarshal(input.([]byte), p) return json.Unmarshal(input.([]byte), p)
} }
@ -41,20 +43,22 @@ func (p *PortArrey) Scan(input interface{}) error {
type Env struct { type Env struct {
Name string `json:"container"` Name string `json:"container"`
Value string `json:"host"` Value string `json:"host"`
Desc string `json:"desc"`
Type int `json:"type"`
} }
type JSON json.RawMessage type JSON json.RawMessage
type EnvArrey []Env type EnvArray []Env
// Value 实现方法 // Value 实现方法
func (p EnvArrey) Value() (driver.Value, error) { func (p EnvArray) Value() (driver.Value, error) {
return json.Marshal(p) return json.Marshal(p)
//return .MarshalJSON() //return .MarshalJSON()
} }
// Scan 实现方法 // Scan 实现方法
func (p *EnvArrey) Scan(input interface{}) error { func (p *EnvArray) Scan(input interface{}) error {
return json.Unmarshal(input.([]byte), p) return json.Unmarshal(input.([]byte), p)
} }
@ -65,17 +69,19 @@ func (p *EnvArrey) Scan(input interface{}) error {
type PathMap struct { type PathMap struct {
ContainerPath string `json:"container"` ContainerPath string `json:"container"`
Path string `json:"host"` Path string `json:"host"`
Type int `json:"type"`
Desc string `json:"desc"`
} }
type PathArrey []PathMap type PathArray []PathMap
// Value 实现方法 // Value 实现方法
func (p PathArrey) Value() (driver.Value, error) { func (p PathArray) Value() (driver.Value, error) {
return json.Marshal(p) return json.Marshal(p)
} }
// Scan 实现方法 // Scan 实现方法
func (p *PathArrey) Scan(input interface{}) error { func (p *PathArray) Scan(input interface{}) error {
return json.Unmarshal(input.([]byte), p) return json.Unmarshal(input.([]byte), p)
} }
@ -103,10 +109,10 @@ type CustomizationPostData struct {
Index string `json:"index"` Index string `json:"index"`
Icon string `json:"icon"` Icon string `json:"icon"`
Image string `json:"image"` Image string `json:"image"`
Envs EnvArrey `json:"envs"` Envs EnvArray `json:"envs"`
Ports PortArrey `json:"ports"` Ports PortArray `json:"ports"`
Volumes PathArrey `json:"volumes"` Volumes PathArray `json:"volumes"`
Devices PathArrey `json:"devices"` Devices PathArray `json:"devices"`
//Port string `json:"port,omitempty"` //Port string `json:"port,omitempty"`
PortMap string `json:"port_map"` PortMap string `json:"port_map"`
CpuShares int64 `json:"cpu_shares"` CpuShares int64 `json:"cpu_shares"`

View File

@ -1,10 +1,25 @@
package docker package docker
import "strings"
func GetDir(id, envName string) string { func GetDir(id, envName string) string {
var path string var path string
switch envName {
case "/config": if len(id) == 0 {
path = "/oasis/app_data/" + id + "/" id = "$AppID"
}
switch {
case strings.Contains(strings.ToLower(envName), "config"):
path = "/DATA/AppData/" + id + "/"
case strings.Contains(strings.ToLower(envName), "movie"):
path = "/DATA/Media/Movies/"
case strings.Contains(strings.ToLower(envName), "music"):
path = "/DATA/Media/Music/"
case strings.Contains(strings.ToLower(envName), "download"):
path = "/DATA/Downloads/"
case strings.Contains(strings.ToLower(envName), "photo") || strings.Contains(strings.ToLower(envName), "pictures"):
path = "/DATA/Downloads/"
default: default:
//path = "/media" //path = "/media"
} }

View File

@ -0,0 +1,10 @@
package docker
import (
"fmt"
"testing"
)
func TestGetDir(t *testing.T) {
fmt.Println(GetDir("", "config"))
}

View File

@ -0,0 +1,19 @@
package env_helper
import "strings"
func ReplaceDefaultENV(key string) string {
temp := ""
switch key {
case "$DefaultPassword":
temp = "casaos"
case "$DefaultUserName":
temp = "admin"
}
return temp
}
//replace env default setting
func ReplaceStringDefaultENV(str string) string {
return strings.ReplaceAll(strings.ReplaceAll(str, "$DefaultPassword", ReplaceDefaultENV("$DefaultPassword")), "$DefaultUserName", ReplaceDefaultENV("$DefaultUserName"))
}

View File

@ -47,6 +47,7 @@ func IsPortAvailable(port int, t string) bool {
uc, err := net.ListenUDP("udp", sadd) uc, err := net.ListenUDP("udp", sadd)
if err != nil { if err != nil {
fmt.Println(err.Error())
return false return false
} else { } else {
defer uc.Close() defer uc.Close()

View File

@ -1,8 +1,9 @@
package sort package sort
import ( import (
"github.com/IceWhaleTech/CasaOS/model"
"sort" "sort"
"github.com/IceWhaleTech/CasaOS/model"
) )
// 数据集类型, 与上一篇排序文章(多字段单独排序)比较, less字段的数据类型不再是 func(p1, p2 *Change) bool // 数据集类型, 与上一篇排序文章(多字段单独排序)比较, less字段的数据类型不再是 func(p1, p2 *Change) bool

View File

@ -1,15 +1,17 @@
package v1 package v1
import ( import (
"net/http"
"strconv"
"github.com/IceWhaleTech/CasaOS/model" "github.com/IceWhaleTech/CasaOS/model"
"github.com/IceWhaleTech/CasaOS/pkg/docker"
"github.com/IceWhaleTech/CasaOS/pkg/utils/env_helper"
"github.com/IceWhaleTech/CasaOS/pkg/utils/file" "github.com/IceWhaleTech/CasaOS/pkg/utils/file"
oasis_err2 "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err" oasis_err2 "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
port2 "github.com/IceWhaleTech/CasaOS/pkg/utils/port" port2 "github.com/IceWhaleTech/CasaOS/pkg/utils/port"
"github.com/IceWhaleTech/CasaOS/pkg/utils/sort"
"github.com/IceWhaleTech/CasaOS/service" "github.com/IceWhaleTech/CasaOS/service"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"net/http"
"strconv"
) )
// @Summary 获取远程列表 // @Summary 获取远程列表
@ -110,51 +112,66 @@ func MyAppList(c *gin.Context) {
func AppInfo(c *gin.Context) { func AppInfo(c *gin.Context) {
id := c.Param("id") id := c.Param("id")
info := service.MyService.App().GetServerAppInfo(id) info := service.MyService.OAPI().GetServerAppInfo(id)
if info.NetworkModel != "host" { if info.NetworkModel != "host" {
port, _ := port2.GetAvailablePort("tcp") for i := 0; i < len(info.Ports); i++ {
info.PortMap = uint(port) if p, _ := strconv.Atoi(info.Ports[i].ContainerPort); port2.IsPortAvailable(p, info.Ports[i].Protocol) {
for i := 0; i < len(info.Configures.TcpPorts); i++ { info.Ports[i].CommendPort = strconv.Itoa(p)
info.Configures.TcpPorts[i].CommendPort, _ = port2.GetAvailablePort("tcp")
}
for i := 0; i < len(info.Configures.UdpPorts); i++ {
info.Configures.UdpPorts[i].CommendPort, _ = port2.GetAvailablePort("udp")
}
} else { } else {
info.PortMap = info.TcpPort if info.Ports[i].Protocol == "tcp" {
if p, err := port2.GetAvailablePort("tcp"); err == nil {
info.Ports[i].CommendPort = strconv.Itoa(p)
}
} else if info.Ports[i].Protocol == "upd" {
if p, err := port2.GetAvailablePort("udp"); err == nil {
info.Ports[i].CommendPort = strconv.Itoa(p)
} }
for i := 0; i < len(info.Configures.Devices); i++ {
if !file.CheckNotExist(info.Configures.Devices[i].ContainerPath) {
info.Configures.Devices[i].Path = info.Configures.Devices[i].ContainerPath
} }
} }
portOrder := func(c1, c2 *model.Ports) bool { if info.Ports[i].Type == 0 {
return c1.Type < c2.Type info.PortMap = info.Ports[i].CommendPort
}
}
} }
envOrder := func(c1, c2 *model.Envs) bool { for i := 0; i < len(info.Devices); i++ {
return c1.Type < c2.Type if !file.CheckNotExist(info.Devices[i].ContainerPath) {
info.Devices[i].Path = info.Devices[i].ContainerPath
}
}
if len(info.Tip) > 0 {
info.Tip = env_helper.ReplaceStringDefaultENV(info.Tip)
} }
volOrder := func(c1, c2 *model.Volume) bool { for i := 0; i < len(info.Volumes); i++ {
return c1.Type < c2.Type info.Volumes[i].Path = docker.GetDir("", info.Volumes[i].ContainerPath)
} }
// portOrder := func(c1, c2 *model.Ports) bool {
// return c1.Type < c2.Type
// }
devOrder := func(c1, c2 *model.Devices) bool { // envOrder := func(c1, c2 *model.Envs) bool {
return c1.Type < c2.Type // return c1.Type < c2.Type
} // }
// volOrder := func(c1, c2 *model.Volume) bool {
// return c1.Type < c2.Type
// }
// devOrder := func(c1, c2 *model.Devices) bool {
// return c1.Type < c2.Type
// }
//sort //sort
if info.NetworkModel != "host" { // if info.NetworkModel != "host" {
sort.PortsSort(portOrder).Sort(info.Configures.TcpPorts) // sort.PortsSort(portOrder).Sort(info.Configures.TcpPorts)
sort.PortsSort(portOrder).Sort(info.Configures.UdpPorts) // sort.PortsSort(portOrder).Sort(info.Configures.UdpPorts)
} // }
sort.EnvSort(envOrder).Sort(info.Configures.Envs) // sort.EnvSort(envOrder).Sort(info.Envs)
sort.VolSort(volOrder).Sort(info.Configures.Volumes) // sort.VolSort(volOrder).Sort(info.Volumes.([]model.PathMap))
sort.DevSort(devOrder).Sort(info.Configures.Devices) // sort.DevSort(devOrder).Sort(info.Devices)
info.MaxMemory = service.MyService.ZiMa().GetMemInfo().Total >> 20 info.MaxMemory = service.MyService.ZiMa().GetMemInfo().Total >> 20

View File

@ -25,6 +25,7 @@ import (
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
"github.com/tidwall/gjson"
"golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh"
) )
@ -172,7 +173,7 @@ func InstallApp(c *gin.Context) {
dockerImageVersion = "latest" dockerImageVersion = "latest"
} }
if m.Origin != "custom" { if m.Origin != "custom" {
appInfo = service.MyService.App().GetServerAppInfo(appId) appInfo = service.MyService.OAPI().GetServerAppInfo(appId)
} else { } else {
@ -239,6 +240,7 @@ func InstallApp(c *gin.Context) {
go func() { go func() {
installLog := model2.AppNotify{} installLog := model2.AppNotify{}
installLog.State = 0 installLog.State = 0
installLog.CustomId = id
installLog.Message = "installing rely" installLog.Message = "installing rely"
installLog.Type = types.NOTIFY_TYPE_UNIMPORTANT installLog.Type = types.NOTIFY_TYPE_UNIMPORTANT
installLog.CreatedAt = strconv.FormatInt(time.Now().Unix(), 10) installLog.CreatedAt = strconv.FormatInt(time.Now().Unix(), 10)
@ -282,7 +284,6 @@ func InstallApp(c *gin.Context) {
} }
} }
} }
} }
installLog.Message = "pulling" installLog.Message = "pulling"
@ -333,6 +334,8 @@ func InstallApp(c *gin.Context) {
service.MyService.Notify().UpdateLog(installLog) service.MyService.Notify().UpdateLog(installLog)
} }
// echo -e "hellow\nworld" >>
//step启动容器 //step启动容器
err = service.MyService.Docker().DockerContainerStart(id) err = service.MyService.Docker().DockerContainerStart(id)
if err != nil { if err != nil {
@ -685,7 +688,11 @@ func UnInstallApp(c *gin.Context) {
if info.Origin != "custom" { if info.Origin != "custom" {
//step: 删除文件夹 //step: 删除文件夹
service.MyService.App().DelAppConfigDir(appId) vol := gjson.Get(info.Volumes, "#.host")
for _, v := range vol.Array() {
service.MyService.App().DelAppConfigDir(appId, v.String())
}
//step: 删除install log //step: 删除install log
service.MyService.Notify().DelLog(appId) service.MyService.Notify().DelLog(appId)
@ -1119,16 +1126,16 @@ func ContainerUpdateInfo(c *gin.Context) {
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS), Data: err.Error()}) c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS), Data: err.Error()})
return return
} }
var port model.PortArrey var port model.PortArray
json2.Unmarshal([]byte(appInfo.Ports), &port) json2.Unmarshal([]byte(appInfo.Ports), &port)
var envs model.EnvArrey var envs model.EnvArray
json2.Unmarshal([]byte(appInfo.Envs), &envs) json2.Unmarshal([]byte(appInfo.Envs), &envs)
var vol model.PathArrey var vol model.PathArray
json2.Unmarshal([]byte(appInfo.Volumes), &vol) json2.Unmarshal([]byte(appInfo.Volumes), &vol)
var dir model.PathArrey var dir model.PathArray
json2.Unmarshal([]byte(appInfo.Devices), &dir) json2.Unmarshal([]byte(appInfo.Devices), &dir)
//volumesStr, _ := json2.Marshal(m.Volumes) //volumesStr, _ := json2.Marshal(m.Volumes)

View File

@ -2,35 +2,31 @@ package service
import ( import (
"context" "context"
json2 "encoding/json" "strings"
"github.com/IceWhaleTech/CasaOS/model" "time"
"github.com/IceWhaleTech/CasaOS/pkg/config" "github.com/IceWhaleTech/CasaOS/pkg/config"
"github.com/IceWhaleTech/CasaOS/pkg/docker" "github.com/IceWhaleTech/CasaOS/pkg/docker"
"github.com/IceWhaleTech/CasaOS/pkg/utils/command" "github.com/IceWhaleTech/CasaOS/pkg/utils/command"
httper2 "github.com/IceWhaleTech/CasaOS/pkg/utils/httper"
loger2 "github.com/IceWhaleTech/CasaOS/pkg/utils/loger" loger2 "github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
model2 "github.com/IceWhaleTech/CasaOS/service/model" model2 "github.com/IceWhaleTech/CasaOS/service/model"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
client2 "github.com/docker/docker/client" client2 "github.com/docker/docker/client"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/tidwall/gjson"
"gorm.io/gorm" "gorm.io/gorm"
"strings"
"time"
) )
type AppService interface { type AppService interface {
GetMyList(index, size int, position bool) *[]model2.MyAppList GetMyList(index, size int, position bool) *[]model2.MyAppList
SaveContainer(m model2.AppListDBModel) SaveContainer(m model2.AppListDBModel)
GetServerAppInfo(id string) model.ServerAppList
GetUninstallInfo(id string) model2.AppListDBModel GetUninstallInfo(id string) model2.AppListDBModel
RemoveContainerById(id string) RemoveContainerById(id string)
GetContainerInfo(name string) (types.Container, error) GetContainerInfo(name string) (types.Container, error)
GetAppDBInfo(id string) model2.AppListDBModel GetAppDBInfo(id string) model2.AppListDBModel
UpdateApp(m model2.AppListDBModel) UpdateApp(m model2.AppListDBModel)
GetSimpleContainerInfo(name string) (types.Container, error) GetSimpleContainerInfo(name string) (types.Container, error)
DelAppConfigDir(id string) DelAppConfigDir(id, path string)
} }
type appStruct struct { type appStruct struct {
@ -155,27 +151,6 @@ func (a *appStruct) GetUninstallInfo(id string) model2.AppListDBModel {
return m return m
} }
func (a *appStruct) GetServerAppInfo(id string) model.ServerAppList {
head := make(map[string]string)
t := make(chan string)
go func() {
str := httper2.Get(config.ServerInfo.ServerApi+"/token", nil)
t <- gjson.Get(str, "data").String()
}()
head["Authorization"] = <-t
infoS := httper2.Get(config.ServerInfo.ServerApi+"/v1/app/info/"+id, head)
info := model.ServerAppList{}
json2.Unmarshal([]byte(gjson.Get(infoS, "data").String()), &info)
return info
}
//创建容器成功后保存容器 //创建容器成功后保存容器
func (a *appStruct) SaveContainer(m model2.AppListDBModel) { func (a *appStruct) SaveContainer(m model2.AppListDBModel) {
a.db.Table(model2.CONTAINERTABLENAME).Create(&m) a.db.Table(model2.CONTAINERTABLENAME).Create(&m)
@ -185,8 +160,8 @@ func (a *appStruct) UpdateApp(m model2.AppListDBModel) {
a.db.Table(model2.CONTAINERTABLENAME).Save(&m) a.db.Table(model2.CONTAINERTABLENAME).Save(&m)
} }
func (a *appStruct) DelAppConfigDir(id string) { func (a *appStruct) DelAppConfigDir(id, path string) {
command.OnlyExec("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;DelAppConfigDir " + docker.GetDir(id, "/config")) command.OnlyExec("source " + config.AppInfo.ProjectPath + "/shell/helper.sh ;DelAppConfigDir " + docker.GetDir(id, path))
} }
func (a *appStruct) RemoveContainerById(id string) { func (a *appStruct) RemoveContainerById(id string) {

View File

@ -11,16 +11,17 @@ import (
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
) )
type OasisService interface { type CasaService interface {
GetServerList(index, size, tp, categoryId, key string) ([]model.ServerAppList, int64) GetServerList(index, size, tp, categoryId, key string) ([]model.ServerAppList, int64)
GetServerCategoryList() []model.ServerCategoryList GetServerCategoryList() []model.ServerCategoryList
GetTaskList(size int) []model2.TaskDBModel GetTaskList(size int) []model2.TaskDBModel
GetServerAppInfo(id string) model.ServerAppList
} }
type oasisService struct { type casaService struct {
} }
func (o *oasisService) GetTaskList(size int) []model2.TaskDBModel { func (o *casaService) GetTaskList(size int) []model2.TaskDBModel {
head := make(map[string]string) head := make(map[string]string)
head["Authorization"] = GetToken() head["Authorization"] = GetToken()
@ -33,7 +34,7 @@ func (o *oasisService) GetTaskList(size int) []model2.TaskDBModel {
return list return list
} }
func (o *oasisService) GetServerList(index, size, tp, categoryId, key string) ([]model.ServerAppList, int64) { func (o *casaService) GetServerList(index, size, tp, categoryId, key string) ([]model.ServerAppList, int64) {
head := make(map[string]string) head := make(map[string]string)
@ -49,7 +50,7 @@ func (o *oasisService) GetServerList(index, size, tp, categoryId, key string) ([
return list, count return list, count
} }
func (o *oasisService) GetServerCategoryList() []model.ServerCategoryList { func (o *casaService) GetServerCategoryList() []model.ServerCategoryList {
head := make(map[string]string) head := make(map[string]string)
head["Authorization"] = GetToken() head["Authorization"] = GetToken()
@ -62,7 +63,19 @@ func (o *oasisService) GetServerCategoryList() []model.ServerCategoryList {
return list return list
} }
func (o *casaService) GetServerAppInfo(id string) model.ServerAppList {
head := make(map[string]string)
head["Authorization"] = GetToken()
infoS := httper2.Get(config.ServerInfo.ServerApi+"/v1/app/info/"+id, head)
info := model.ServerAppList{}
json2.Unmarshal([]byte(gjson.Get(infoS, "data").String()), &info)
return info
}
func GetToken() string { func GetToken() string {
t := make(chan string) t := make(chan string)
keyName := "casa_token" keyName := "casa_token"
@ -86,6 +99,6 @@ func GetToken() string {
return auth return auth
} }
func NewOasisService() OasisService { func NewOasisService() CasaService {
return &oasisService{} return &casaService{}
} }

View File

@ -3,14 +3,15 @@ package service
import ( import (
json2 "encoding/json" json2 "encoding/json"
"fmt" "fmt"
"strconv"
"strings"
"github.com/IceWhaleTech/CasaOS/model" "github.com/IceWhaleTech/CasaOS/model"
"github.com/IceWhaleTech/CasaOS/pkg/config" "github.com/IceWhaleTech/CasaOS/pkg/config"
command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command" command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command"
loger2 "github.com/IceWhaleTech/CasaOS/pkg/utils/loger" loger2 "github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
"github.com/shirou/gopsutil/v3/disk" "github.com/shirou/gopsutil/v3/disk"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"strconv"
"strings"
) )
type DiskService interface { type DiskService interface {

View File

@ -20,6 +20,7 @@ import (
"github.com/IceWhaleTech/CasaOS/model" "github.com/IceWhaleTech/CasaOS/model"
"github.com/IceWhaleTech/CasaOS/pkg/docker" "github.com/IceWhaleTech/CasaOS/pkg/docker"
command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command" command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command"
"github.com/IceWhaleTech/CasaOS/pkg/utils/env_helper"
"github.com/IceWhaleTech/CasaOS/pkg/utils/file" "github.com/IceWhaleTech/CasaOS/pkg/utils/file"
loger2 "github.com/IceWhaleTech/CasaOS/pkg/utils/loger" loger2 "github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
@ -60,6 +61,7 @@ type DockerService interface {
DockerNetworkModelList() []types.NetworkResource DockerNetworkModelList() []types.NetworkResource
DockerImageInfo(image string) DockerImageInfo(image string)
GetNetWorkNameByNetWorkID(id string) (string, error) GetNetWorkNameByNetWorkID(id string) (string, error)
ContainerExecShell(container_id string) string
} }
type dockerService struct { type dockerService struct {
@ -67,15 +69,20 @@ type dockerService struct {
log loger2.OLog log loger2.OLog
} }
func DockerPs() { func (ds *dockerService) ContainerExecShell(container_id string) string {
cli, _ := client2.NewClientWithOpts(client2.FromEnv) cli, _ := client2.NewClientWithOpts(client2.FromEnv)
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{}) exec, err := cli.ContainerExecCreate(context.Background(), container_id, types.ExecConfig{
User: "1000:1000",
Cmd: []string{"echo -e \"hellow\nworld\" >> /a.txt"},
})
if err != nil { if err != nil {
os.Exit(5) os.Exit(5)
} }
for _, container := range containers { err = cli.ContainerExecStart(context.Background(), exec.ID, types.ExecStartCheck{})
fmt.Printf("%s %s\n", container.ID[:10], container.Image) if err != nil {
fmt.Println("exec script error ", err)
} }
return exec.ID
} }
//创建默认网络 //创建默认网络
@ -401,6 +408,10 @@ func (ds *dockerService) DockerContainerCreate(imageName string, containerDbId s
var envArr []string var envArr []string
for _, e := range m.Envs { for _, e := range m.Envs {
if strings.HasPrefix(e.Value, "$") {
envArr = append(envArr, e.Name+"="+env_helper.ReplaceDefaultENV(e.Value))
continue
}
if len(e.Value) > 0 { if len(e.Value) > 0 {
if e.Value == "port_map" { if e.Value == "port_map" {
envArr = append(envArr, e.Name+"="+m.PortMap) envArr = append(envArr, e.Name+"="+m.PortMap)
@ -433,6 +444,7 @@ func (ds *dockerService) DockerContainerCreate(imageName string, containerDbId s
continue continue
} }
} }
path = strings.ReplaceAll(path, "$AppID", containerDbId)
reg1 := regexp.MustCompile(`([^<>/\\\|:""\*\?]+\.\w+$)`) reg1 := regexp.MustCompile(`([^<>/\\\|:""\*\?]+\.\w+$)`)
result1 := reg1.FindAllStringSubmatch(path, -1) result1 := reg1.FindAllStringSubmatch(path, -1)
if len(result1) == 0 { if len(result1) == 0 {
@ -475,11 +487,12 @@ func (ds *dockerService) DockerContainerCreate(imageName string, containerDbId s
StartPeriod: 0, StartPeriod: 0,
Retries: 1000, Retries: 1000,
} }
fmt.Print(health)
config := &container.Config{ config := &container.Config{
Image: imageName, Image: imageName,
Labels: map[string]string{"origin": m.Origin, m.Origin: m.Origin}, Labels: map[string]string{"origin": m.Origin, m.Origin: m.Origin},
Env: envArr, Env: envArr,
Healthcheck: health, // Healthcheck: health,
} }
hostConfig := &container.HostConfig{Resources: res, Mounts: volumes, RestartPolicy: rp, NetworkMode: container.NetworkMode(net)} hostConfig := &container.HostConfig{Resources: res, Mounts: volumes, RestartPolicy: rp, NetworkMode: container.NetworkMode(net)}
//if net != "host" { //if net != "host" {
@ -816,7 +829,6 @@ func Containerd() {
) )
if err != nil { if err != nil {
fmt.Println("333")
fmt.Println(err) fmt.Println(err)
} }
defer container.Delete(ctx, containerd.WithSnapshotCleanup) defer container.Delete(ctx, containerd.WithSnapshotCleanup)
@ -824,7 +836,6 @@ func Containerd() {
// create a task from the container // create a task from the container
task, err := container.NewTask(ctx, cio.NewCreator(cio.WithStdio)) task, err := container.NewTask(ctx, cio.NewCreator(cio.WithStdio))
if err != nil { if err != nil {
fmt.Println("444")
fmt.Println(err) fmt.Println(err)
} }
defer task.Delete(ctx) defer task.Delete(ctx)
@ -837,7 +848,6 @@ func Containerd() {
// call start on the task to execute the redis server // call start on the task to execute the redis server
if err = task.Start(ctx); err != nil { if err = task.Start(ctx); err != nil {
fmt.Println("555")
fmt.Println(err) fmt.Println(err)
} }
@ -847,7 +857,6 @@ func Containerd() {
// kill the process and get the exit status // kill the process and get the exit status
if err = task.Kill(ctx, syscall.SIGTERM); err != nil { if err = task.Kill(ctx, syscall.SIGTERM); err != nil {
fmt.Println("666")
fmt.Println(err) fmt.Println(err)
} }
@ -856,7 +865,6 @@ func Containerd() {
status := <-exitStatusC status := <-exitStatusC
code, _, err := status.Result() code, _, err := status.Result()
if err != nil { if err != nil {
fmt.Println("777")
fmt.Println(err) fmt.Println(err)
} }
fmt.Printf("redis-server exited with status: %d\n", code) fmt.Printf("redis-server exited with status: %d\n", code)

View File

@ -3,7 +3,7 @@ package docker_base
import "github.com/IceWhaleTech/CasaOS/model" import "github.com/IceWhaleTech/CasaOS/model"
//过滤mysql关键字 //过滤mysql关键字
func MysqlFilter(c MysqlConfig, envs model.EnvArrey) model.EnvArrey { func MysqlFilter(c MysqlConfig, envs model.EnvArray) model.EnvArray {
for i := 0; i < len(envs); i++ { for i := 0; i < len(envs); i++ {
switch envs[i].Value { switch envs[i].Value {
case "$MYSQL_HOST": case "$MYSQL_HOST":

View File

@ -9,6 +9,7 @@ type AppNotify struct {
Type int `json:"type"` // 1:显示即为已读 2:info 3:warning 4:error 5:success Type int `json:"type"` // 1:显示即为已读 2:info 3:warning 4:error 5:success
Icon string `json:"icon"` Icon string `json:"icon"`
Name string `json:"name"` Name string `json:"name"`
CustomId string `gorm:"column:custom_id;primary_key" json:"custom_id"`
} }
func (p *AppNotify) TableName() string { func (p *AppNotify) TableName() string {

View File

@ -18,7 +18,7 @@ type Repository interface {
//Redis() RedisService //Redis() RedisService
ZeroTier() ZeroTierService ZeroTier() ZeroTierService
ZiMa() ZiMaService ZiMa() ZiMaService
OAPI() OasisService OAPI() CasaService
Disk() DiskService Disk() DiskService
Notify() NotifyServer Notify() NotifyServer
ShareDirectory() ShareDirService ShareDirectory() ShareDirService
@ -58,7 +58,7 @@ type store struct {
docker DockerService docker DockerService
zerotier ZeroTierService zerotier ZeroTierService
zima ZiMaService zima ZiMaService
oapi OasisService oapi CasaService
disk DiskService disk DiskService
notify NotifyServer notify NotifyServer
shareDirectory ShareDirService shareDirectory ShareDirService
@ -105,7 +105,7 @@ func (c *store) ZeroTier() ZeroTierService {
func (c *store) ZiMa() ZiMaService { func (c *store) ZiMa() ZiMaService {
return c.zima return c.zima
} }
func (c *store) OAPI() OasisService { func (c *store) OAPI() CasaService {
return c.oapi return c.oapi
} }

View File

@ -1,4 +1,4 @@
package types package types
const CURRENTVERSION = "0.1.9" const CURRENTVERSION = "0.1.10"
const BODY = "<li>add casaOS logs</li><li>add application terminal</li><li>add application logs</li>" const BODY = "<li>Add App Store for installation</li><li>add casaOS logs</li><li>add application terminal</li><li>add application logs</li>"