configtranslate

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package configtranslate reads hosted-platform config files (Heroku Procfile and app.json, Vercel vercel.json) and proposes a Levelrail app spec fragment plus findings for what has no equivalent. It is pure and offline: same input, same output, nothing is read from disk or network.

Index

Constants

View Source
const (
	DefaultWebPort  = 8080
	DefaultNodePort = 3000
)

Default ports proposed when the source config names none.

Variables

This section is empty.

Functions

func NextSteps

func NextSteps(f Fragment, prog, specFile string) []string

NextSteps returns the exact commands that turn the proposal into running apps. prog is the CLI name, specFile the path the proposal was saved to.

func ShellQuote

func ShellQuote(s string) string

ShellQuote single-quotes s for a POSIX shell unless it is already plain.

func SkippedStep

func SkippedStep(kind, name string) string

SkippedStep is the printed line that replaces a command whose name is invalid.

func ValidDatabaseName

func ValidDatabaseName(name string) bool

ValidDatabaseName reports whether name is accepted by databases create.

func ValidServiceName

func ValidServiceName(name string) bool

ValidServiceName reports whether name is safe as a --service value.

Types

type Build

type Build struct {
	Type    string `yaml:"type" json:"type"`
	Command string `yaml:"command,omitempty" json:"command,omitempty"`
	Publish string `yaml:"publish,omitempty" json:"publish,omitempty"`
}

Build is a service's build block.

type Database

type Database struct {
	Engine string `yaml:"engine" json:"engine"`
}

Database is one proposed databases: entry.

type EmitOptions

type EmitOptions struct {
	// Services limits the emit to these service names, like apps create --service. Empty means all.
	Services []string
	// DBVersions sets the engine version per database engine, such as postgres=16.
	DBVersions map[string]string
}

EmitOptions narrow what a translation result becomes as stack documents.

type Env

type Env struct {
	Value    string `json:"value,omitempty"`
	From     string `json:"from,omitempty"`
	Secret   bool   `json:"secret,omitempty"`
	Required bool   `json:"required,omitempty"`
}

Env is one env value: a literal, a reference to a database, or a secret the operator supplies at deploy time.

type Finding

type Finding struct {
	Code     string   `json:"code"`
	Severity Severity `json:"severity"`
	// Source is the input file the finding came from.
	Source string `json:"source"`
	// Subject names the setting concerned (an env key, add-on, route).
	Subject string `json:"subject,omitempty"`
	Message string `json:"message"`
	// Fix is a short human instruction.
	Fix string `json:"fix"`
}

Finding is one thing the operator should know or do, with a stable code.

type Format

type Format string

Format names a supported source config format.

const (
	FormatHeroku Format = "heroku"
	FormatVercel Format = "vercel"
)

Supported source formats.

func Detect

func Detect(files map[string][]byte) []Format

Detect reports which formats have at least one input file present, in a fixed order.

type Fragment

type Fragment struct {
	Version   int                 `yaml:"version" json:"version"`
	Services  map[string]Service  `yaml:"services,omitempty" json:"services,omitempty"`
	Databases map[string]Database `yaml:"databases,omitempty" json:"databases,omitempty"`
}

Fragment is the proposed app.yaml content, mirroring internal/spec field names.

func (Fragment) YAML

func (f Fragment) YAML() ([]byte, error)

YAML renders the fragment as app.yaml text with sorted, stable keys.

type HeaderRule

type HeaderRule struct {
	Path   string            `yaml:"path" json:"path"`
	Values map[string]string `yaml:"values,omitempty" json:"values,omitempty"`
}

HeaderRule sets response headers on a static site for a path pattern.

type Health

type Health struct {
	Readiness *Probe `yaml:"readiness,omitempty" json:"readiness,omitempty"`
}

Health holds the readiness probe proposal.

type Hooks

