scaffold

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllInstanceNames added in v0.2.0

func AllInstanceNames(cfg *InfraConfig) []string

AllInstanceNames returns the names of all deployed instances.

func AllNames added in v0.2.0

func AllNames(instances []Instance) []string

AllNames returns names from a slice of instances.

func BuildImage added in v0.2.0

func BuildImage(name, source string) (string, error)

BuildImage builds a Docker image locally and saves it as a gzipped tarball. Returns the path to the tarball, or empty string if local Docker is unavailable.

func BuildSourceImages added in v0.2.0

func BuildSourceImages(services []string, specs map[string]ServiceSpec) (map[string]string, error)

BuildSourceImages builds Docker images for all source-based services.

func CountInstances added in v0.2.0

func CountInstances(cfg *InfraConfig) int

func DeployToInstance added in v0.2.0

func DeployToInstance(
	p *platform.Platform,
	imagePaths map[string]string,
	cfg *InfraConfig,
	serverType string,
	inst *Instance,
	region platform.Region,
) error

DeployToInstance deploys services to a specific instance.

func ExpandEnv added in v0.2.0

func ExpandEnv(s string) string

func ExtractPackages

func ExtractPackages(targetDir, newModule string, packages []string) error

ExtractPackages copies framework packages from the embedded pkg/ source into targetDir/internal/<package>/, rewriting imports to the new module path.

func InitProviders added in v0.2.0

func InitProviders(cfg *InfraConfig) (map[string]*platform.Platform, error)

InitProviders creates a platform client for each named platform in the config.

func ProviderFor added in v0.2.0

func ProviderFor(providers map[string]*platform.Platform, cfg *InfraConfig, serverType string) *platform.Platform

ProviderFor returns the platform for a specific server type.

func RenderApp

func RenderApp(targetDir string, data Data) error

RenderApp renders only the app subdirectory (controllers/, models/, views/, main.go) for adding a new app to an existing project.

func RenderProject

func RenderProject(targetDir string, data Data) error

RenderProject walks res/scaffold/ and writes files into targetDir.

Routing rules:

  • res/scaffold/web/ → targetDir/<Dir>/
  • res/scaffold/<path> → targetDir/<path>

Files ending in .tmpl are executed as text/template with <<>> delimiters and written with the .tmpl suffix stripped. All other files are copied verbatim.

func SafeName added in v0.2.0

func SafeName(s string) bool

SafeName validates a name contains only safe characters (no path separators).

func SafePath added in v0.2.0

func SafePath(s string) bool

SafePath validates an absolute path for shell interpolation (no .., must start with /).

func SafeRelPath added in v0.2.0

func SafeRelPath(s string) bool

SafeRelPath validates a relative path for setup scripts (no .., no leading /).

func SyncSecrets added in v0.2.0

func SyncSecrets(server *platform.Server, services map[string]ServiceSpec)

SyncSecrets pushes local env vars to the server for empty env_files.

Types

type Data

type Data struct {
	Name          string
	Module        string
	Dir           string // app subdirectory (default: "web")
	WithFrontend  bool
	WithAssistant bool
	WithPlatform  bool
	WithDatabase  bool
}

Data holds template variables for scaffold rendering.

type InfraConfig added in v0.2.0

type InfraConfig struct {
	Platforms map[string]PlatformConfig `json:"platforms"`
	Servers   map[string]ServerSpec     `json:"servers"`
	Services  map[string]ServiceSpec    `json:"services,omitempty"`
	Instances map[string][]Instance     `json:"instances,omitempty"`
}

InfraConfig defines the complete infrastructure for a project.

Schema (infra.json):

{
  "platforms": { "<name>": { provider, token?, region? } }
  "servers":   { "<type>": { platform, size, setup?, volumes?, services } }
  "services":  { "<name>": { image|source, setup?, ports, volumes?, env?, env_files?, network?, healthcheck? } }
  "instances": { "<type>": [{ id, name, ip, region? }] }
}

Volume references: Service volume sources and env values support $volume-name syntax. A server volume {"name": "data", "mount": "/mnt/data"} can be referenced as "$data/app" which expands to "/mnt/data/app" at deploy time.

