Documentation
¶
Index ¶
- Constants
- func FormatDuration(d time.Duration) string
- func ParseCommand(command string) (string, []string)
- func RunCommand(ctx context.Context, command string, handler OutputHandler) error
- func RunCommandInDir(ctx context.Context, command, dir string, handler OutputHandler) error
- func RunScript(ctx context.Context, scriptPath string, handler OutputHandler) error
- type BaseExecutor
- func (e *BaseExecutor) AddEnv(key, value string)
- func (e *BaseExecutor) GetEnv() []string
- func (e *BaseExecutor) GetTimeout() time.Duration
- func (e *BaseExecutor) GetWorkingDir() string
- func (e *BaseExecutor) Name() string
- func (e *BaseExecutor) SetEnv(env []string)
- func (e *BaseExecutor) SetTimeout(timeout time.Duration)
- func (e *BaseExecutor) SetWorkingDir(dir string)
- func (e *BaseExecutor) Type() string
- type CommandRunner
- type DockerBuildExecutor
- type DockerPushExecutor
- type DockerScanner
- type Executor
- type GoBuildExecutor
- type MavenExecutor
- type OutputHandler
- type Result
- type SSHExecutor
- type ScriptRunner
Constants ¶
const ( TypeMaven = "maven" TypeDockerBuild = "docker-build" TypeDockerPush = "docker-push" TypeSSH = "ssh" TypeCommand = "command" TypeGoBuild = "go-build" )
ExecutorType 执行器类型常量
Variables ¶
This section is empty.
Functions ¶
func RunCommand ¶
func RunCommand(ctx context.Context, command string, handler OutputHandler) error
RunCommand 便捷函数:运行单个命令
func RunCommandInDir ¶
func RunCommandInDir(ctx context.Context, command, dir string, handler OutputHandler) error
RunCommandInDir 便捷函数:在指定目录运行命令
Types ¶
type BaseExecutor ¶
type BaseExecutor struct {
// contains filtered or unexported fields
}
BaseExecutor 基础执行器(可嵌入其他执行器)
func NewBaseExecutor ¶
func NewBaseExecutor(name, execType string) *BaseExecutor
NewBaseExecutor 创建基础执行器
func (*BaseExecutor) GetTimeout ¶
func (e *BaseExecutor) GetTimeout() time.Duration
GetTimeout 获取超时时间
func (*BaseExecutor) GetWorkingDir ¶
func (e *BaseExecutor) GetWorkingDir() string
GetWorkingDir 获取工作目录
func (*BaseExecutor) SetTimeout ¶
func (e *BaseExecutor) SetTimeout(timeout time.Duration)
SetTimeout 设置超时时间
func (*BaseExecutor) SetWorkingDir ¶
func (e *BaseExecutor) SetWorkingDir(dir string)
SetWorkingDir 设置工作目录
type CommandRunner ¶
type CommandRunner struct {
*BaseExecutor
// contains filtered or unexported fields
}
CommandRunner 通用命令运行器,支持实时输出流
func NewCommandRunner ¶
func NewCommandRunner(name, command string) *CommandRunner
NewCommandRunner 创建命令运行器
func NewCommandRunnerWithArgs ¶
func NewCommandRunnerWithArgs(name, cmd string, args []string) *CommandRunner
NewCommandRunnerWithArgs 创建带参数的命令运行器
func (*CommandRunner) Execute ¶
func (r *CommandRunner) Execute(ctx context.Context, handler OutputHandler) error
Execute 执行命令并实时流式输出
func (*CommandRunner) SetShell ¶
func (r *CommandRunner) SetShell(shell bool)
SetShell 设置是否使用 shell 执行
type DockerBuildExecutor ¶
type DockerBuildExecutor struct {
*BaseExecutor
// contains filtered or unexported fields
}
DockerBuildExecutor Docker 构建执行器
func NewDockerBuildExecutor ¶
func NewDockerBuildExecutor(taskName string, cfg config.TaskConfig) *DockerBuildExecutor
NewDockerBuildExecutor 创建 Docker 构建执行器
func (*DockerBuildExecutor) Execute ¶
func (e *DockerBuildExecutor) Execute(ctx context.Context, handler OutputHandler) error
Execute 执行 Docker 构建
func (*DockerBuildExecutor) FullImageName ¶
func (e *DockerBuildExecutor) FullImageName() string
FullImageName 返回完整的镜像名称
func (*DockerBuildExecutor) IsPushed ¶
func (e *DockerBuildExecutor) IsPushed() bool
IsPushed 返回镜像是否已在构建阶段推送
func (*DockerBuildExecutor) IsPushedLatest ¶
func (e *DockerBuildExecutor) IsPushedLatest() bool
IsPushedLatest 返回 latest 标签是否已在构建阶段推送
func (*DockerBuildExecutor) LatestImageName ¶
func (e *DockerBuildExecutor) LatestImageName() string
LatestImageName 返回 latest 标签的镜像名称
type DockerPushExecutor ¶
type DockerPushExecutor struct {
*BaseExecutor
// contains filtered or unexported fields
}
DockerPushExecutor Docker 推送执行器
func NewDockerPushExecutor ¶
func NewDockerPushExecutor(taskName string, cfg config.TaskConfig, registry *config.Registry) *DockerPushExecutor
NewDockerPushExecutor 创建 Docker 推送执行器
func (*DockerPushExecutor) Execute ¶
func (e *DockerPushExecutor) Execute(ctx context.Context, handler OutputHandler) error
Execute 执行 Docker 推送
func (*DockerPushExecutor) SetImages ¶
func (e *DockerPushExecutor) SetImages(images []string)
SetImages 设置要推送的镜像列表
func (*DockerPushExecutor) SetSkipPushedImages ¶
func (e *DockerPushExecutor) SetSkipPushedImages(pushed map[string]bool)
SetSkipPushedImages 设置已推送的镜像(这些将被跳过)
type DockerScanner ¶
type DockerScanner struct {
// contains filtered or unexported fields
}
DockerScanner Dockerfile 扫描器
func NewDockerScanner ¶
func NewDockerScanner(rootDir string, cfg *config.AutoScanConfig) *DockerScanner
NewDockerScanner 创建 Dockerfile 扫描器
func (*DockerScanner) Scan ¶
func (s *DockerScanner) Scan() ([]*DockerBuildExecutor, error)
Scan 扫描 Dockerfile 并返回构建执行器列表
type Executor ¶
type Executor interface {
// Execute 执行任务
// ctx: 上下文,用于取消操作
// handler: 输出处理函数,用于实时接收输出
Execute(ctx context.Context, handler OutputHandler) error
// Name 返回执行器名称
Name() string
// Type 返回执行器类型
Type() string
}
Executor 执行器接口
type GoBuildExecutor ¶
type GoBuildExecutor struct {
*BaseExecutor
// contains filtered or unexported fields
}
GoBuildExecutor Go 构建执行器
func NewGoBuildExecutor ¶
func NewGoBuildExecutor(taskName string, cfg config.TaskConfig) *GoBuildExecutor
NewGoBuildExecutor 创建 Go 构建执行器
func (*GoBuildExecutor) Execute ¶
func (e *GoBuildExecutor) Execute(ctx context.Context, handler OutputHandler) error
Execute 执行 Go 构建
type MavenExecutor ¶
type MavenExecutor struct {
*BaseExecutor
// contains filtered or unexported fields
}
MavenExecutor Maven 构建执行器
func NewMavenExecutor ¶
func NewMavenExecutor(taskName string, cfg config.TaskConfig) *MavenExecutor
NewMavenExecutor 创建 Maven 执行器
func (*MavenExecutor) Execute ¶
func (e *MavenExecutor) Execute(ctx context.Context, handler OutputHandler) error
Execute 执行 Maven 构建
type OutputHandler ¶
OutputHandler 输出处理函数类型 line: 输出行内容 isError: 是否为错误输出(stderr)
type Result ¶
type Result struct {
Success bool // 是否成功
Duration time.Duration // 执行耗时
Output string // 输出内容
Error error // 错误信息
ExitCode int // 退出码
StartTime time.Time // 开始时间
EndTime time.Time // 结束时间
}
Result 执行结果
type SSHExecutor ¶
type SSHExecutor struct {
*BaseExecutor
// contains filtered or unexported fields
}
SSHExecutor SSH 远程执行器
func NewSSHExecutor ¶
func NewSSHExecutor(taskName string, cfg config.TaskConfig, server *config.Server) (*SSHExecutor, error)
NewSSHExecutor 创建 SSH 执行器
func (*SSHExecutor) Execute ¶
func (e *SSHExecutor) Execute(ctx context.Context, handler OutputHandler) error
Execute 执行 SSH 命令
type ScriptRunner ¶
type ScriptRunner struct {
*CommandRunner
// contains filtered or unexported fields
}
ScriptRunner 脚本运行器
func NewScriptRunner ¶
func NewScriptRunner(name, scriptPath string) *ScriptRunner
NewScriptRunner 创建脚本运行器
func (*ScriptRunner) Execute ¶
func (r *ScriptRunner) Execute(ctx context.Context, handler OutputHandler) error
Execute 执行脚本