type Hooks struct {
	PreDeploy  string `yaml:"preDeploy,omitempty" json:"preDeploy,omitempty"`
	PostDeploy string `yaml:"postDeploy,omitempty" json:"postDeploy,omitempty"`
}

Hooks are deploy-lifecycle shell commands run inside the container.

type Job

type Job struct {
	Name     string   `yaml:"name" json:"name"`
	Schedule string   `yaml:"schedule" json:"schedule"`
	Command  []string `yaml:"command" json:"command"`
	Timezone string   `yaml:"timezone,omitempty" json:"timezone,omitempty"`
	Mode     string   `yaml:"mode,omitempty" json:"mode,omitempty"`
}

Job is one proposed scheduled task under a service's jobs:.

type Option

type Option func(*options)

Option tunes a translation without making the package read the environment.

func WithNodePort

func WithNodePort(p int) Option

WithNodePort sets the port proposed for a Vercel server service.

func WithWebPort

func WithWebPort(p int) Option

WithWebPort sets the port proposed for Heroku web and worker services.

type Probe

type Probe struct {
	Path string `yaml:"path" json:"path"`
}

Probe is an HTTP readiness check path.

type Resources

type Resources struct {
	Memory string `yaml:"memory,omitempty" json:"memory,omitempty"`
}

Resources holds proposed container limits.

type Result

type Result struct {
	Detected []Format  `json:"detected"`
	Fragment Fragment  `json:"fragment"`
	Findings []Finding `json:"findings"`
}

Result is the full output of a translation.

func Translate

func Translate(files map[string][]byte, opts ...Option) Result

Translate detects the known config files in files (keyed by repo-relative path) and returns the merged proposal. Unknown files are ignored.

func (Result) EmitInput

func (r Result) EmitInput(o EmitOptions) (platformimport.EmitInput, error)

EmitInput converts the proposal into the neutral model that platformimport.EmitStack writes. Jobs, routes and build settings have no App document field yet, so they become notes instead of being dropped.

type Route

type Route struct {
	From   string `yaml:"from" json:"from"`
	To     string `yaml:"to" json:"to"`
	Status int    `yaml:"status,omitempty" json:"status,omitempty"`
}

Route is a static-site redirect or rewrite rule.

type Service

type Service struct {
	Build     Build          `yaml:"build" json:"build"`
	Port      int            `yaml:"port,omitempty" json:"port,omitempty"`
	Health    *Health        `yaml:"health,omitempty" json:"health,omitempty"`
	Resources *Resources     `yaml:"resources,omitempty" json:"resources,omitempty"`
	Replicas  int            `yaml:"replicas,omitempty" json:"replicas,omitempty"`
	Command   []string       `yaml:"command,omitempty" json:"command,omitempty"`
	Hooks     *Hooks         `yaml:"hooks,omitempty" json:"hooks,omitempty"`
	Jobs      []Job          `yaml:"jobs,omitempty" json:"jobs,omitempty"`
	Routes    []Route        `yaml:"routes,omitempty" json:"routes,omitempty"`
	Headers   []HeaderRule   `yaml:"headers,omitempty" json:"headers,omitempty"`
	Static    *StaticOptions `yaml:"static,omitempty" json:"static,omitempty"`
	Env       map[string]Env `yaml:"-" json:"env,omitempty"`
}

Service is one proposed services: entry.

type Severity

type Severity string

Severity ranks how much a finding needs the operator's attention.

const (
	SeverityInfo    Severity = "info"
	SeverityWarn    Severity = "warn"
	SeverityBlocker Severity = "blocker"
)

Finding severities: info is FYI, warn changes behavior, blocker has no equivalent.

type StaticOptions

type StaticOptions struct {
	CleanURLs     bool   `yaml:"cleanUrls,omitempty" json:"cleanUrls,omitempty"`
	TrailingSlash string `yaml:"trailingSlash,omitempty" json:"trailingSlash,omitempty"`
}

StaticOptions are a static service's serving options.

Jump to

Keyboard shortcuts

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