store

package
v0.4.6-beta.5 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package store defines data models and interfaces for persistence in dployr.

It models users, deployments, services, instances, and task results, and provides contract interfaces for interacting with persistent state. All concrete persistence implementations, including SQLite-backed stores, reside in the internal/store package.

Index

Constants

This section is empty.

Variables

View Source
var RoleLevel = map[Role]int{
	RoleOwner:     3,
	RoleAdmin:     2,
	RoleDeveloper: 1,
	RoleViewer:    0,
}

Functions

This section is empty.

Types

type Blueprint

type Blueprint struct {
	Name       string            `json:"name" db:"name"`
	Desc       string            `json:"description" db:"description"`
	Source     string            `json:"source" db:"source"`
	Runtime    RuntimeObj        `json:"runtime" db:"runtime"`
	Remote     RemoteObj         `json:"remote" db:"remote"`
	RunCmd     string            `json:"run_cmd,omitempty" db:"run_cmd"`
	BuildCmd   string            `json:"build_cmd,omitempty" db:"build_cmd"`
	Port       int               `json:"port" db:"port"`
	WorkingDir string            `json:"working_dir,omitempty" db:"working_dir"`
	StaticDir  string            `json:"static_dir,omitempty" db:"static_dir"`
	Image      string            `json:"image,omitempty" db:"image"`
	EnvVars    map[string]string `json:"env_vars,omitempty" db:"env_vars"`
	Status     string            `json:"status" db:"status"`
	ProjectID  *string           `json:"project_id,omitempty" db:"project_id"`
}

type Deployment

type Deployment struct {
	ID        string    `json:"id" db:"id"`
	UserId    *string   `json:"user_id,omitempty" db:"user_id"`
	Blueprint Blueprint `json:"config" db:"config"`
	Status    Status    `json:"status" db:"status"`
	Metadata  string    `json:"metadata" db:"metadata"`
	CreatedAt time.Time `json:"created_at" db:"created_at"`
	UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}

type DeploymentStore

type DeploymentStore interface {
	CreateDeployment(ctx context.Context, d *Deployment) error
	GetDeployment(ctx context.Context, id string) (*Deployment, error)
	ListDeployments(ctx context.Context, limit, offset int) ([]*Deployment, error)
	UpdateDeploymentStatus(ctx context.Context, id string, status string) error
}

type Instance

type Instance struct {
	ID              string    `json:"id" db:"id"`
	BootstrapToken  string    `json:"bootstrap_token" db:"bootstrap_token"`
	AccessToken     string    `json:"access_token" db:"access_token"`
	InstanceID      string    `json:"instance_id" db:"instance_id"`
	Issuer          string    `json:"issuer" db:"issuer"`
	Audience        string    `json:"audience" db:"audience"`
	RegisteredAt    time.Time `json:"registered_at" db:"registered_at"`
	LastInstalledAt time.Time `json:"last_installed_at" db:"last_installed_at"`
}

Instance table for this dployr server

type InstanceStore

type InstanceStore interface {
	// GetInstance returns the current instance record, if any.
	GetInstance(ctx context.Context) (*Instance, error)
	// RegisterInstance persists the instance row on first registration.
	RegisterInstance(ctx context.Context, i *Instance) error
	UpdateLastInstalledAt(ctx context.Context) error
	SetBootstrapToken(ctx context.Context, token string) error
	GetBootstrapToken(ctx context.Context) (string, error)
	SetAccessToken(ctx context.Context, token string) error
	GetAccessToken(ctx context.Context) (string, error)
}

InstanceStore provides access to the instance record stored in SQLite.

type RemoteObj

type RemoteObj struct {
	Url        string `json:"url" db:"url"`
	Branch     string `json:"branch" db:"branch"`
	CommitHash string `json:"commit_hash" db:"commit_hash"`
}

type Role

type Role string
const (
	RoleOwner     Role = "owner"     // uninstall dployr, manage admins
	RoleAdmin     Role = "admin"     // delete infrastructure, secrets, users, proxies; manage deployr versions; shell access
	RoleDeveloper Role = "developer" // deploy apps, view logs, view events, view resource graph
	RoleViewer    Role = "viewer"    // view services
)

owner > admin > developer > viewer

func (Role) IsPermitted

