appdef

package
v0.0.35 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2025 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// JsonFileName defines the file name of the app manifest,
	// that should appear in the root of each webkit dir.
	JsonFileName = "app.json"
)

Variables

Commands defines all the Commands available that should be run in order.

Functions

func ParseResourceReference added in v0.0.15

func ParseResourceReference(value any) (resourceName, outputName string, ok bool)

ParseResourceReference parses a resource reference string (e.g., "db.connection_url").

Resource references follow the format: "resource_name.output_name".

Types

type App

type App struct {
	Name             string                  `json:"name"`
	Title            string                  `json:"title"`
	Type             AppType                 `json:"type"`
	Description      string                  `json:"description,omitempty"`
	Path             string                  `json:"path"`
	Build            Build                   `json:"build"`
	Infra            Infra                   `json:"infra"`
	Env              Environment             `json:"env"`
	UsesNPM          *bool                   `json:"usesNPM"`
	TerraformManaged *bool                   `json:"terraformManaged,omitempty"`
	Domains          []Domain                `json:"domains,omitzero"`
	Commands         map[Command]CommandSpec `json:"commands,omitzero" jsonschema:"oneof_type=boolean;object;string" inline:"true"`
}

func (*App) IsTerraformManaged added in v0.0.8

func (a *App) IsTerraformManaged() bool

IsTerraformManaged returns whether this app should be managed by Terraform. It defaults to true when the field is nil or explicitly set to true.

func (*App) Language

func (a *App) Language() string

Language determines what language ecosystem a given app is. Either "go" or "js".

func (*App) MergeEnvironments

func (a *App) MergeEnvironments(shared Environment) Environment

MergeEnvironments merges the shared env with the apps, with the app specific variables taking precedence.

func (*App) OrderedCommands

func (a *App) OrderedCommands() []CommandSpec

OrderedCommands returns the app's commands in canonical order with Name populated.

func (*App) PrimaryDomain added in v0.0.19

func (a *App) PrimaryDomain() string

PrimaryDomain returns the primary domain for this app. It first looks for a domain with type "primary" in the Domains array. If no primary domain is found, it returns the first domain in the array. If the Domains array is empty, it returns an empty string.

func (*App) ShouldRelease added in v0.0.10

func (a *App) ShouldRelease() bool

ShouldRelease returns whether this app should be built and released in CI/CD. It defaults to true when the field is nil or explicitly set to true.

func (*App) ShouldUseNPM

func (a *App) ShouldUseNPM() bool

ShouldUseNPM returns whether this app should be included in pnpm workspace. It checks the UsesNPM field first, and if not set, defaults based on Language().

type AppType

type AppType string

AppType defines the type of application being run.

const (
	AppTypeSvelteKit AppType = "svelte-kit"
	AppTypeGoLang    AppType = "golang"
	AppTypePayload   AppType = "payload"
)

AppType constants.

func (AppType) String

func (a AppType) String() string

String implements fmt.Stringer on the AppType.

type Build

type Build struct {
	Dockerfile string `json:"dockerfile"`
	Port       int    `json:"port,omitempty"`
	Release    *bool  `json:"release,omitempty"`
}

type Command

type Command string

Command defines the type of action that will be actioned.

const (
	CommandLint   Command = "lint"
	CommandTest   Command = "test"
	CommandFormat Command = "format"
	CommandBuild  Command = "build"
)

Command constants.

func (Command) String

func (c Command) String() string

String implements fmt.Stringer on Command.

type CommandSpec

type CommandSpec struct {
	Name     string `json:"-"`
	Cmd      string `json:"command,omitempty"`
	SkipCI   bool   `json:"skip_ci,omitempty"`
	Timeout  string `json:"timeout,omitempty"`
	Disabled bool   `json:"-"` // Set during unmarshal
}

CommandSpec defines an action for an App, this can run in CI or locally.

func (*CommandSpec) JSONSchemaOneOf

func (*CommandSpec) JSONSchemaOneOf() []interface{}

JSONSchemaOneOf returns the polymorphic schema options.

func (*CommandSpec) UnmarshalJSON

func (c *CommandSpec) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler to

type Contact

type Contact struct {
	Email       string
	Phone       string
	Coordinates struct{ Latitude, Longitude string }
	Address     schemaorg.Address
}

type Definition

type Definition struct {
	WebkitVersion string     `json:"webkit_version"`
	Project       Project    `json:"project"`
	Shared        Shared     `json:"shared"`
	Resources     []Resource `json:"resources"`
	Apps          []App      `json:"apps"`
}

