appimport

package
v0.8.8 Latest Latest
Warning

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

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

Documentation

Overview

Package appimport turns a source platform's application inventory into a reviewed, staged import: per-app verdicts, a hostname mapping with a visible diff, preflight checks and a secret-free receipt. It reads from internal/platformimport and never talks to the source itself.

Index

Constants

View Source
const (
	CheckName    = "name"
	CheckDomains = "domains"
	CheckEnvKeys = "env-keys"
	CheckDBHosts = "db-hosts"
	CheckSecrets = "secrets"
	CheckBuild   = "build"
	CheckDisk    = "disk"
)

Check ids reported by Preflight.

View Source
const (
	VerdictReady       = "ready"
	VerdictNotes       = "ready-with-notes"
	VerdictAttention   = "needs-attention"
	VerdictUnsupported = "unsupported"
)

Verdicts for one source application or service.

View Source
const (
	KindApp     = "app"
	KindService = "service"
)

Kinds of inventory entries.

View Source
const (
	SourceGit     = "git"
	SourceImage   = "image"
	SourceCompose = "compose"
	SourceService = "service"
	SourceUnknown = "unknown"
)

Where an app's code comes from, for display.

View Source
const (
	MapDockerfile = "dockerfile"
	MapRailpack   = "railpack"
	MapStatic     = "static"
	MapImage      = "image"
)

Build methods an app maps to here.

View Source
const DefaultDiskMargin = 1.5

DefaultDiskMargin multiplies known volume sizes when comparing to free space.

View Source
const ReceiptStatement = "" /* 135-byte string literal not displayed */

ReceiptStatement is printed on every receipt.

Variables

This section is empty.

Functions

func FindReferences

func FindReferences(env []platformimport.Env, hosts []string) map[string]bool

FindReferences lists which of hosts appear in env values, so a caller can tell which databases an app depends on. Values are inspected, not kept.

func ReferencesHost

func ReferencesHost(v, host string) bool

ReferencesHost reports whether v contains host as a whole hostname token.

func Remaining

func Remaining(e Entry, it store.AppImportItem) []string

Remaining lists what an operator still has to do by hand for one app.

func RewriteValue

func RewriteValue(v string, maps []Mapping) (string, int)

RewriteValue replaces every whole-token occurrence of each mapping's source host and returns the new value with the number of replacements.

func ValidateMapping

func ValidateMapping(m Mapping) error

ValidateMapping checks both sides are plain hostnames.

Types

type AppliedChange

type AppliedChange struct {
	Key   string `json:"key"`
	Count int    `json:"count"`
}

AppliedChange records that a mapping rewrote a variable, without values.

type Change

type Change struct {
	App    string `json:"app"`
	Key    string `json:"key"`
	Secret bool   `json:"secret"`
	Count  int    `json:"count"`
	Before string `json:"before"`
	After  string `json:"after"`
}

Change is one env value a mapping rewrote, in a form safe to show.

func RewriteEnv

func RewriteEnv(app string, env []platformimport.Env, maps []Mapping) ([]platformimport.Env, []Change)

RewriteEnv applies maps to env values and returns the new env with a masked diff. The input slice is not modified.

type Check

type Check struct {
	App    string `json:"app,omitempty"`
	ID     string `json:"id"`
	Status string `json:"status"`
	Detail string `json:"detail"`
	Fix    string `json:"fix,omitempty"`
}

Check is one preflight result. App is empty for a whole-import check.

type Context

type Context struct {
	// Targets maps a lowercased source database name to the database here.
	Targets map[string]string
	// TargetHost returns the connection host of a database here.
	TargetHost func(name string) string
}

Context is what the target platform already holds, used to judge which source databases were migrated and where they went.

type DBRef

type DBRef struct {
	SourceID string `json:"source_id"`
	Name     string `json:"name"`
	// Host is the in-network hostname apps on the source use.
	Host string `json:"host"`
	// Target is the database here the data was moved to, empty when none.
	Target string `json:"target,omitempty"`
	// TargetHost is the connection host of Target here.
	TargetHost string `json:"target_host,omitempty"`
}

DBRef is a database one app's configuration points at.

func DatabaseRefs

func DatabaseRefs(d *platformimport.Discovery, c Context) []DBRef

DatabaseRefs lists every source database with where it went here.

type Entry

type Entry struct {
	SourceID    string        `json:"source_id"`
	Name        string        `json:"name"`
	Kind        string        `json:"kind"`
	Project     string        `json:"project,omitempty"`
	Environment string        `json:"environment,omitempty"`
	Server      string        `json:"server,omitempty"`
	Source      string        `json:"source"`
	Repo        string        `json:"repo,omitempty"`
	Branch      string        `json:"branch,omitempty"`
	Image       string        `json:"image,omitempty"`
	ImageID     string        `json:"image_id,omitempty"`
	HostBuilt   bool          `json:"host_built,omitempty"`
	BuildPack   string        `json:"build_pack,omitempty"`
	MapsTo      string        `json:"maps_to,omitempty"`
	Port        int           `json:"port,omitempty"`
	Domains     []string      `json:"domains,omitempty"`
	Env         EnvSummary    `json:"env"`
	Volumes     []VolumeEntry `json:"volumes,omitempty"`
	Crons       int           `json:"crons,omitempty"`
	Health      *HealthEntry  `json:"health,omitempty"`
	MemoryBytes int64         `json:"memory_bytes,omitempty"`
	NanoCPUs    int64         `json:"nano_cpus,omitempty"`
	Databases   []DBRef       `json:"databases,omitempty"`
	Verdict     string        `json:"verdict"`
	Findings    []Finding     `json:"findings,omitempty"`
}