func (r Role) IsPermitted(required Role) bool

type Runtime

type Runtime string
const (
	RuntimeStatic Runtime = "static"
	RuntimeGo     Runtime = "golang"
	RuntimePHP    Runtime = "php"
	RuntimePython Runtime = "python"
	RuntimeNodeJS Runtime = "nodejs"
	RuntimeRuby   Runtime = "ruby"
	RuntimeDotnet Runtime = "dotnet"
	RuntimeJava   Runtime = "java"
	RuntimeDocker Runtime = "docker"
	RuntimeK3S    Runtime = "k3s"
	RuntimeCustom Runtime = "custom"
)

type RuntimeObj

type RuntimeObj struct {
	Type    Runtime `json:"type" db:"type" validate:"required,oneof=static golang php python nodejs ruby dotnet java docker k3s custom"`
	Version string  `json:"version,omitempty" db:"version"`
}

type Service

type Service struct {
	ID             string            `json:"id" db:"id"`
	Name           string            `json:"name" db:"name"`
	Description    string            `json:"description" db:"description"`
	Source         string            `json:"source" db:"source"`
	Runtime        Runtime           `json:"runtime" db:"runtime"`
	RuntimeVersion string            `json:"runtime_version,omitempty" db:"runtime_version"`
	RunCmd         string            `json:"run_cmd,omitempty" db:"run_cmd"`
	BuildCmd       string            `json:"build_cmd,omitempty" db:"build_cmd"`
	Port           int               `json:"port"`
	WorkingDir     string            `json:"working_dir,omitempty" db:"working_dir"`
	StaticDir      string            `json:"static_dir,omitempty" db:"static_dir"`
	Image          string            `json:"image,omitempty" db:"image"`
	EnvVars        map[string]string `json:"env_vars,omitempty"`
	Status         string            `json:"status"`
	Remote         string            `json:"remote,omitempty" db:"remote_url"`
	Branch         string            `json:"branch" db:"remote_branch"`
	CommitHash     string            `json:"commit_hash" db:"remote_commit_hash"`
	DeploymentId   string            `json:"-" db:"deployment_id"`
	Blueprint      *Blueprint        `json:"blueprint,omitempty"`
	CreatedAt      time.Time         `json:"created_at" db:"created_at"`
	UpdatedAt      time.Time         `json:"updated_at" db:"updated_at"`
}

type ServiceStore

type ServiceStore interface {
	CreateService(ctx context.Context, svc *Service) (*Service, error)
	GetService(ctx context.Context, id string) (*Service, error)
	ListServices(ctx context.Context, limit, offset int) ([]*Service, error)
	UpdateService(ctx context.Context, svc *Service) error
}

type Status

type Status string
const (
	StatusPending    Status = "pending"
	StatusInProgress Status = "in_progress"
	StatusFailed     Status = "failed"
	StatusCompleted  Status = "completed"
)

type TaskResult

type TaskResult struct {
	ID     string `db:"id"`
	Status string `db:"status"`
	Result any    `db:"result"`
	Error  string `db:"error"`
}

TaskResult represents the outcome of executing a remote task.

type TaskResultStore

type TaskResultStore interface {
	// ListUnsent returns all results that have not yet been marked as synced.
	ListUnsent(ctx context.Context) ([]*TaskResult, error)
	// SaveResults persists new task results as unsynced.
	SaveResults(ctx context.Context, results []*TaskResult) error
	// MarkSynced marks the given result IDs as synced.
	MarkSynced(ctx context.Context, ids []string) error
}

TaskResultStore provides access to persisted task results.

type User

type User struct {
	ID        string    `json:"id" db:"id"`
	Email     string    `json:"email" db:"email"`
	Role      Role      `json:"role" db:"role"`
	CreatedAt time.Time `json:"created_at" db:"created_at"`
	UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}

type UserStore

type UserStore interface {
	FindOrCreateUser(email string, role Role) (*User, error)
	GetUserByEmail(ctx context.Context, email string) (*User, error)
	UpdateUserRole(ctx context.Context, email string, role Role) error
	HasOwner() (bool, error) // Returns true if owner exists
	GetRole(ctx context.Context, email string) (Role, error)
}

Jump to

Keyboard shortcuts

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