func Read

func Read(root afero.Fs) (*Definition, error)

func (*Definition) ApplyDefaults

func (d *Definition) ApplyDefaults() error

ApplyDefaults ensures all required defaults are set on the Definition. This should be called after unmarshaling and before validation.

func (*Definition) ContainsGo

func (d *Definition) ContainsGo() bool

ContainsGo returns true if any of the apps are marked as Go.

func (*Definition) ContainsJS

func (d *Definition) ContainsJS() bool

ContainsJS returns true if any of the apps are marked as JS.

func (*Definition) FilterTerraformManaged added in v0.0.8

func (d *Definition) FilterTerraformManaged() (*Definition, SkippedItems)

FilterTerraformManaged creates a filtered copy of the Definition containing only apps and resources that are managed by Terraform.

Returns the filtered definition and information about what was skipped.

func (*Definition) GetAppsByType added in v0.0.8

func (d *Definition) GetAppsByType(appType AppType) []App

GetAppsByType returns all apps of the specified type from the definition.

func (*Definition) GithubLabels

func (d *Definition) GithubLabels() []string

GithubLabels returns the labels that will appear on the GitHub repository by looking at the application types.

func (*Definition) HasAppType added in v0.0.8

func (d *Definition) HasAppType(appType AppType) bool

HasAppType checks if the definition contains an app of the specified type.

func (*Definition) MergeAllEnvironments

func (d *Definition) MergeAllEnvironments() Environment

MergeAllEnvironments merges shared env variables with all apps' environments. App-specific values take precedence over shared ones. If multiple apps define the same variable, the last app in the list wins.

type Domain

type Domain struct {
	Name     string     `json:"name"`
	Type     DomainType `json:"type"`
	Zone     string     `json:"zone,omitempty"`
	Wildcard bool       `json:"wildcard,omitempty"`
}

type DomainType

type DomainType string

DomainType defines the type of domain that should be provisioned.

const (
	DomainTypePrimary   DomainType = "primary"
	DomainTypeAlias     DomainType = "alias"
	DomainTypeUnmanaged DomainType = "unmanaged"
)

DomainType constants.

func (DomainType) String

func (d DomainType) String() string

String implements fmt.Stringer on the DomainType.

type EnvSource

type EnvSource string

EnvSource defines the type of application being run.

const (
	// EnvSourceValue is a static string value (default).
	// Example: "https://api.example.com"
	EnvSourceValue EnvSource = "value"

	// EnvSourceResource references a Terraform resource output.
	// Example: "db.connection_url"
	EnvSourceResource EnvSource = "resource"

	// EnvSourceSOPS is an encrypted secret stored in a SOPS file.
	// Example: "secrets/production.yaml:API_KEY"
	EnvSourceSOPS EnvSource = "sops"
)

func (EnvSource) String

func (e EnvSource) String() string

String implements fmt.Stringer on the EnvSource.

type EnvValue

type EnvValue struct {
	// Source defines the source type: "value", "resource", or "sops"
	Source EnvSource `json:"source"`
	// Value holds the actual value for different source types:
	// - "value": A static string (e.g., "https://api.example.com")
	// - "resource": A Terraform resource reference (e.g., "db.connection_url")
	// - "sops": The variable name/key to lookup in the SOPS file (e.g., "API_KEY")
	//   Note: For SOPS, the file path is determined by environment (dev.yaml, staging.yaml, production.yaml)
	Value any `json:"value,omitempty"`
}

EnvValue represents a single env variable configuration

type EnvVar

type EnvVar map[string]EnvValue

EnvVar is a map of variable names to their configurations.

type EnvWalkEntry

type EnvWalkEntry struct {
	Environment env.Environment
	Key         string
	Value       any
	Source      EnvSource
	Map         EnvVar
}

EnvWalkEntry holds the details of a single env variable during iteration.

type Environment

type Environment struct {
	Default    EnvVar `json:"default,omitempty" inline:"true"`
	Dev        EnvVar `json:"dev,omitempty" inline:"true"`
	Staging    EnvVar `json:"staging,omitempty" inline:"true"`
	Production EnvVar `json:"production,omitempty" inline:"true"`
}

Environment contains env-specific variable configurations.

func (Environment) GetVarsForEnvironment added in v0.0.25

