cook

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCloneFailed      = errors.New("git clone failed")
	ErrInvalidCommit    = errors.New("invalid commit hash")
	ErrWorkDirNotSet    = errors.New("work directory not set")
	ErrRepositoryNotSet = errors.New("repository URL not set")
	ErrAuthFailed       = errors.New("authentication failed")
)

Functions

This section is empty.

Types

type AuthConfig

type AuthConfig struct {
	Type             string // "basic", "ssh-key", "ssh-agent"
	Username         string
	Password         string
	SSHKey           string
	SSHKeyPassphrase string
}

AuthConfig defines authentication options for git operations.

type Config

type Config struct {
	ID       string
	URL      string // empty for push-only mode
	Branch   string
	WorkDir  string
	Logger   *ll.Logger
	Auth     AuthConfig
	Metrics  *Metrics
	KeepLast int
}

Config defines the configuration for a Cook instance.

type Cook

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

Cook handles atomic git-based deployments with zero downtime. In push-only mode (URL == ""), Cook does not clone — it serves content written directly to the work directory via webhook.

func New

func New(cfg Config) (*Cook, error)

New creates a Cook instance. URL may be empty for push-only mode, in which case Make must never be called.

func (*Cook) Cleanup

func (c *Cook) Cleanup(keep int) error

Cleanup removes old deployments keeping current + specified count.

func (*Cook) CollectMetrics

func (c *Cook) CollectMetrics() Metrics

CollectMetrics returns a snapshot of current metrics (if configured).

func (*Cook) CurrentCommit

func (c *Cook) CurrentCommit() string

CurrentCommit returns the commit hash of the active deployment. Returns empty string in push-only mode.

func (*Cook) CurrentPath

func (c *Cook) CurrentPath() string

CurrentPath returns the filesystem path currently being served. For pull/both mode this is the most recent deployment directory. For push-only mode this is the work directory set by SetCurrentPath.

func (*Cook) ListDeployments

func (c *Cook) ListDeployments() ([]Deployment, error)

ListDeployments returns all available deployment commits sorted newest first.

func (*Cook) Make

func (c *Cook) Make(ctx context.Context) error

Make performs an atomic deployment from the configured repository. Must not be called in push-only mode (URL == "").

func (*Cook) Rollback

func (c *Cook) Rollback(commitHash string) error

Rollback switches to a previous deployment by commit hash.

func (*Cook) SetCurrentPath

func (c *Cook) SetCurrentPath(path string)

SetCurrentPath sets the serving path directly without a deployment. Used exclusively by push-only mode so CurrentPath returns immediately rather than blocking on a clone that will never happen.

type Deployment

type Deployment struct {
	Commit    string
	Path      string
	CreatedAt time.Time
}

Deployment represents a single deployed version.

type Entry

type Entry struct {
	Cook   *Cook
	Config alaye.Git
	// contains filtered or unexported fields
}

type HealthStatus

type HealthStatus struct {
	State       string `json:"state"`
	CurrentPath string `json:"current_path"`
	Commit      string `json:"commit"`
	Deployments int    `json:"deployments"`
}

type Manager

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

func NewManager

func NewManager(cfg ManagerConfig) (*Manager, error)

func (*Manager) CurrentPath

func (m *Manager) CurrentPath(routeKey string) string

func (*Manager) GetCook

func (m *Manager) GetCook(routeKey string) (*Cook, bool)

func (*Manager) HandleWebhook

func (m *Manager) HandleWebhook(w http.ResponseWriter, r *http.Request, routeKey string)

func (*Manager) Health

func (m *Manager) Health() map[string]HealthStatus

func (*Manager) Prune

func (m *Manager) Prune(activeIDs map[string]bool)

func (*Manager) Register

func (m *Manager) Register(routeKey string, cfg alaye.Git) error

func (*Manager) Stop

func (m *Manager) Stop()

func (*Manager) Unregister

func (m *Manager) Unregister(routeKey string)

func (*Manager) WebhookHandler

func (m *Manager) WebhookHandler(routeKey string) http.HandlerFunc

type ManagerConfig

type ManagerConfig struct {
	WorkDir expect.Folder
	Pool    *jack.Pool
	Logger  *ll.Logger
}

type Metrics

type Metrics struct {
	DeploymentsTotal   atomic.Int64
	DeploymentErrors   atomic.Int64
	DeploymentDuration atomic.Int64
	LastDeploymentTime atomic.Value
}

Metrics tracks deployment statistics.

type WebhookPayload

type WebhookPayload struct {
	Ref        string `json:"ref"`
	Before     string `json:"before"`
	After      string `json:"after"`
	Repository struct {
		CloneURL string `json:"clone_url"`
	} `json:"repository"`
}

Jump to

Keyboard shortcuts

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