agent

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MPL-2.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DockerlessEnvVar          = "DOCKERLESS"
	DockerlessContextEnvVar   = "DOCKERLESS_CONTEXT"
	DefaultImageConfigPath    = "/.dockerless/image.json"
	DockerlessCredentialsPath = "/.dockerless/.docker" // #nosec G101 -- not a credential

)
View Source
const ContainerAgentEnvPrefix = EnvAgentInContainer + "=" + EnvAgentInContainerTrue + " "

ContainerAgentEnvPrefix is the inline env-var assignment SSH command builders prepend to the shell snippet that launches `devsy agent ...` inside the workspace container or machine. POSIX shells parse leading `NAME=value cmd ...` as a one-shot environment assignment for `cmd`, so this works without requiring the SSH server to honour SetEnv (which is often disabled).

View Source
const DefaultInactivityTimeout = time.Minute * 20
View Source
const EnvAgentInContainer = "DEVSY_AGENT_IN_CONTAINER"

EnvAgentInContainer is set to "1" by every SSH command builder that launches `devsy agent ...` inside the workspace container or machine. It is the single signal used by IsHostAgentInvocation to distinguish a container-side invocation from a host-side one. The host never sets it.

View Source
const EnvAgentInContainerTrue = "1"

EnvAgentInContainerTrue is the value the env var takes when set.

Variables

View Source
var (
	ErrBinaryNotFound = errors.New("agent binary not found")
	ErrInjectTimeout  = errors.New("injection timeout")
	ErrArchMismatch   = errors.New("architecture mismatch")
)
View Source
var ErrFindAgentHomeFolder = fmt.Errorf("couldn't find devsy home directory")

Functions

func AgentCommandEnvPrefix added in v1.3.1

func AgentCommandEnvPrefix(isLocal bool) string

AgentCommandEnvPrefix omits the container env prefix when the command will be executed on the host (provider agent.local=true); prepending it there would mislabel the host process and trip IsHostAgentInvocation's stale-env warning.

func Bool

func Bool(b bool) *bool

func CloneRepositoryForWorkspace

func CloneRepositoryForWorkspace(
	ctx context.Context,
	source *provider2.WorkspaceSource,
	agentConfig *provider2.ProviderAgentConfig,
	workspaceDir, helper string,
	options provider2.CLIOptions,
	overwriteContent bool,
) error

func CreateAgentWorkspaceDir

func CreateAgentWorkspaceDir(agentFolder, context, workspaceID string) (string, error)

func CreateWorkspaceBusyFile

func CreateWorkspaceBusyFile(folder string)

func DecodeContainerWorkspaceInfo

func DecodeContainerWorkspaceInfo(
	workspaceInfoRaw string,
) (*provider2.ContainerWorkspaceInfo, string, error)

func DecodeWorkspaceInfo

func DecodeWorkspaceInfo(workspaceInfoRaw string) (*provider2.AgentWorkspaceInfo, string, error)

func DeleteWorkspaceBusyFile

func DeleteWorkspaceBusyFile(folder string)

func DockerlessBuild

func DockerlessBuild(opts DockerlessBuildOptions) error

func FindAgentHomeFolder

func FindAgentHomeFolder(agentFolder string) (string, error)

func GetAgentBinariesDir

func GetAgentBinariesDir(agentFolder, context, workspaceID string) (string, error)

func GetAgentBinariesDirFromWorkspaceDir

func GetAgentBinariesDirFromWorkspaceDir(workspaceDir string) (string, error)

func GetAgentDaemonLogFolder

func GetAgentDaemonLogFolder(agentFolder string) (string, error)

GetAgentDaemonLogFolder returns the folder that holds agent-daemon.log. The daemon is a container/machine-side process: it is started by the inject-and-run path during `devsy up` and the SSH command builder sets DEVSY_AGENT_IN_CONTAINER=1. A host-side invocation has no daemon to inspect and therefore is rejected explicitly instead of silently resolving to the legacy `<DEVSY_HOME>/agent` glob.

func GetAgentWorkspaceContentDir

func GetAgentWorkspaceContentDir(workspaceDir string) string

func GetAgentWorkspaceDir

func GetAgentWorkspaceDir(agentFolder, context, workspaceID string) (string, error)

func GetDockerlessBuildContext

func GetDockerlessBuildContext() string

func HasWorkspaceBusyFile

func HasWorkspaceBusyFile(folder string) bool

func ImageConfigExists

func ImageConfigExists(path string) bool

func InjectAgent

func InjectAgent(opts *InjectOptions) error

func IsDockerlessEnabled

func IsDockerlessEnabled() bool

func IsHostAgentInvocation added in v1.3.1

func IsHostAgentInvocation(agentFolder string) bool

func ParseAgentWorkspaceInfo

func ParseAgentWorkspaceInfo(workspaceConfigFile string) (*provider2.AgentWorkspaceInfo, error)

func PrepareAgentHomeFolder

func PrepareAgentHomeFolder(agentFolder string) (string, error)

func ReadAgentWorkspaceInfo

func ReadAgentWorkspaceInfo(
	agentFolder, context, id string,
) (bool, *provider2.AgentWorkspaceInfo, error)

func Tunnel

func Tunnel(ctx context.Context, opts TunnelOptions) error

func WorkspaceInfo

func WorkspaceInfo(
	workspaceInfoEncoded string,
) (bool, *provider2.AgentWorkspaceInfo, error)

