Documentation
¶
Overview ¶
Package platformimport reads apps from another self-hosted platform (read-only) into a neutral model and maps it to this platform's resources. The source credential is used in memory only.
Index ¶
- Constants
- Variables
- func LooksSecret(key string) bool
- func SanitizeName(s string) string
- type APIError
- type App
- type AppPlan
- type Applier
- type CapRoverSource
- type ClientOptions
- type ComposeSource
- type CoolifySource
- type Cron
- type Database
- type DatabasePlan
- type Discovery
- type DokkuEnvSource
- type DokploySource
- type Env
- type HealthCheck
- type HealthPlan
- type Item
- type NetworkPolicy
- type Note
- type Plan
- type PlanOptions
- type Platform
- type Report
- type Source
- type SourceKind
- type Unsupported
- type Volume
- type VolumePlan
Constants ¶
const ( AllowPrivateEnv = "APP_IMPORT_ALLOW_PRIVATE_NETWORKS" AllowLoopbackEnv = "APP_IMPORT_ALLOW_LOOPBACK" )
Environment variables that must be set before a request may opt in to private or loopback source addresses. Both the env var and the request field are required, so a leaked API token alone cannot aim the control plane at the internal network.
const ( LabelSourceID = "import/source-id" LabelSourcePlatform = "import/source-platform" LabelSourceName = "import/source-name" )
Labels stamped on every imported resource. The source-id label is what makes a re-run idempotent and lets an operator find imports to delete.
const ( StatusMapped = "mapped" StatusNeedsAttention = "needs-attention" StatusUnsupported = "unsupported" StatusAlready = "already-imported" StatusSkipped = "skipped" StatusCreated = "created" StatusFailed = "failed" )
Item statuses in a Report.
const ( CollisionSuffix = "suffix" CollisionSkip = "skip" )
Collision modes for a target name that is already taken.
const DataNote = "" /* 142-byte string literal not displayed */
DataNote is added to every report that contains databases.
const (
// MaxPages bounds every paginated or fan-out walk.
MaxPages = 200
)
Variables ¶
var ErrBlockedAddress = errors.New("platformimport: source address is not allowed")
ErrBlockedAddress is returned when the source URL resolves to an address the network policy forbids.
Functions ¶
func LooksSecret ¶
LooksSecret reports whether an env var name suggests a secret value.
func SanitizeName ¶
SanitizeName turns a source name into a valid resource name.
Types ¶
type App ¶
type App struct {
SourceID string
Name string
Project string
Kind SourceKind
Image string
GitURL string
GitBranch string
BuildMethod string
BuildPath string
Port int
Env []Env
Domains []string
Volumes []Volume
Replicas int
Health *HealthCheck
Crons []Cron
MemoryBytes int64
NanoCPUs int64
Notes []Note
}
App is one application in the neutral model.
type AppPlan ¶
type AppPlan struct {
SourceID string `json:"source_id"`
SourceName string `json:"source_name"`
Name string `json:"name"`
Image string `json:"image"`
Port int `json:"port"`
Env map[string]string `json:"env,omitempty"`
Secrets map[string]string `json:"-"`
Domains []string `json:"domains,omitempty"`
Volumes []VolumePlan `json:"volumes,omitempty"`
Replicas int `json:"replicas"`
Health *HealthPlan `json:"health,omitempty"`
MemoryBytes int64 `json:"memory_bytes,omitempty"`
NanoCPUs int64 `json:"nano_cpus,omitempty"`
Labels map[string]string `json:"labels"`
Project string `json:"project,omitempty"`
GitURL string `json:"git_url,omitempty"`
GitBranch string `json:"git_branch,omitempty"`
BuildMethod string `json:"build_method,omitempty"`
BuildPath string `json:"build_path,omitempty"`
}
AppPlan is one app create request. Secrets holds plaintext and is never serialized.
type Applier ¶
type Applier interface {
CreateApp(ctx context.Context, p AppPlan) (warnings []string, err error)
CreateDatabase(ctx context.Context, p DatabasePlan) (warnings []string, err error)
}
Applier creates resources on this platform. Implementations must be safe to call again after a partial failure.
type CapRoverSource ¶
type CapRoverSource struct {
// contains filtered or unexported fields
}
CapRoverSource reads a CapRover instance. The login POST is the only non-GET call it makes.
func NewCapRover ¶
func NewCapRover(baseURL, password string, o ClientOptions) (*CapRoverSource, error)
NewCapRover builds a CapRover source. The password is exchanged for a session token in memory and never stored.
type ClientOptions ¶
type ClientOptions struct {
Policy NetworkPolicy
Insecure bool
}
ClientOptions configure the source HTTP client.
type ComposeSource ¶
type ComposeSource struct {
Data []byte
}
ComposeSource maps a plain compose file, one app per service.
type CoolifySource ¶
type CoolifySource struct {
// contains filtered or unexported fields
}
CoolifySource reads a Coolify instance through its bearer-token API v1.
func NewCoolify ¶
func NewCoolify(baseURL, token string, o ClientOptions) (*CoolifySource, error)
NewCoolify builds a Coolify source. The token is kept in memory only.
type DatabasePlan ¶
type DatabasePlan struct {
SourceID string `json:"source_id"`
SourceName string `json:"source_name"`
Name string `json:"name"`
Engine string `json:"engine"`
Version string `json:"version"`
Project string `json:"project,omitempty"`
}
DatabasePlan is one managed database create request (empty, no data).
type Discovery ¶
type Discovery struct {
Platform Platform
Projects []string
Apps []App
Databases []Database
Unsupported []Unsupported
}
Discovery is everything read from a source.
type DokkuEnvSource ¶
DokkuEnvSource maps one Dokku app from a `dokku config:export` style dump (KEY=VALUE lines). It never contacts a Dokku host.
type DokploySource ¶
type DokploySource struct {
// contains filtered or unexported fields
}
DokploySource reads a Dokploy instance through its x-api-key API.
func NewDokploy ¶
func NewDokploy(baseURL, apiKey string, o ClientOptions) (*DokploySource, error)
NewDokploy builds a Dokploy source. The API key is kept in memory only.
type Env ¶
Env is one environment variable. Secret is true when the source marked it secret or the key looks like one.
type HealthCheck ¶
HealthCheck is an HTTP probe.
type HealthPlan ¶
HealthPlan is an HTTP readiness probe.
type Item ¶
type Item struct {
Kind string `json:"kind"`
SourceID string `json:"source_id"`
SourceName string `json:"source_name"`
Target string `json:"target,omitempty"`
Status string `json:"status"`
Reasons []string `json:"reasons,omitempty"`
Manual []string `json:"manual,omitempty"`
}
Item is one report row.
type NetworkPolicy ¶
NetworkPolicy decides which destinations the source client may dial. Cloud metadata and link-local addresses are never allowed.
type Plan ¶
type Plan struct {
Apps []AppPlan
Databases []DatabasePlan
Report Report
}
Plan is the mapped result of a Discovery.
func BuildPlan ¶
func BuildPlan(d *Discovery, o PlanOptions) *Plan
BuildPlan maps a Discovery onto create requests and a Report.
type PlanOptions ¶
type PlanOptions struct {
// Only restricts the plan to these source ids or source names. Empty means all.
Only []string
// Collision is CollisionSuffix (default) or CollisionSkip.
Collision string
// ExistingApps maps an import label value (platform:sourceID) to the
// app already created for it. TakenApps is every app name in use.
ExistingApps map[string]string
TakenApps map[string]bool
// ExistingDatabases maps a database name to "engine:version".
ExistingDatabases map[string]string
}
PlanOptions steer mapping.
type Platform ¶
type Platform string
Platform identifies a supported source.
const ( Coolify Platform = "coolify" Dokploy Platform = "dokploy" CapRover Platform = "caprover" Compose Platform = "compose" Dokku Platform = "dokku" )
Supported source platforms.
func ParsePlatform ¶
ParsePlatform validates a live-source platform name.
type Report ¶
type Report struct {
Platform Platform `json:"platform"`
Items []Item `json:"items"`
Counts map[string]int `json:"counts"`
Notes []string `json:"notes,omitempty"`
}
Report is the per-item outcome of a discover, plan or apply.
type SourceKind ¶
type SourceKind string
SourceKind says where an app's code comes from.
const ( SourceImage SourceKind = "image" SourceGit SourceKind = "git" SourceUnknown SourceKind = "unknown" )
Where an app comes from.
type Unsupported ¶
Unsupported is something that cannot be imported.