func LoadInfraConfig added in v0.2.0

func LoadInfraConfig(projectDir string) (*InfraConfig, error)

LoadInfraConfig reads and validates infra.json from the given directory.

func (*InfraConfig) AllInstances added in v0.2.0

func (cfg *InfraConfig) AllInstances() []Instance

func (*InfraConfig) PlatformFor added in v0.2.0

func (cfg *InfraConfig) PlatformFor(serverType string) PlatformConfig

PlatformFor returns the PlatformConfig for a server type.

func (*InfraConfig) PlatformNameFor added in v0.2.0

func (cfg *InfraConfig) PlatformNameFor(serverType string) string

PlatformNameFor returns the platform key for a server type. Falls back to the first (or only) key if the server has no explicit platform.

func (*InfraConfig) Save added in v0.2.0

func (cfg *InfraConfig) Save(projectDir string) error

type Instance added in v0.2.0

type Instance struct {
	ID     string `json:"id,omitempty"`
	Name   string `json:"name"`
	IP     string `json:"ip,omitempty"`
	Region string `json:"region,omitempty"`
}

func CreateInstance added in v0.2.0

func CreateInstance(p *platform.Platform, name string, spec ServerSpec, region string) (*Instance, error)

CreateInstance provisions a new server and waits for SSH.

func FindInstance added in v0.2.0

func FindInstance(cfg *InfraConfig, name string) (*Instance, string, error)

FindInstance looks up an instance by name across all server types.

func FindInstanceOrDefault added in v0.2.0

func FindInstanceOrDefault(cfg *InfraConfig, name string) (*Instance, error)

FindInstanceOrDefault returns the named instance, or the only instance if name is empty.

func (*Instance) ToServer added in v0.2.0

func (inst *Instance) ToServer() *platform.Server

ToServer converts an Instance to a platform.Server for SSH operations.

type MultipleInstancesError added in v0.2.0

type MultipleInstancesError struct {
	Instances []Instance
}

MultipleInstancesError is returned when an instance must be specified but multiple exist.

func (*MultipleInstancesError) Error added in v0.2.0

func (e *MultipleInstancesError) Error() string

type PlatformConfig added in v0.2.0

type PlatformConfig struct {
	Provider string `json:"provider"`        // "congo" or "metal"
	Token    string `json:"token,omitempty"` // API token (supports $ENV_VAR)
	Region   string `json:"region,omitempty"`

	RawToken string `json:"-"`
}

type PortSpec added in v0.2.0

type PortSpec struct {
	Host      int    `json:"host"`
	Container int    `json:"container"`
	Bind      string `json:"bind,omitempty"`
}

type ServerSpec added in v0.2.0

type ServerSpec struct {
	Platform string       `json:"platform,omitempty"` // key into Platforms map
	Size     string       `json:"size"`
	Setup    string       `json:"setup,omitempty"` // relative path to setup script
	Volumes  []VolumeSpec `json:"volumes,omitempty"`
	Services []string     `json:"services,omitempty"`
}

type ServiceSpec added in v0.2.0

type ServiceSpec struct {
	Image       string            `json:"image,omitempty"`
	Source      string            `json:"source,omitempty"`
	Setup       string            `json:"setup,omitempty"` // relative path to setup script (runs on host before container)
	Command     []string          `json:"command,omitempty"`
	Ports       []PortSpec        `json:"ports,omitempty"`
	Volumes     []VolumeMount     `json:"volumes,omitempty"`
	Env         map[string]string `json:"env,omitempty"`
	EnvFiles    map[string]string `json:"env_files,omitempty"`
	Network     string            `json:"network,omitempty"`
	Healthcheck string            `json:"healthcheck,omitempty"`
	Privileged  bool              `json:"privileged,omitempty"`
}

type VolumeMount added in v0.2.0

type VolumeMount struct {
	Source string `json:"source"`
	Target string `json:"target"`
}

type VolumeSpec added in v0.2.0

type VolumeSpec struct {
	Name  string `json:"name"`
	Size  int    `json:"size"`
	Mount string `json:"mount"`
}

Jump to

Keyboard shortcuts

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