Entry is one row of the inventory.

type EnvSummary

type EnvSummary struct {
	Plain  int `json:"plain"`
	Secret int `json:"secret"`
	// Empty counts secrets that came back without a readable value.
	Empty int `json:"empty"`
}

EnvSummary counts variables by sensitivity. Values are never included.

type Finding

type Finding struct {
	Reason string `json:"reason"`
	Next   string `json:"next,omitempty"`
}

Finding is one reason behind a verdict and what to do about it.

type Group

type Group struct {
	Project     string  `json:"project"`
	Environment string  `json:"environment"`
	Entries     []Entry `json:"entries"`
}

Group is the entries of one project environment.

type HealthEntry

type HealthEntry struct {
	Path            string `json:"path"`
	IntervalSeconds int    `json:"interval_seconds,omitempty"`
	TimeoutSeconds  int    `json:"timeout_seconds,omitempty"`
	Retries         int    `json:"retries,omitempty"`
}

HealthEntry is the source's HTTP probe.

type Inventory

type Inventory struct {
	Platform  string         `json:"platform"`
	Groups    []Group        `json:"groups"`
	Databases []DBRef        `json:"databases"`
	Counts    map[string]int `json:"counts"`
}

Inventory is everything read from the source, grouped and judged.

func BuildInventory

func BuildInventory(d *platformimport.Discovery, c Context) Inventory

BuildInventory judges every app and unsupported item of a discovery and groups them by project and environment.

func (Inventory) Entries

func (i Inventory) Entries() []Entry

Entries returns every entry across groups.

type Mapping

type Mapping struct {
	From string `json:"from"`
	To   string `json:"to"`
}

Mapping rewrites one source hostname to a new one in env values.

type PreflightInput

type PreflightInput struct {
	Inventory Inventory
	// Selected lists source ids to import. Nil selects every importable entry.
	Selected map[string]bool
	// Names maps a source id to its planned name here.
	Names map[string]string
	// DomainOwners maps a domain to the app here that holds it.
	DomainOwners map[string]string
	Mappings     []Mapping
	// Env holds source env per source id, in memory only. Nil skips the
	// checks that need values.
	Env map[string][]platformimport.Env
	// FreeBytes is free disk here, negative when unknown.
	FreeBytes  int64
	DiskMargin float64
}

PreflightInput is everything the checks depend on.

type PreflightResult

type PreflightResult struct {
	Checks   []Check  `json:"checks"`
	Diff     []Change `json:"diff"`
	Failed   int      `json:"failed"`
	Warnings int      `json:"warnings"`
	// EnvChecked is false when no source values were available.
	EnvChecked bool `json:"env_checked"`
	CanStage   bool `json:"can_stage"`
}

PreflightResult is the outcome of all checks.

func Preflight

func Preflight(in PreflightInput) PreflightResult

Preflight evaluates every selected entry before anything is written.

type Receipt

type Receipt struct {
	GeneratedAt string       `json:"generated_at"`
	SessionID   string       `json:"session_id"`
	Platform    string       `json:"platform"`
	SourceURL   string       `json:"source_url"`
	Statement   string       `json:"statement"`
	Mappings    []Mapping    `json:"mappings"`
	Apps        []ReceiptApp `json:"apps"`
	Remaining   int          `json:"remaining_manual_steps"`
}

Receipt is the downloadable record of one import session.

func BuildReceipt

func BuildReceipt(sess store.AppImportSession, items []ReceiptInput, now time.Time) Receipt

BuildReceipt assembles the receipt. It reads only stored state, never source values, so it cannot carry a secret.

type ReceiptApp

type ReceiptApp struct {
	SourceID    string          `json:"source_id"`
	SourceName  string          `json:"source_name"`
	Target      string          `json:"target,omitempty"`
	Project     string          `json:"project,omitempty"`
	Environment string          `json:"environment,omitempty"`
	Verdict     string          `json:"verdict"`
	State       string          `json:"state"`
	Domains     []string        `json:"domains,omitempty"`
	EnvPlain    int             `json:"env_plain"`
	EnvSecret   int             `json:"env_secret"`
	Rewritten   []AppliedChange `json:"rewritten,omitempty"`
	Volumes     []ReceiptVolume `json:"volumes,omitempty"`
	Remaining   []string        `json:"remaining,omitempty"`
}

ReceiptApp is what happened to one source app.

type ReceiptInput

type ReceiptInput struct {
	Item      store.AppImportItem
	Entry     Entry
	Rewritten []AppliedChange
}

ReceiptInput couples a stored item with its decoded inventory entry.

type ReceiptVolume

type ReceiptVolume struct {
	Name          string `json:"name"`
	ContainerPath string `json:"container_path"`
	Copied        bool   `json:"copied"`
	CopiedAt      string `json:"copied_at,omitempty"`
}

ReceiptVolume is one persistent volume and its confirmation state.

type VolumeEntry

type VolumeEntry struct {
	Name          string `json:"name"`
	ContainerPath string `json:"container_path"`
	HostPath      string `json:"host_path,omitempty"`
	SizeBytes     int64  `json:"size_bytes"`
	SizeKnown     bool   `json:"size_known"`
}

VolumeEntry is one persistent mount.

Jump to

Keyboard shortcuts

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