target

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package target defines the execution environment abstraction for DevX sessions. A Target controls where a session's processes run: on the host, in a Docker container, or (future) in a VM or remote server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttachTmuxSession

func AttachTmuxSession(name string, sess *session.Session) error

AttachTmuxSession attaches the current terminal to the target's tmux session.

func BuildImage

func BuildImage(ctx context.Context, tag, contextDir string) error

BuildImage builds a Docker image from the given context directory.

func CheckAvailable

func CheckAvailable() error

CheckAvailable returns nil if Docker is running, or an error with a clear message.

func ContainerName

func ContainerName(sessionName string) string

ContainerName returns the Docker container name for a session.

func EnsureTmuxSession

func EnsureTmuxSession(name string, sess *session.Session) error

EnsureTmuxSession ensures the session's tmux environment exists for its target.

func ExecInSession

func ExecInSession(meta session.TargetMeta, cmd []string, interactive bool) *exec.Cmd

ExecInSession builds an exec.Cmd that runs a command in the session's execution environment. For host sessions it runs the command directly. For Docker sessions it wraps with docker exec.

The caller is responsible for setting Stdin/Stdout/Stderr and running the command.

func ImageExists

func ImageExists(image string) bool

ImageExists checks if a Docker image exists locally.

func IsDockerRunning

func IsDockerRunning(meta session.TargetMeta) bool

IsDockerRunning checks if a Docker container is alive.

func IsRunning

func IsRunning(meta session.TargetMeta) bool

IsRunning reports whether the target runtime needed for session commands is available.

func KillTmuxServer

func KillTmuxServer(meta session.TargetMeta) error

KillTmuxServer stops any target-owned tmux server; no-op when not applicable.

func NetworkName

func NetworkName(sessionName string) string

NetworkName returns the Docker network name for a session.

func ReprovisionGatepostSecrets

func ReprovisionGatepostSecrets(gp session.GatepostMeta, cfg GatepostRuntimeConfig)

ReprovisionGatepostSecrets checks if the proxy lost secrets (e.g. after a container restart) and re-runs provider bootstrap to restore them. cfg supplies trusted runtime config (logs command, root, etc.).

func RuntimeName

func RuntimeName(meta session.TargetMeta) string

RuntimeName returns a human-readable runtime identifier for status messages.

func SetGatepostBypass

func SetGatepostBypass(ctx context.Context, meta session.TargetMeta, bypass bool) error

SetGatepostBypass toggles the host-owned emergency egress bypass for the current Docker-backed Gatepost runtime. The command layer calls this helper rather than manipulating runtime internals directly.

func StartReadyTmuxSession

func StartReadyTmuxSession(name string, sess *session.Session) (func() error, error)

StartReadyTmuxSession starts a handoff without repeating target readiness checks.

Types

type DockerTarget

type DockerTarget struct{}

DockerTarget runs sessions inside Docker containers.

func (*DockerTarget) Start

func (d *DockerTarget) Start(ctx context.Context, opts StartOpts) (*StartResult, error)

func (*DockerTarget) Stop

func (d *DockerTarget) Stop(ctx context.Context, meta session.TargetMeta) error

func (*DockerTarget) Type

func (d *DockerTarget) Type() string

type GatepostRuntimeConfig

type GatepostRuntimeConfig struct {
	Root                     string
	LogsCommand              string
	ProviderBootstrapCommand string
	AuthHome                 string
	RequiredProviders        string
}

GatepostRuntimeConfig is the trusted host-side contract DevX passes to the Gatepost target. Executable command paths should come from trusted DevX configuration, never from workspace-controlled project files or env.

type GatepostTarget

type GatepostTarget struct{}

GatepostTarget runs a DevX session behind a Gatepost runtime. The initial runtime is Docker + mitmproxy, but the persisted metadata is intentionally framed as a Gatepost capability rather than a mitmproxy-specific contract.

func (*GatepostTarget) Start

func (g *GatepostTarget) Start(ctx context.Context, opts StartOpts) (*StartResult, error)

func (*GatepostTarget) Stop

func (*GatepostTarget) Type

func (g *GatepostTarget) Type() string

type HostTarget

type HostTarget struct{}

HostTarget is the default target — sessions run directly on the host. Start and Stop are no-ops since the host environment is always available.

func (*HostTarget) Start

func (h *HostTarget) Start(_ context.Context, _ StartOpts) (*StartResult, error)

func (*HostTarget) Stop

func (*HostTarget) Type

func (h *HostTarget) Type() string

type SecurityOpts

type SecurityOpts struct {
	MemoryLimit  string // e.g. "4g"
	CPULimit     string // e.g. "2"
	PidsLimit    int
	ReadOnlyRoot bool
	CapDrop      []string // capabilities to drop
	NoNewPrivs   bool
	TmpfsMounts  []string // tmpfs paths when read-only root is on
}

SecurityOpts holds container security configuration.

func DefaultSecurityOpts

func DefaultSecurityOpts() SecurityOpts

DefaultSecurityOpts returns sane security defaults for Docker containers.

type SessionOperator

type SessionOperator interface {
	// IsRunning reports whether the runtime needed for session commands is available.
	IsRunning(meta session.TargetMeta) bool
	// EnsureTmuxSession ensures the session's tmux environment exists.
	EnsureTmuxSession(name string, sess *session.Session) error
	// AttachTmuxSession ensures readiness and attaches the current terminal.
	AttachTmuxSession(name string, sess *session.Session) error
	// StartReadyTmuxSession starts an already-ensured handoff and returns its waiter.
	StartReadyTmuxSession(name string, sess *session.Session) (func() error, error)
	// KillTmuxServer stops any target-owned tmux server; no-op when not applicable.
	KillTmuxServer(meta session.TargetMeta) error
}

SessionOperator owns tmux/session UX operations for a target runtime. It is deliberately separate from Target so future runtimes can keep lifecycle concerns independent from how DevX attaches terminals to sessions.

func ResolveSessionOperator

func ResolveSessionOperator(meta session.TargetMeta) (SessionOperator, error)

type StartOpts

type StartOpts struct {
	SessionName    string
	WorktreePath   string
	HostPorts      map[string]int // service name -> host port to publish
	Image          string
	Env            map[string]string
	Labels         map[string]string
	Security       SecurityOpts
	GatepostConfig GatepostRuntimeConfig
}

StartOpts contains everything a target needs to create a session environment.

type StartResult

type StartResult struct {
	Meta session.TargetMeta
}

StartResult is returned by Target.Start with metadata to persist.

type Target

type Target interface {
	// Type returns the target identifier ("host", "docker", etc.)
	Type() string
	// Start creates and starts the execution environment for a session.
	Start(ctx context.Context, opts StartOpts) (*StartResult, error)
	// Stop tears down the execution environment. Must be idempotent.
	Stop(ctx context.Context, meta session.TargetMeta) error
}

Target is the interface that isolation backends implement.

func Resolve

func Resolve(targetType string) (Target, error)

Resolve returns the Target implementation for the given type string.

Jump to

Keyboard shortcuts

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