model

package
v0.4.95 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

@Author: link a624669980@163.com

*@Date: 2022-05-16 17:37:08
*@LastEditors: LinkLeong
*@LastEditTime: 2022-07-13 10:46:38
*@FilePath: /CasaOS/model/category.go
*@Description:

@Author: LinkLeong link@icewhale.com

*@Date: 2021-12-08 18:10:25
*@LastEditors: LinkLeong
*@LastEditTime: 2022-07-13 10:49:16
*@FilePath: /CasaOS/model/docker.go
*@Description:
*@Website: https://www.casaos.io
*Copyright (c) 2022 by icewhale, All Rights Reserved.

Index

Constants

View Source
const (
	MaxLabelKeyLength   = 128
	MaxLabelValueLength = 2048
	MaxLabelsPerService = 50
)

What a user may set as a Docker label on a container (a service of a compose app, or the custom_labels of an app file). Labels are free text that reaches `docker create`, and some readers act on them: this box reads `casaos`, `origin` and `icon` to tell its own apps, and a reverse proxy such as Traefik routes by `traefik.*`. So:

  • a key is 1 to 128 characters of letters, digits and `. _ - /`, starting with a letter or a digit (no space, `=`, `:` or `$`: they cut a key short in the places that read one);
  • a value is valid UTF-8 of at most 2048 bytes with no control character;
  • at most 50 labels are added or changed per service in one request;
  • the keys this box sets itself, and the namespaces of Docker Compose and of CasaOS, are refused, so a label cannot turn a container into a CasaOS v1 app or take the place of what Compose records about its project.

Reverse-proxy labels (`traefik.*`) are allowed: setting them is why labels were asked for (CasaOS issue 1518), and only someone who can already write the whole compose file reaches this far. They are not filtered, so what they route is that user's to check.

Variables

This section is empty.

Functions

func IsReservedLabel added in v0.4.94

func IsReservedLabel(key string) bool

IsReservedLabel says whether the key is one this box or Docker Compose sets.

func ValidateLabel added in v0.4.94

func ValidateLabel(key, value string) error

ValidateLabel says why a label may not be set, or returns nil.

func ValidateLabels added in v0.4.94

func ValidateLabels(labels, known map[string]string) error

