Documentation
¶
Overview ¶
Package templatesource delivers the app template catalog to the agent from an external origin, so the catalog can change without rebuilding the binary. A Source produces the catalog in one uniform shape regardless of where it lives (the marketplace API today gated off, a GitHub repo as the working default); a Resolver picks the first available Source in priority order; a Syncer writes the chosen catalog into the on-disk template cache the deploy and listing paths already read. Infra and welcome content stays embedded in the binary and does not flow through here.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GitHubSource ¶
type GitHubSource struct {
// Repo is "owner/name", e.g. "flatrun/templates".
Repo string
// Ref is a branch, tag, or commit; "main" when empty.
Ref string
// Enabled gates the source from config.
Enabled bool
// BaseURL overrides the codeload host; tests point it at an httptest server.
BaseURL string
// Client is the HTTP client; a default with a timeout is used when nil.
Client *http.Client
}
GitHubSource delivers the catalog from a GitHub repository (flatrun/templates) by downloading its tarball and reading each directory that contains a docker-compose.yml as one template. It shells out to nothing: the fetch is a single HTTPS request extracted with the standard library, so the fetch mechanism is private to this source and swappable without touching callers.
func (GitHubSource) Name ¶
func (g GitHubSource) Name() string
type MarketplaceSource ¶
type MarketplaceSource struct {
// BaseURL is the marketplace API root, e.g. "https://api.flatrun.dev/api/v1".
BaseURL string
// Enabled gates the source from config.
Enabled bool
// Client is the HTTP client; a default with a timeout is used when nil.
Client *http.Client
}
MarketplaceSource delivers the catalog from the FlatRun marketplace agent-sync API (GET {base}/agent/templates). The marketplace stores compose and metadata inline, so a template arrives fully formed. Entries whose compose is empty are backed by an external git repo on the marketplace side and are skipped here; resolving those is a follow-up. This source is gated off by default until the marketplace API is declared ready; flipping the config flag makes it authoritative ahead of GitHub with no code change.
func (MarketplaceSource) List ¶
func (m MarketplaceSource) List(ctx context.Context) ([]Template, error)
func (MarketplaceSource) Name ¶
func (m MarketplaceSource) Name() string
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver holds sources in priority order (authoritative first, fallbacks after) and returns the catalog from the first one that succeeds.
func NewResolver ¶
NewResolver keeps the sources in the given order; earlier sources win.
func (*Resolver) Resolve ¶
Resolve returns the catalog from the first available source that lists successfully, along with that source's name. An available source that errors is skipped so a broken authoritative source still falls back to the next one; the first such error is returned only when every available source failed. When no source is available it returns (nil, "", nil) so the caller can keep whatever is already cached.
type Source ¶
type Source interface {
Name() string
Available(ctx context.Context) bool
List(ctx context.Context) ([]Template, error)
}
Source produces the app template catalog from one origin. Available reports whether the source is configured and worth trying; List returns the full catalog. A source that is configured but unreachable should return an error from List rather than reporting false from Available, so the Resolver can fall through to the next source.
type Syncer ¶
Syncer resolves the catalog and writes it into the on-disk template cache the deploy and listing paths read from. The cache is the durable store: once written it survives restarts and outages, and an operator can populate it by hand on an air-gapped host.
func (*Syncer) Sync ¶
Sync resolves the catalog and materializes it into CacheDir. It returns the source used and the number of templates written. When no source is available it leaves the cache untouched and returns ("", 0, nil) so a previously synced catalog survives an outage. Per-template write failures are skipped rather than aborting the whole sync.
type Template ¶
type Template struct {
ID string
Version string
Metadata []byte
Compose []byte
Files map[string][]byte
}
Template is one catalog entry in the shape the on-disk cache stores: a metadata.yml, a docker-compose.yml, and any extra files the template ships, keyed by their path relative to the template directory.