func WriteWorkspaceInfo

func WriteWorkspaceInfo(
	workspaceInfoEncoded string,
) (bool, *provider2.AgentWorkspaceInfo, error)

func WriteWorkspaceInfoAndDeleteOld

func WriteWorkspaceInfoAndDeleteOld(
	workspaceInfoEncoded string,
	deleteWorkspace func(workspaceInfo *provider2.AgentWorkspaceInfo) error,
) (bool, *provider2.AgentWorkspaceInfo, error)

Types

type BinaryCache

type BinaryCache struct {
	BaseDir string
}

func (*BinaryCache) Get

func (c *BinaryCache) Get(arch string) (io.ReadCloser, error)

func (*BinaryCache) ReadVersion added in v1.3.1

func (c *BinaryCache) ReadVersion(arch string) string

func (*BinaryCache) Set

func (c *BinaryCache) Set(arch string, data io.Reader) error

func (*BinaryCache) WriteVersion added in v1.3.1

func (c *BinaryCache) WriteVersion(arch, ver string)

type BinaryManager

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

func NewBinaryManager

func NewBinaryManager(downloadURL string) (*BinaryManager, error)

func (*BinaryManager) AcquireBinary

func (m *BinaryManager) AcquireBinary(ctx context.Context, arch string) (io.ReadCloser, error)

type BinarySource

type BinarySource interface {
	GetBinary(ctx context.Context, arch string) (io.ReadCloser, error)
	SourceName() string
}

type ConfigureCredentialsFunc

type ConfigureCredentialsFunc func(context.Context) (string, error)

type DockerlessBuildOptions

type DockerlessBuildOptions struct {
	Context                  context.Context
	SetupInfo                *config.Result
	DockerlessOptions        *provider2.ProviderDockerlessOptions
	ImageConfigOutput        string
	Debug                    bool
	ConfigureCredentialsFunc ConfigureCredentialsFunc
}

type Exec

type Exec func(
	ctx context.Context, user string, command string,
	stdin io.Reader, stdout io.Writer, stderr io.Writer,
) error

type FileCacheSource

type FileCacheSource struct {
	Cache           *BinaryCache
	ExpectedVersion string
}

func (*FileCacheSource) GetBinary

func (s *FileCacheSource) GetBinary(ctx context.Context, arch string) (io.ReadCloser, error)

func (*FileCacheSource) SourceName

func (s *FileCacheSource) SourceName() string

type HTTPDownloadSource

type HTTPDownloadSource struct {
	BaseURL string
	Cache   *BinaryCache
	Version string
}

func (*HTTPDownloadSource) GetBinary

func (s *HTTPDownloadSource) GetBinary(ctx context.Context, arch string) (io.ReadCloser, error)

func (*HTTPDownloadSource) SourceName

func (s *HTTPDownloadSource) SourceName() string

type InjectError

type InjectError struct {
	Stage InjectStage
	Cause error
}

func (*InjectError) Error

func (e *InjectError) Error() string

func (*InjectError) Unwrap

func (e *InjectError) Unwrap() error

type InjectOptions

type InjectOptions struct {
	// Ctx is the context for the injection operation. Required.
	Ctx context.Context
	// Exec is the function used to execute commands on the remote machine. Required.
	Exec inject.ExecFunc

	// IsLocal indicates if the injection target is the local machine.
	IsLocal bool
	// RemoteAgentPath is the path where the agent binary should be placed on the remote machine.
	// Defaults to config.RemoteDevsyHelperLocation.
	RemoteAgentPath string
	// DownloadURL is the base URL to download the agent binary from. Defaults to config.DefaultAgentDownloadURL().
	DownloadURL string
	// PreferDownloadFromRemoteUrl forces downloading the agent even if a local binary is available.
	// Defaults to true for release versions, false for dev versions.
	PreferDownloadFromRemoteUrl *bool
	// Timeout is the maximum duration to wait for the injection to complete. Defaults to 5 minutes.
	Timeout time.Duration

	// Command is the command to execute after successful injection.
	Command string

	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer

	// LocalVersion is the version of the local Devsy binary.
	// Defaults to version.GetVersion().
	LocalVersion string
	// RemoteVersion is the expected version of the remote agent.
	// Defaults to LocalVersion.
	RemoteVersion string
	// SkipVersionCheck disables the validation of the remote agent's version.
	// Defaults to false, unless DEVSY_AGENT_URL is set.
	SkipVersionCheck bool
}

InjectOptions defines the parameters for injecting the Devsy agent into a remote environment.

func (*InjectOptions) ApplyDefaults

func (o *InjectOptions) ApplyDefaults()

func (*InjectOptions) Validate

func (o *InjectOptions) Validate() error

type InjectSource

type InjectSource struct{}

func (*InjectSource) GetBinary

func (s *InjectSource) GetBinary(ctx context.Context, arch string) (io.ReadCloser, error)

func (*InjectSource) SourceName

func (s *InjectSource) SourceName() string

type InjectStage

type InjectStage string
const (
	InjectStageInject           InjectStage = "inject"
	InjectStageCommandExecution InjectStage = "command execution"
	InjectStageVersionCheck     InjectStage = "version check"
)

type TunnelOptions added in v1.3.1

type TunnelOptions struct {
	Exec    Exec
	User    string
	Stdin   io.Reader
	Stdout  io.Writer
	Stderr  io.Writer
	Timeout time.Duration
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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