func (e Environment) GetVarsForEnvironment(target env.Environment) (EnvVar, error)

GetVarsForEnvironment returns the EnvVar map for the specified environment. Returns an error if the environment is unknown.

func (Environment) Walk

func (e Environment) Walk(fn EnvironmentWalker)

Walk iterates over all environments and calls fn for each env variable.

func (Environment) WalkE

func (e Environment) WalkE(fn EnvironmentWalkerE) error

WalkE iterates over all environments and calls fn for each env variable. If fn returns an error, iteration stops and the error is returned.

type EnvironmentWalker

type EnvironmentWalker func(entry EnvWalkEntry)

EnvironmentWalker defines a function that processes one env entry.

type EnvironmentWalkerE

type EnvironmentWalkerE func(entry EnvWalkEntry) error

EnvironmentWalkerE defines a function that processes one env entry and may return an error.

type GitHubRepo

type GitHubRepo struct {
	Owner string `json:"owner"`
	Name  string `json:"name"`
}

GitHubRepo defines the metadata for GitHub repositories within an app declaration.

type Infra

type Infra struct {
	Provider ResourceProvider `json:"provider"`
	// TODO, we need to define this as a AppResourceType or something.
	Type   string         `json:"type"`
	Config map[string]any `json:"config"`
}
type MenuItem struct {
	Identifier string
	Name       string
	URL        string
	Weight     string
	Children   []MenuItem
	Params     map[string]any
}

type Project

type Project struct {
	Name        string     `json:"name"`
	Title       string     `json:"title"`
	Description string     `json:"description"`
	Repo        GitHubRepo `json:"repo"`
}

Project defines root metadata about the project such as business names and descriptions.

type Resource

type Resource struct {
	Name             string               `json:"name"`
	Type             ResourceType         `json:"type"`
	Provider         ResourceProvider     `json:"provider"`
	Config           map[string]any       `json:"config"` // Conforms to Terraform
	Backup           ResourceBackupConfig `json:"backup,omitempty"`
	TerraformManaged *bool                `json:"terraformManaged,omitempty"`
}

Resource represents an infrastructure component that an application depends on, such as databases, storage buckets or caches.

func (*Resource) GitHubSecretName

func (r *Resource) GitHubSecretName(environment env.Environment, output string) string

GitHubSecretName returns the GitHub secret name for a resource output. Format: TF_{ENVIRONMENT}_{RESOURCE_NAME}_{OUTPUT_NAME} (uppercase)

Example:

resource.GitHubSecretName(env.Production, "connection_url")
↓
"TF_PROD_DB_CONNECTION_URL"

func (*Resource) IsTerraformManaged added in v0.0.8

func (r *Resource) IsTerraformManaged() bool

IsTerraformManaged returns whether this resource should be managed by Terraform. It defaults to true when the field is nil or explicitly set to true.

type ResourceBackupConfig

type ResourceBackupConfig struct {
	Enabled bool `json:"enabled"`
}

ResourceBackupConfig defines optional backup behavior for a resource. Backup is enabled by default.

type ResourceProvider

type ResourceProvider string

ResourceProvider defines a provider of cloud infra.

const (
	ResourceProviderDigitalOcean ResourceProvider = "digitalocean"
	ResourceProviderBackBlaze    ResourceProvider = "backblaze"
)

ResourceProvider constants.

func (ResourceProvider) String

func (r ResourceProvider) String() string

String implements fmt.Stringer on the ResourceProvider.

type ResourceType

type ResourceType string

ResourceType defines the type of resource to be provisioned.

const (
	ResourceTypePostgres ResourceType = "postgres"
	ResourceTypeS3       ResourceType = "s3"
)

ResourceType constants.

func (ResourceType) Outputs

func (r ResourceType) Outputs() []string

Outputs returns the required outputs for a resource type for Terraform.

These should always be exported to GitHub secrets regardless of user config defined in the app definition.

func (ResourceType) String

func (r ResourceType) String() string

String implements fmt.Stringer on the ResourceType.

type Shared

type Shared struct {
	Env Environment `json:"env"`
}

type SkippedItems added in v0.0.8

type SkippedItems struct {
	Apps      []string
	Resources []string
}

SkippedItems contains information about apps and resources that were filtered out due to not being Terraform managed.

type Social

type Social struct {
	Twitter   string
	LinkedIn  string
	GitHub    string
	YouTube   string
	Facebook  string
	Instagram string
	TikTok    string
	Dribbble  string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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