matcha

package module
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2026 License: MIT Imports: 19 Imported by: 0

README

Matcha

Go library for deploying containerized applications with automatic SSL, zero-downtime updates, and SQLite backup management.

This is not a generic Docker orchestration tool. Matcha is purpose-built for deploying a specific stack: Caddy reverse proxy + Docker app container + SQLite database. It powers Fusionaly, Formlander, and Lognorth.

What it does

  • Deploys your app behind Caddy with automatic Let's Encrypt SSL
  • Blue-green deployments for zero downtime
  • SQLite backups with retention policies
  • Self-updating manager binaries
  • DNS validation during setup

Usage

Embed matcha in your project's CLI:

package main

import "github.com/karloscodes/matcha"

var version = "dev" // set via ldflags

func main() {
    m := matcha.New(matcha.Config{
        Name:           "myapp",
        AppImage:       "ghcr.io/user/myapp:latest",
        BlueGreen:      true,
        CronUpdates:    true,
        Backups:        true,
        ManagerRepo:    "user/myapp",       // GitHub repo for self-updates
        ManagerVersion: version,
    })

    // m.Install(), m.Update(), m.Status(), etc.
}

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackupFile

type BackupFile struct {
	Name       string
	Path       string
	BackupType BackupType
	CreatedAt  time.Time
	Size       int64
}

BackupFile represents a database backup file.

type BackupType

type BackupType string

BackupType represents the type of backup (daily, weekly, monthly).

const (
	BackupDaily   BackupType = "daily"
	BackupWeekly  BackupType = "weekly"
	BackupMonthly BackupType = "monthly"
)

type Config

type Config struct {
	// Required
	Name     string // "fusionaly" → env prefix FUSIONALY_, container names, etc.
	AppImage string // "karloscodes/fusionaly:latest"

	// Optional with defaults
	InstallDir string // default: /opt/{Name}
	BinaryPath string // default: /usr/local/bin/{Name}
	CaddyImage string // default: caddy:2-alpine
	HealthPath string // default: /_health
	AppPort    int    // default: 8080

	// Feature flags
	BlueGreen   bool // dual containers, zero-downtime switch
	CronUpdates bool // daily 3 AM auto-update cron job
	Backups     bool // SQLite backup with retention policy

	// Self-update configuration (see selfupdate.go for conventions)
	// When configured, Update() checks GitHub releases for newer versions
	// and downloads the new binary automatically.
	ManagerRepo    string // GitHub repo for releases, e.g., "karloscodes/fusionaly"
	ManagerVersion string // current version, e.g., "v1.4.37" (set via ldflags at build time)
}

Config defines how Matcha deploys your application.

type Matcha

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

Matcha is the main orchestrator for deployments.

func New

func New(cfg Config) *Matcha

New creates a new Matcha instance with the given configuration.

func (*Matcha) AppContainerName

func (m *Matcha) AppContainerName(slot int) string

AppContainerName returns the app container name(s).

func (*Matcha) BackupDB

func (m *Matcha) BackupDB() (string, error)

BackupDB creates a backup of the database and returns the backup path.

func (*Matcha) CaddyContainerName

func (m *Matcha) CaddyContainerName() string

CaddyContainerName returns the Caddy container name.

func (*Matcha) Deploy

func (m *Matcha) Deploy() error

Deploy triggers a deployment with current configuration.

func (*Matcha) EnvPrefix

func (m *Matcha) EnvPrefix() string

EnvPrefix returns the uppercase name used for environment variables.

func (*Matcha) Exec

func (m *Matcha) Exec(args ...string) error

Exec runs a command inside the app container.

func (*Matcha) GetConfig

func (m *Matcha) GetConfig() Config

GetConfig returns the current configuration.

func (*Matcha) GetDomain

func (m *Matcha) GetDomain() (string, error)

GetDomain reads the domain from the .env file.

func (*Matcha) Install

func (m *Matcha) Install() error

Install runs the full installation process.

func (*Matcha) NetworkName

func (m *Matcha) NetworkName() string

NetworkName returns the Docker network name.

func (*Matcha) Reload

func (m *Matcha) Reload() error

Reload restarts containers with current config (no image pull).

func (*Matcha) RestoreDB

func (m *Matcha) RestoreDB() error

RestoreDB lists backups and restores the selected one.

func (*Matcha) SaveImage

func (m *Matcha) SaveImage() error

SaveImage persists the current app image to the .env file.

func (*Matcha) SelfUpdate

func (m *Matcha) SelfUpdate() (bool, error)

SelfUpdate checks for a newer manager version and updates if available. Returns true if an update was performed.

func (*Matcha) SetImage

func (m *Matcha) SetImage(image string)

SetImage changes the app image for subsequent deployments.

func (*Matcha) StartSpinner

func (m *Matcha) StartSpinner(name string) *Spinner

StartSpinner creates and starts an animated spinner for a step.

func (*Matcha) Status

func (m *Matcha) Status() error

Status shows the current state of the deployment.

func (*Matcha) Update

func (m *Matcha) Update() error

Update pulls the latest image and performs a deployment. Also checks for manager self-updates if configured.

type RetentionConfig

type RetentionConfig struct {
	DailyDays   int // Keep daily backups for N days (default: 7)
	WeeklyDays  int // Keep weekly backups for N days (default: 14)
	MonthlyDays int // Keep monthly backups for N days (default: 90)
}

RetentionConfig defines the retention period for each backup type.

func DefaultRetention

func DefaultRetention() RetentionConfig

DefaultRetention returns sensible default retention values.

type Spinner

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

Spinner handles animated progress display.

func (*Spinner) Stop

func (s *Spinner) Stop(success bool)

Stop stops the spinner and shows success or failure.

Directories

Path Synopsis
Package testrunner provides utilities for running integration tests in isolated environments using OrbStack VMs.
Package testrunner provides utilities for running integration tests in isolated environments using OrbStack VMs.

Jump to

Keyboard shortcuts

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