provision

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package provision 统一管理容器运行时的「安装 / 启动」生命周期。

设计动机见 docs/container-runtime-provisioner.md。要点:

  • 每次进程启动只调用一次 Start:已安装则确保 daemon 可用并返回 endpoint, 未安装则返回 ErrNotInstalled 且不产生任何副作用;
  • Download / Install / Uninstall 只由安装向导(UI)触发;
  • 接口在 Windows(WSL 发行版)与 Linux(本机 dockerd)上保持一致, 上层装配与 HTTP 接口无需区分平台。

具体类型定义在 provision/types 子包,这里用类型别名再导出, 调用方只需 import provision 一个包。

Index

Constants

View Source
const (
	StateNotInstalled = types.StateNotInstalled
	StateDownloaded   = types.StateDownloaded
	StateInstalled    = types.StateInstalled
	StateRunning      = types.StateRunning
)

状态常量别名。

View Source
const StartTimeout = 30 * time.Second

StartTimeout 是 StartAsync 的默认超时上限。

dockerd 冷启动(WSL 实例唤醒 + 容器运行时初始化)通常 3-15s, 给 30s 上限既避免误判,也不会留下长期挂起的 goroutine。

Variables

View Source
var (
	ErrNotInstalled   = types.ErrNotInstalled
	ErrUnsupported    = types.ErrUnsupported
	ErrAlreadyRunning = types.ErrAlreadyRunning
	ErrNotDownloaded  = types.ErrNotDownloaded
)

哨兵错误别名。

View Source
var Report = types.Report

Report 进度上报工具(实现包使用)。

Functions

This section is empty.

Types

type Config

type Config = types.Config

Config 跨平台构造参数。

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager 包装一个具体 Provisioner,补上上层需要的三件事:

  1. 统一的「启动时调用一次」入口 Start / StartAsync;
  2. 把 ErrNotInstalled 与真正的失败区分开,方便调用方决定是否静默;
  3. 提供只读的 Endpoint,避免装配层为了拿地址再探测一次。

func NewManager

func NewManager(inner Provisioner) *Manager

NewManager 包装给定实现;inner 为 nil 时返回 nil(调用方按「无预置能力」处理)。

func (*Manager) Endpoint

func (m *Manager) Endpoint() string

Endpoint 返回 daemon 地址(由底层实现提供,如 WSL 侧解析出的发行版地址); 未启用或未启动时为空。

func (*Manager) Inner

func (m *Manager) Inner() Provisioner

Inner 返回底层实现,供需要平台特有能力(如安装向导)的调用方使用。

func (*Manager) ProbeEndpoint

func (m *Manager) ProbeEndpoint(ctx context.Context) (string, error)

ProbeEndpoint 是装配层的便捷方法:启动成功则返回 endpoint, 未安装返回 ("", ErrNotInstalled),其余返回错误。

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) (string, error)

Start 启动运行时。

未安装时返回 ErrNotInstalled(调用方应静默忽略并等待 UI 安装向导); 其他错误视为真实故障。

func (*Manager) StartAsync

func (m *Manager) StartAsync(ctx context.Context)

StartAsync 在后台启动运行时,立即返回,不阻塞调用方(如进程启动 / 界面打开)。

语义与 Start 一致,只是把等待与错误处理移入 goroutine:

  • 未安装(ErrNotInstalled)只记录日志,等待 UI 安装向导;
  • 其他错误记录告警;
  • 成功后通过 Endpoint 读取实际地址。

m 为 nil(未启用预置)时什么都不做。

func (*Manager) WrappedError

func (m *Manager) WrappedError() error

WrappedError 返回最近一次 Start 的错误(供状态接口展示)。

type Progress

type Progress = types.Progress

Progress 一次 Download / Install 的进度快照。

type ProgressFunc

type ProgressFunc = types.ProgressFunc

ProgressFunc 进度回调。

type Provisioner

type Provisioner = types.Provisioner

Provisioner 容器运行时生命周期接口。

func New

func New(cfg Config) Provisioner

New 按当前平台返回合适的 Provisioner。

非 Windows 平台统一管理本机 dockerd(Linux 是主要场景)。 与 Windows 实现共享完全相同的接口与错误语义,上层无需分支。 cfg.Endpoint 作为 daemon 地址传入;为空时由 newLocal 回退默认值。

type RuntimeStatus

type RuntimeStatus = types.RuntimeStatus

RuntimeStatus UI 需要的状态信息。

type State

type State = types.State

State 运行时预置状态。

Directories

Path Synopsis
Package types 是 provision 各实现共享的最小类型集合。
Package types 是 provision 各实现共享的最小类型集合。

Jump to

Keyboard shortcuts

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