runnerfiles

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package runnerfiles transfers versioned files between the controller and standalone runners. It deliberately does not emulate a shared POSIX filesystem.

Index

Constants

View Source
const Missing = "missing"

Variables

View Source
var (
	ErrConflict = errors.New("file changed since the downloaded version")
	// SourceBusy means no conflicting publication happened: a source changed
	// while being snapshotted. Retry file synchronization, never the tool command.
	ErrSourceBusy = fmt.Errorf("source file is changing; retry synchronization: %w", ErrConflict)
	ErrLocked     = errors.New("file is leased by another execution")
	ErrPath       = errors.New("invalid or unauthorized file path")
	ErrDigest     = errors.New("file digest does not match")
	ErrLimit      = errors.New("file exceeds configured transfer limit")
)
View Source
var ErrUnavailable = errors.New("file service temporarily unavailable")

ErrUnavailable is a bounded, retryable file transport failure. It does not authorize replaying tool calls or ignoring a conflicting file version.

Functions

func Handler

func Handler(store *Store, authorize Authorize, commit CommitGuard) http.Handler

Handler is mounted outside the browser JWT middleware: Authorize validates a runner credential and binds every operation to its current execution attempt.

Types

type Authorize

type Authorize func(*http.Request, string, bool) (Plan, error)

type Client

type Client struct {
	BaseURL     string // controller origin, without /runner/v1/files
	Credential  string
	HTTP        *http.Client
	IdleTimeout time.Duration // default one minute without transfer progress
}

func (*Client) Download

func (c *Client) Download(ctx context.Context, session, mount string, entry Entry, destination string) error

func (*Client) Manifest

func (c *Client) Manifest(ctx context.Context, session, mount string) ([]Entry, error)

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, session, mount, rootPath string, entry Entry, expected string) error

type CommitGuard

type CommitGuard func(*http.Request, string, func() error) error

type Entry

type Entry struct {
	Path   string `json:"path"`
	Digest string `json:"digest"`
	Size   int64  `json:"size"`
	Mode   uint32 `json:"mode"`
}

type Mount

type Mount struct {
	Name     string   `json:"name"`
	Source   string   `json:"source"`
	Target   string   `json:"target"`
	Writable []string `json:"writable,omitempty"`
}

Source belongs to the controller; a runner must never interpret it as a host mount. Target is the absolute path presented inside its execution sandbox.

type Plan

type Plan struct {
	Mounts []Mount `json:"mounts"`
}

type Store

type Store struct {
	MaxBytes int64
	Now      func() time.Time
	// contains filtered or unexported fields
}

Store serializes publication within one controller. Atomic rename means readers see complete files; compare-and-swap prevents lost updates between runners. A single controller owns the workspace (matching ARTEX's existing architecture).

func NewStore

func NewStore() *Store

func (*Store) Lease

func (s *Store) Lease(m Mount, p, owner string, ttl time.Duration) (string, error)

func (*Store) Manifest

func (s *Store) Manifest(ctx context.Context, m Mount) ([]Entry, error)

func (*Store) Put

func (s *Store) Put(ctx context.Context, m Mount, p, expected, digest string, mode uint32, owner, lease string, body io.Reader, commitGuard func(func() error) error) (Entry, error)

Put validates an entire upload before acquiring the publication lock. A failed upload, canceled context, stale lease, or digest mismatch never replaces data. authorize is rechecked under the lock immediately before commit to fence a runner whose execution was revoked while it was uploading.

func (*Store) Read

func (s *Store) Read(m Mount, p, expected string, w io.Writer) (Entry, error)

Read pins the version before sending any bytes. The immutable snapshot also prevents in-place local writes from corrupting an otherwise valid download.

func (*Store) ReadContext

func (s *Store) ReadContext(ctx context.Context, m Mount, p, expected string, w io.Writer) (Entry, error)

func (*Store) Unlock

func (s *Store) Unlock(m Mount, p, owner, token string) error

type Syncer

type Syncer struct {
	Client  *Client
	Session string
	Plan    Plan
	Roots   map[string]string // mount name -> runner host cache, NOT sandbox target
	// contains filtered or unexported fields
}

Syncer owns one attempt's private host cache. Calls are serialized. Files are only published after their complete bytes have been verified; a conflict is an error, never last-writer-wins. Remote deletions do not erase local work.

func (*Syncer) Checkpoint added in v0.6.0

func (s *Syncer) Checkpoint(ctx context.Context) error

Checkpoint publishes stable files while commands may still be writing others. A real remote version conflict is still fatal. Close always uses strict Push.

func (*Syncer) Pull

func (s *Syncer) Pull(ctx context.Context) error

func (*Syncer) PullReadOnly

func (s *Syncer) PullReadOnly(ctx context.Context) error

PullReadOnly refreshes peer artifacts without replacing this execution's writable files. Use after the initial Pull, while commands may be running.

func (*Syncer) Push

func (s *Syncer) Push(ctx context.Context) error

Jump to

Keyboard shortcuts

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