package runtime
import (
"context"
"fmt"
)
type ContainerRuntime interface {
Name() string
Create(ctx context.Context, cfg *CreateConfig) (containerID string, err error)
Wait(ctx context.Context, containerID string) (*ContainerStatus, error)
Delete(ctx context.Context, containerID string, timeoutSeconds int64) error
Close() error
}
type CreateConfig struct {
ID string
Sandbox string
Rootfs RootfsConfig
Command []string
Envs map[string]string
Mounts []MountConfig
CPUMillicore float64
MemoryMB float64
Stdout string
Stderr string
ExtraConfig string
MakeSeed bool
Network string
Ports []string
}
type MountConfig struct {
Type string
Source string
Target string
Options []string
}
type RootfsConfig struct {
Readonly bool
Type RootfsSrcType
ImageURL string
S3 *S3Config
}
type RootfsSrcType int
const (
RootfsSrcS3 RootfsSrcType = 0
RootfsSrcImage RootfsSrcType = 1
)
type S3Config struct {
Endpoint string
Bucket string
Object string
AccessKeyID string
AccessKeySecret string
}
type ContainerStatus struct {
StatusCode int32
ExitCode int32
Message string
}
func NewRuntime(backend string, cfg map[string]string) (ContainerRuntime, error) {
switch backend {
case "docker":
return NewDockerRuntime(cfg)
case "podman":
return NewPodmanRuntime(cfg)
default:
return nil, fmt.Errorf("不支持的运行时后端: %s (可选: docker, podman)", backend)
}
}