ValidateLabels checks labels a service gains or changes. known is what the service already carries (the installed app, or the store's version of it): a label equal to the one in known is not checked again, so an app that came with labels of its own, or with those this box added, can be saved as it is. nil known checks them all.

Types

type APPModel

type APPModel struct {
	LogPath      string
	LogSaveName  string
	LogFileExt   string
	AppStorePath string
	AppsPath     string
	DataPath     string

	// UpWaitTimeout bounds how long an app is given to report itself running or
	// healthy after it is started. Zero (the key absent) keeps the built-in default.
	// A duration with a unit: "5m", "20m".
	UpWaitTimeout time.Duration

	// The apps' logs: where they are kept, for how long and up to what size, and whether
	// the containers of no app are kept too.
	LogsPath          string
	LogsRetentionDays int
	LogsMaxSizeMB     int
	LogsIncludeOthers bool
}

type CasaOSGlobalVariables

type CasaOSGlobalVariables struct {
	AppChange bool
}

type Category

type Category struct {
	ID uint `gorm:"column:id;primary_key" json:"id"`
	//CreatedAt time.Time `json:"created_at"`
	//
	//UpdatedAt time.Time `json:"updated_at"`
	Font  string `json:"font"` // @tiger - 如果这个和前端有关,应该不属于后端的出参范围,而是前端去界定
	Name  string `json:"name"`
	Count uint   `json:"count"` // @tiger - count 属于动态信息,应该单独放在一个出参结构中(原因见另外一个关于 静态/动态 出参的注释)
}

type CommonModel

type CommonModel struct {
	RuntimePath string
}

type CustomizationPostData

type CustomizationPostData struct {
	ContainerName string    `json:"container_name"`
	CustomID      string    `json:"custom_id"`
	Origin        string    `json:"origin"`
	NetworkModel  string    `json:"network_model"`
	Index         string    `json:"index"`
	Icon          string    `json:"icon"`
	Image         string    `json:"image"`
	Envs          EnvArray  `json:"envs"`
	Ports         PortArray `json:"ports"`
	Volumes       PathArray `json:"volumes"`
	Devices       PathArray `json:"devices"`
	// Port         string    `json:"port,omitempty"`
	PortMap     string   `json:"port_map"`
	CPUShares   int64    `json:"cpu_shares"`
	Memory      int64    `json:"memory"`
	Restart     string   `json:"restart"`
	EnableUPNP  bool     `json:"enable_upnp"`
	Label       string   `json:"label"`
	Description string   `json:"description"`
	Position    bool     `json:"position"`
	HostName    string   `json:"host_name"`
	Privileged  bool     `json:"privileged"`
	CapAdd      []string `json:"cap_add"`
	Cmd         []string `json:"cmd"`
	Protocol    string   `json:"protocol"`
	Host        string   `json:"host"`
	AppStoreID  uint     `json:"appstore_id"`
	// Docker labels set by the user; see ValidateCustomLabels for what is accepted
	CustomLabels EnvArray `json:"custom_labels"`
}

func (*CustomizationPostData) AppStoreInfo

func (c *CustomizationPostData) AppStoreInfo() codegen.AppStoreInfo

func (*CustomizationPostData) Compose

func (*CustomizationPostData) ComposeAppStoreInfo

func (c *CustomizationPostData) ComposeAppStoreInfo() codegen.ComposeAppStoreInfo

func (*CustomizationPostData) Services

func (c *CustomizationPostData) Services() types.Services

func (*CustomizationPostData) ValidateCustomLabels added in v0.4.94

func (c *CustomizationPostData) ValidateCustomLabels() error

ValidateCustomLabels refuses labels that are invalid, reserved, too many or named twice (see labels.go).

type Devices

type Devices struct {
	ContainerPath string `json:"container_path"`
	Path          string `json:"path"`
	Desc          string `json:"desc"`
	Type          int    `json:"type"` //  1:必选 2:可选 3:默认值不必显示 4:系统处理 5:container内容也可编辑
}

type DockerDaemonConfigurationModel

type DockerDaemonConfigurationModel struct {
	// e.g. `/var/lib/docker`
	Root string `json:"data-root,omitempty"`
}

reference - https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file

type DockerStatsModel

type DockerStatsModel struct {
	Icon     string      `json:"icon"`
	Title    string      `json:"title"`
	Data     interface{} `json:"data"`
	Previous interface{} `json:"previous"`
}

type Env

type Env struct {
	Name  string `json:"container"`
	Value string `json:"host"`
	Desc  string `json:"desc"`
	Type  int    `json:"type"`
}

type EnvArray

type EnvArray []Env

func (*EnvArray) EnvStoreInfoList

func (ea *EnvArray) EnvStoreInfoList() []codegen.EnvStoreInfo

func (*EnvArray) LabelMap added in v0.4.94

func (ea *EnvArray) LabelMap() map[string]string

LabelMap gives the labels as Docker takes them; nil when there are none.

func (*EnvArray) ToMappingWithEquals

func (ea *EnvArray) ToMappingWithEquals() types.MappingWithEquals

type Envs

type Envs struct {
	Name  string `json:"name"`
	Value string `json:"value"`
	Desc  string `json:"desc"`
	Type  int    `json:"type"` //  1:必选 2:可选 3:默认值不必显示 4:系统处理 5:container内容也可编辑
}

type GlobalModel

type GlobalModel struct {
	OpenAIAPIKey string
}

type MapStrings

type MapStrings []map[string]string

type MyAppList

type MyAppList struct {
	ID             string `json:"id"`
	Name           string `json:"name"`
	Icon           string `json:"icon"`
	State          string `json:"state"`
	CustomID       string `gorm:"column:custom_id;primary_key" json:"custom_id"`
	Index          string `json:"index"`
	Port           string `json:"port"`
	Slogan         string `json:"slogan"`
	Type           string `json:"type"`
	Image          string `json:"image"`
	Volumes        string `json:"volumes"`
	Latest         bool   `json:"latest"`
	Host           string `json:"host"`
	Protocol       string `json:"protocol"`
	Created        int64  `json:"created"`
	AppStoreID     uint   `json:"appstore_id"`
	IsUncontrolled bool   `json:"is_uncontrolled"`
	ComposeProject string `json:"compose_project,omitempty"`
	// the compose files that project was started from, as its containers record them
	ComposeConfigFiles string `json:"-"`
}

type PathArray

type PathArray []PathMap

func (*PathArray) DeviceStoreInfoList

func (p *PathArray) DeviceStoreInfoList() []codegen.DeviceStoreInfo

func (*PathArray) ServiceVolumeConfigList

func (p *PathArray) ServiceVolumeConfigList() []types.ServiceVolumeConfig

func (*PathArray) ToSlice

func (p *PathArray) ToSlice() []types.DeviceMapping

ToSlice gives the mappings compose-go made of the "host:container" strings it took before v2.15

func (*PathArray) VolumeStoreInfoList

func (p *PathArray) VolumeStoreInfoList() []codegen.VolumeStoreInfo

type PathMap

type PathMap struct {
	ContainerPath string `json:"container"`
	Path          string `json:"host"`
	Type          int    `json:"type"`
	Desc          string `json:"desc"`
}

type PortArray

type PortArray []PortMap

func (*PortArray) PortStoreInfoList

func (p *PortArray) PortStoreInfoList() []codegen.PortStoreInfo

func (*PortArray) ServicePortConfigList

func (p *PortArray) ServicePortConfigList() []types.ServicePortConfig

type PortMap

type PortMap struct {
	ContainerPort string `json:"container"`
	CommendPort   string `json:"host"`
	Protocol      string `json:"protocol"`
	Desc          string `json:"desc"`
	Type          int    `json:"type"`
}

func (*PortMap) ServicePortConfig

func (p *PortMap) ServicePortConfig() (types.ServicePortConfig, error)

type Ports

type Ports struct {
	ContainerPort uint   `json:"container_port"`
	CommendPort   int    `json:"commend_port"`
	Desc          string `json:"desc"`
	Type          int    `json:"type"` //  1:必选 2:可选 3:默认值不必显示 4:系统处理  5:container内容也可编辑
}

type ServerAppList

type ServerAppList struct {
	ID             uint      `gorm:"column:id;primary_key" json:"id"`
	Title          string    `json:"title"`
	Description    string    `json:"description"`
	Tagline        string    `json:"tagline"`
	Tags           Strings   `gorm:"type:json" json:"tags"`
	Icon           string    `json:"icon"`
	ScreenshotLink Strings   `gorm:"type:json" json:"screenshot_link"`
	Category       string    `json:"category"`
	CategoryID     int       `json:"category_id"`
	CategoryFont   string    `json:"category_font"`
	PortMap        string    `json:"port_map"`
	ImageVersion   string    `json:"image_version"`
	Tip            string    `json:"tip"`
	Envs           EnvArray  `json:"envs"`
	Ports          PortArray `json:"ports"`
	Volumes        PathArray `json:"volumes"`
	Devices        PathArray `json:"devices"`
	NetworkModel   string    `json:"network_model"`
	Image          string    `json:"image"`
	Index          string    `json:"index"`
	CreatedAt      time.Time `json:"created_at"`
	UpdatedAt      time.Time `json:"updated_at"`
	State          StateEnum `json:"state"`
	Author         string    `json:"author"`
	MinMemory      int       `json:"min_memory"`
	MinDisk        int       `json:"min_disk"`
	Thumbnail      string    `json:"thumbnail"`
	Healthy        string    `json:"healthy"`
	Plugins        Strings   `json:"plugins"`
	Origin         string    `json:"origin"`
	Type           int       `json:"type"`
	QueryCount     int       `json:"query_count"`
	Developer      string    `json:"developer"`
	HostName       string    `json:"host_name"`
	Privileged     bool      `json:"privileged"`
	CapAdd         Strings   `json:"cap_add"`
	Cmd            Strings   `json:"cmd"`
	Architectures  Strings   `json:"architectures"`
	LatestDigest   Strings   `json:"latest_digests"`
}

@tiger - 对于用于出参的数据结构,静态信息(例如 title)和

动态信息(例如 state、query_count)应该划分到不同的数据结构中

这样的好处是
1 - 多次获取动态信息时可以减少出参复杂度,因为静态信息只获取一次就好
2 - 在未来的迭代中,可以降低维护成本(所有字段都展开放在一个层级维护成本略高)

另外,一些针对性字段,例如 Docker 相关的,可以用 map 来保存。
这样在未来增加多态 App,例如 Snap,不需要维护多个结构,或者一个结构保存不必要的字段

type ServerAppListCollection

type ServerAppListCollection struct {
	List      []ServerAppList `json:"list"`
	Recommend []ServerAppList `json:"recommend"`
	Community []ServerAppList `json:"community"`
}

type ServerCategoryList

type ServerCategoryList struct {
	Item []Category `json:"item"`
}

type ServerModel

type ServerModel struct {
	AppStoreList []string `ini:"appstore,,allowshadow"`
}

type StateEnum

type StateEnum int
const (
	StateEnumNotInstalled StateEnum = iota
	StateEnumInstalled
)

type Strings

type Strings []string

type TCPPorts

type TCPPorts struct {
	Desc          string `json:"desc"`
	ContainerPort int    `json:"container_port"`
}

type UDPPorts

type UDPPorts struct {
	Desc          string `json:"desc"`
	ContainerPort int    `json:"container_port"`
}

type Volume

type Volume struct {
	ContainerPath string `json:"container_path"`
	Path          string `json:"path"`
	Desc          string `json:"desc"`
	Type          int    `json:"type"` //  1:必选 2:可选 3:默认值不必显示 4:系统处理   5:container内容也可编辑
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL