Documentation
¶
Overview ¶
Package docker 应用商店目录服务 加载 docker-apps.yaml,提供应用浏览、搜索、分类查询
Package docker HTTP 处理器 ¶
Package docker 已安装应用服务 管理 Docker 应用的安装、卸载、启停、日志等生命周期操作
Package docker 已安装应用 HTTP 处理器 ¶
Package docker 提供 Docker 容器管理和应用商店模块 ¶
Package docker 端口检测服务 ¶
Package docker Docker 服务 ¶
Package docker 应用商店 HTTP 处理器 ¶
Package docker Docker 类型定义
Index ¶
- Constants
- type AppRaw
- type AppStoreRaw
- type CatalogService
- type ContainerConfig
- type ContainerInfo
- type ContainerStats
- type ContainerStatus
- type CreateContainerRequest
- type CreateNetworkRequest
- type DockerInfo
- type FormField
- type FormFieldRaw
- type Handler
- func (h *Handler) CreateContainer(c *gin.Context)
- func (h *Handler) CreateNetwork(c *gin.Context)
- func (h *Handler) ExecContainer(c *gin.Context)
- func (h *Handler) GetContainerLogs(c *gin.Context)
- func (h *Handler) GetContainerStats(c *gin.Context)
- func (h *Handler) GetContainerStatus(c *gin.Context)
- func (h *Handler) GetInfo(c *gin.Context)
- func (h *Handler) GetStatus(c *gin.Context)
- func (h *Handler) ListContainers(c *gin.Context)
- func (h *Handler) ListImages(c *gin.Context)
- func (h *Handler) ListNetworks(c *gin.Context)
- func (h *Handler) PullImage(c *gin.Context)
- func (h *Handler) RegisterRoutes(r *gin.RouterGroup)
- func (h *Handler) RemoveContainer(c *gin.Context)
- func (h *Handler) RemoveImage(c *gin.Context)
- func (h *Handler) RemoveNetwork(c *gin.Context)
- func (h *Handler) RestartContainer(c *gin.Context)
- func (h *Handler) StartContainer(c *gin.Context)
- func (h *Handler) StopContainer(c *gin.Context)
- type ImageInfo
- type InstallTask
- type InstalledApp
- type InstalledHandler
- func (h *InstalledHandler) GetLogs(c *gin.Context)
- func (h *InstalledHandler) GetTask(c *gin.Context)
- func (h *InstalledHandler) Install(c *gin.Context)
- func (h *InstalledHandler) InstallAsync(c *gin.Context)
- func (h *InstalledHandler) List(c *gin.Context)
- func (h *InstalledHandler) RegisterRoutes(r *gin.RouterGroup)
- func (h *InstalledHandler) Restart(c *gin.Context)
- func (h *InstalledHandler) Start(c *gin.Context)
- func (h *InstalledHandler) Stop(c *gin.Context)
- func (h *InstalledHandler) Uninstall(c *gin.Context)
- type InstalledService
- func (is *InstalledService) Get(name string) *InstalledApp
- func (is *InstalledService) GetAll() []*InstalledApp
- func (is *InstalledService) GetLogs(name string, tail int) (string, error)
- func (is *InstalledService) GetTask(taskID string) *InstallTask
- func (is *InstalledService) Install(appID string, config map[string]interface{}) (*InstalledApp, string, error)
- func (is *InstalledService) InstallAsync(appID string, config map[string]interface{}) (*InstallTask, error)
- func (is *InstalledService) InstallStreaming(appID string, config map[string]interface{}, onOutput func(string)) (*InstalledApp, string, error)
- func (is *InstalledService) Restart(name string) error
- func (is *InstalledService) Start(name string) error
- func (is *InstalledService) Stop(name string) error
- func (is *InstalledService) Uninstall(name string) error
- type LocaleText
- type Module
- func (m *Module) Dependencies() []string
- func (m *Module) GetCatalog() *CatalogService
- func (m *Module) GetService() *Service
- func (m *Module) ID() string
- func (m *Module) Init(ctx *module.Context) error
- func (m *Module) Name() string
- func (m *Module) RegisterRoutes(group *gin.RouterGroup)
- func (m *Module) Start() error
- func (m *Module) Stop() error
- func (m *Module) Version() string
- type NetworkInfo
- type PortBinding
- type PortHandler
- type PullImageRequest
- type Service
- func (s *Service) Close() error
- func (s *Service) CreateContainer(ctx context.Context, config *ContainerConfig) (string, error)
- func (s *Service) CreateNetwork(ctx context.Context, name, driver string) (string, error)
- func (s *Service) ExecInContainer(ctx context.Context, containerID string, command string) (string, error)
- func (s *Service) GetContainerLogs(ctx context.Context, containerID string, tail int) (string, error)
- func (s *Service) GetContainerStats(ctx context.Context, containerID string) (*ContainerStats, error)
- func (s *Service) GetContainerStatus(ctx context.Context, containerID string) (*ContainerStatus, error)
- func (s *Service) GetInfo(ctx context.Context) (*DockerInfo, error)
- func (s *Service) ImageExists(ctx context.Context, image string) bool
- func (s *Service) IsRunning(ctx context.Context) bool
- func (s *Service) ListContainers(ctx context.Context, all bool) ([]ContainerInfo, error)
- func (s *Service) ListImages(ctx context.Context) ([]ImageInfo, error)
- func (s *Service) ListNetworks(ctx context.Context) ([]NetworkInfo, error)
- func (s *Service) PullImage(ctx context.Context, image string, progress chan<- string) error
- func (s *Service) RemoveContainer(ctx context.Context, containerID string, force bool) error
- func (s *Service) RemoveImage(ctx context.Context, imageID string) error
- func (s *Service) RemoveNetwork(ctx context.Context, networkID string) error
- func (s *Service) RestartContainer(ctx context.Context, containerID string) error
- func (s *Service) StartContainer(ctx context.Context, containerID string) error
- func (s *Service) StopContainer(ctx context.Context, containerID string) error
- type StoreApp
- type StoreCategory
- type StoreHandler
Constants ¶
const ( ModuleID = "docker" ModuleName = "Docker App Store" ModuleVersion = "1.0.0" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppRaw ¶
type AppRaw struct {
ID string `yaml:"id"`
Name string `yaml:"name"`
Platform string `yaml:"platform"`
Category string `yaml:"category"`
Author string `yaml:"author,omitempty"`
License string `yaml:"license,omitempty"`
Homepage string `yaml:"homepage"`
Repository string `yaml:"repository"`
Icon string `yaml:"icon"`
Version string `yaml:"version"`
Architectures []string `yaml:"architectures"`
Tags []string `yaml:"tags"`
Title map[string]string `yaml:"title"`
Description map[string]string `yaml:"description"`
Form []FormFieldRaw `yaml:"form"`
Compose yaml.Node `yaml:"compose"` // 保持原始 YAML 结构
}
AppRaw 单个应用的 YAML 原始结构
type AppStoreRaw ¶
AppStoreRaw YAML 顶层结构
type CatalogService ¶
type CatalogService struct {
// contains filtered or unexported fields
}
CatalogService 应用目录服务
func NewCatalogService ¶
func NewCatalogService(yamlPath string, logger *zap.Logger) (*CatalogService, error)
NewCatalogService 创建目录服务
func (*CatalogService) GetApp ¶
func (cs *CatalogService) GetApp(id string) *StoreApp
GetApp 获取单个应用详情
func (*CatalogService) GetApps ¶
func (cs *CatalogService) GetApps(category, search string) []StoreApp
GetApps 获取应用列表(支持分类和搜索筛选)
func (*CatalogService) GetCategories ¶
func (cs *CatalogService) GetCategories() []StoreCategory
GetCategories 获取分类列表
type ContainerConfig ¶
type ContainerConfig struct {
Name string `json:"name"`
Image string `json:"image"`
Ports map[string]string `json:"ports"`
Volumes map[string]string `json:"volumes"`
Environment []string `json:"environment"`
Networks []string `json:"networks"`
Labels map[string]string `json:"labels"`
Restart string `json:"restart"`
Privileged bool `json:"privileged"`
CapAdd []string `json:"cap_add"`
Devices []string `json:"devices"`
Command []string `json:"command"`
}
ContainerConfig 容器创建配置
type ContainerInfo ¶
type ContainerInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Image string `json:"image"`
ImageID string `json:"image_id"`
State string `json:"state"`
Status string `json:"status"`
Created int64 `json:"created"`
Ports []PortBinding `json:"ports"`
}
ContainerInfo 容器简要信息
type ContainerStats ¶
type ContainerStats struct {
CPUPercent float64 `json:"cpu_percent"`
MemoryUsage uint64 `json:"memory_usage"`
MemoryLimit uint64 `json:"memory_limit"`
MemoryPercent float64 `json:"memory_percent"`
NetworkRx uint64 `json:"network_rx"`
NetworkTx uint64 `json:"network_tx"`
BlockRead uint64 `json:"block_read"`
BlockWrite uint64 `json:"block_write"`
}
ContainerStats 容器资源统计
type ContainerStatus ¶
type ContainerStatus struct {
ID string `json:"id"`
Name string `json:"name"`
Image string `json:"image"`
State string `json:"state"`
Running bool `json:"running"`
StartedAt string `json:"started_at"`
ExitCode int `json:"exit_code"`
}
ContainerStatus 容器状态
type CreateContainerRequest ¶
type CreateContainerRequest struct {
Name string `json:"name" binding:"required"`
Image string `json:"image" binding:"required"`
Ports map[string]string `json:"ports"`
Volumes map[string]string `json:"volumes"`
Environment []string `json:"environment"`
Networks []string `json:"networks"`
Labels map[string]string `json:"labels"`
Restart string `json:"restart"`
Privileged bool `json:"privileged"`
CapAdd []string `json:"cap_add"`
Devices []string `json:"devices"`
Command []string `json:"command"`
}
CreateContainerRequest 创建容器请求
type CreateNetworkRequest ¶
type CreateNetworkRequest struct {
Name string `json:"name" binding:"required"`
Driver string `json:"driver"`
}
CreateNetworkRequest 创建网络请求
type DockerInfo ¶
type DockerInfo struct {
Version string `json:"version"`
APIVersion string `json:"api_version"`
OS string `json:"os"`
Arch string `json:"arch"`
KernelVersion string `json:"kernel_version"`
Containers int `json:"containers"`
ContainersRunning int `json:"containers_running"`
ContainersStopped int `json:"containers_stopped"`
Images int `json:"images"`
Driver string `json:"driver"`
MemTotal int64 `json:"mem_total"`
NCPU int `json:"ncpu"`
}
DockerInfo Docker 系统信息
type FormField ¶
type FormField struct {
Key string `json:"key"`
Label LocaleText `json:"label"`
Default interface{} `json:"default,omitempty"`
Required bool `json:"required"`
Type string `json:"type"`
EnvKey string `json:"env_key,omitempty"`
}
FormField 表单字段(API 响应)
type FormFieldRaw ¶
type FormFieldRaw struct {
Key string `yaml:"key"`
Label map[string]string `yaml:"label"`
Default interface{} `yaml:"default,omitempty"`
Required bool `yaml:"required,omitempty"`
Type string `yaml:"type"`
EnvKey string `yaml:"env_key,omitempty"`
}
FormFieldRaw 表单字段原始结构
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler HTTP 处理器
func (*Handler) CreateContainer ¶
CreateContainer 创建容器
func (*Handler) ExecContainer ¶
ExecContainer 在容器内执行命令
func (*Handler) GetContainerLogs ¶
GetContainerLogs 获取容器日志
func (*Handler) GetContainerStats ¶
GetContainerStats 获取容器统计
func (*Handler) GetContainerStatus ¶
GetContainerStatus 获取容器状态
func (*Handler) ListContainers ¶
ListContainers 列出容器
func (*Handler) RegisterRoutes ¶
func (h *Handler) RegisterRoutes(r *gin.RouterGroup)
RegisterRoutes 注册路由
func (*Handler) RemoveContainer ¶
RemoveContainer 删除容器
func (*Handler) RestartContainer ¶
RestartContainer 重启容器
func (*Handler) StartContainer ¶
StartContainer 启动容器
type ImageInfo ¶
type ImageInfo struct {
ID string `json:"id"`
Repository string `json:"repository"`
Tag string `json:"tag"`
Size int64 `json:"size"`
Created int64 `json:"created"`
}
ImageInfo 镜像信息
type InstallTask ¶
type InstallTask struct {
ID string `json:"id"`
AppID string `json:"app_id"`
Name string `json:"name"`
Status string `json:"status"` // "pending", "running", "success", "failed"
Output string `json:"output"`
Error string `json:"error,omitempty"`
CreatedAt time.Time `json:"created_at"`
DoneAt time.Time `json:"done_at,omitempty"`
}
InstallTask 安装任务(异步)
type InstalledApp ¶
type InstalledApp struct {
Name string `json:"name"`
AppID string `json:"app_id"`
Version string `json:"version"`
Icon string `json:"icon"`
Status string `json:"status"`
Config map[string]interface{} `json:"config"`
ComposePath string `json:"compose_path"`
InstalledAt time.Time `json:"installed_at"`
}
InstalledApp 已安装应用
type InstalledHandler ¶
type InstalledHandler struct {
// contains filtered or unexported fields
}
InstalledHandler 已安装应用 HTTP 处理器
func NewInstalledHandler ¶
func NewInstalledHandler(installed *InstalledService, logger *zap.Logger) *InstalledHandler
NewInstalledHandler 创建处理器
func (*InstalledHandler) GetLogs ¶
func (h *InstalledHandler) GetLogs(c *gin.Context)
GetLogs 获取应用日志 GET /docker/apps/:name/logs?tail=100
func (*InstalledHandler) GetTask ¶
func (h *InstalledHandler) GetTask(c *gin.Context)
GetTask 获取安装任务状态 GET /docker/apps/tasks/:taskId
func (*InstalledHandler) Install ¶
func (h *InstalledHandler) Install(c *gin.Context)
Install 安装应用 POST /docker/apps { app_id, config }
func (*InstalledHandler) InstallAsync ¶
func (h *InstalledHandler) InstallAsync(c *gin.Context)
InstallAsync 异步安装应用 POST /docker/apps/async { app_id, config }
func (*InstalledHandler) List ¶
func (h *InstalledHandler) List(c *gin.Context)
List 获取已安装应用列表 GET /docker/apps
func (*InstalledHandler) RegisterRoutes ¶
func (h *InstalledHandler) RegisterRoutes(r *gin.RouterGroup)
RegisterRoutes 注册路由
func (*InstalledHandler) Restart ¶
func (h *InstalledHandler) Restart(c *gin.Context)
Restart 重启应用 POST /docker/apps/:name/restart
func (*InstalledHandler) Start ¶
func (h *InstalledHandler) Start(c *gin.Context)
Start 启动应用 POST /docker/apps/:name/start
func (*InstalledHandler) Stop ¶
func (h *InstalledHandler) Stop(c *gin.Context)
Stop 停止应用 POST /docker/apps/:name/stop
func (*InstalledHandler) Uninstall ¶
func (h *InstalledHandler) Uninstall(c *gin.Context)
Uninstall 卸载应用 DELETE /docker/apps/:name
type InstalledService ¶
type InstalledService struct {
// contains filtered or unexported fields
}
InstalledService 已安装应用服务
func NewInstalledService ¶
func NewInstalledService(dataDir string, catalog *CatalogService, logger *zap.Logger) (*InstalledService, error)
NewInstalledService 创建已安装应用服务
func (*InstalledService) Get ¶
func (is *InstalledService) Get(name string) *InstalledApp
Get 获取单个已安装应用
func (*InstalledService) GetAll ¶
func (is *InstalledService) GetAll() []*InstalledApp
GetAll 获取所有已安装应用(含实时状态)
func (*InstalledService) GetLogs ¶
func (is *InstalledService) GetLogs(name string, tail int) (string, error)
GetLogs 获取应用日志
func (*InstalledService) GetTask ¶
func (is *InstalledService) GetTask(taskID string) *InstallTask
GetTask 获取安装任务状态
func (*InstalledService) Install ¶
func (is *InstalledService) Install(appID string, config map[string]interface{}) (*InstalledApp, string, error)
Install 安装应用(同步)
func (*InstalledService) InstallAsync ¶
func (is *InstalledService) InstallAsync(appID string, config map[string]interface{}) (*InstallTask, error)
InstallAsync 异步安装应用,返回任务 ID
func (*InstalledService) InstallStreaming ¶
func (is *InstalledService) InstallStreaming(appID string, config map[string]interface{}, onOutput func(string)) (*InstalledApp, string, error)
InstallStreaming 安装应用(流式输出版本) onOutput 回调在每读到新行时被调用,用于实时更新进度
func (*InstalledService) Restart ¶
func (is *InstalledService) Restart(name string) error
Restart 重启应用
func (*InstalledService) Uninstall ¶
func (is *InstalledService) Uninstall(name string) error
Uninstall 卸载应用
type LocaleText ¶
LocaleText 多语言文本
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module Docker应用模块
func (*Module) GetCatalog ¶
func (m *Module) GetCatalog() *CatalogService
GetCatalog 获取目录服务实例(供其他模块调用)
func (*Module) RegisterRoutes ¶
func (m *Module) RegisterRoutes(group *gin.RouterGroup)
RegisterRoutes 注册路由
type NetworkInfo ¶
type NetworkInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Driver string `json:"driver"`
Scope string `json:"scope"`
Subnet string `json:"subnet"`
Gateway string `json:"gateway"`
}
NetworkInfo 网络信息
type PortBinding ¶
type PortBinding struct {
HostPort string `json:"host_port"`
ContainerPort string `json:"container_port"`
Protocol string `json:"protocol"`
}
PortBinding 端口绑定
type PortHandler ¶
type PortHandler struct{}
PortHandler 端口检测 HTTP 处理器
func (*PortHandler) CheckPort ¶
func (h *PortHandler) CheckPort(c *gin.Context)
CheckPort 检查端口是否可用 GET /docker/ports/check?port=8080
func (*PortHandler) RegisterRoutes ¶
func (h *PortHandler) RegisterRoutes(r *gin.RouterGroup)
RegisterRoutes 注册路由
func (*PortHandler) SuggestPort ¶
func (h *PortHandler) SuggestPort(c *gin.Context)
SuggestPort 建议可用端口 GET /docker/ports/suggest?preferred=8080
type PullImageRequest ¶
type PullImageRequest struct {
Image string `json:"image" binding:"required"`
}
PullImageRequest 拉取镜像请求
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service Docker 服务
func (*Service) CreateContainer ¶
CreateContainer 创建容器
func (*Service) CreateNetwork ¶
CreateNetwork 创建网络
func (*Service) ExecInContainer ¶
func (s *Service) ExecInContainer(ctx context.Context, containerID string, command string) (string, error)
ExecInContainer 在容器内执行命令
func (*Service) GetContainerLogs ¶
func (s *Service) GetContainerLogs(ctx context.Context, containerID string, tail int) (string, error)
GetContainerLogs 获取容器日志
func (*Service) GetContainerStats ¶
func (s *Service) GetContainerStats(ctx context.Context, containerID string) (*ContainerStats, error)
GetContainerStats 获取容器统计
func (*Service) GetContainerStatus ¶
func (s *Service) GetContainerStatus(ctx context.Context, containerID string) (*ContainerStatus, error)
GetContainerStatus 获取容器状态
func (*Service) GetInfo ¶
func (s *Service) GetInfo(ctx context.Context) (*DockerInfo, error)
GetInfo 获取 Docker 信息
func (*Service) ImageExists ¶
ImageExists 检查镜像是否存在
func (*Service) ListContainers ¶
ListContainers 列出容器
func (*Service) ListImages ¶
ListImages 列出镜像
func (*Service) ListNetworks ¶
func (s *Service) ListNetworks(ctx context.Context) ([]NetworkInfo, error)
ListNetworks 列出网络
func (*Service) RemoveContainer ¶
RemoveContainer 删除容器
func (*Service) RemoveImage ¶
RemoveImage 删除镜像
func (*Service) RemoveNetwork ¶
RemoveNetwork 删除网络
func (*Service) RestartContainer ¶
RestartContainer 重启容器
func (*Service) StartContainer ¶
StartContainer 启动容器
type StoreApp ¶
type StoreApp struct {
ID string `json:"id"`
Name string `json:"name"`
Title string `json:"title"`
Description string `json:"description"`
TitleI18n LocaleText `json:"title_i18n"`
DescI18n LocaleText `json:"description_i18n"`
Category string `json:"category"`
Icon string `json:"icon"`
Version string `json:"version"`
Author string `json:"author,omitempty"`
License string `json:"license,omitempty"`
Homepage string `json:"homepage"`
Repository string `json:"repository"`
Tags []string `json:"tags"`
Architectures []string `json:"architectures"`
Form []FormField `json:"form"`
Compose string `json:"compose"` // YAML 字符串
}
StoreApp 商店应用(API 响应)
type StoreCategory ¶
type StoreCategory struct {
ID string `json:"id"`
Name string `json:"name"`
Count int `json:"count"`
}
StoreCategory 商店分类
type StoreHandler ¶
type StoreHandler struct {
// contains filtered or unexported fields
}
StoreHandler 应用商店 HTTP 处理器
func NewStoreHandler ¶
func NewStoreHandler(catalog *CatalogService, logger *zap.Logger) *StoreHandler
NewStoreHandler 创建商店处理器
func (*StoreHandler) GetApp ¶
func (h *StoreHandler) GetApp(c *gin.Context)
GetApp 获取应用详情 GET /docker/store/apps/:id
func (*StoreHandler) ListApps ¶
func (h *StoreHandler) ListApps(c *gin.Context)
ListApps 获取应用列表 GET /docker/store/apps?category=xxx&search=xxx
func (*StoreHandler) ListCategories ¶
func (h *StoreHandler) ListCategories(c *gin.Context)
ListCategories 获取分类列表 GET /docker/store/categories
func (*StoreHandler) RegisterRoutes ¶
func (h *StoreHandler) RegisterRoutes(r *gin.RouterGroup)
RegisterRoutes 注册商店路由
func (*StoreHandler) SetIconsDir ¶
func (h *StoreHandler) SetIconsDir(dir string)
SetIconsDir 设置图标目录路径