dokployextras

package
v1.5.10 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dokployextras plans and applies the parts of a Dokploy import that are not apps: S3 backup destinations, database backup schedules and alert channels. The CLI and the dashboard import share it, so both create through the same API calls.

Index

Constants

View Source
const (
	StateWouldCreate = "would_create"
	StateNeedsSecret = "needs_secret"
	StateCreated     = "created"
	StateExists      = "exists"
	StatePending     = "pending"
	StateSkipped     = "skipped"
	StateReview      = "review"
	StateFailed      = "failed"
	StateUnsupported = "unsupported"

	KindBackupTarget   = "backup_target"
	KindBackupSchedule = "backup_schedule"
	KindChannel        = "alert_channel"

	EnvLimit     = "APP_MIGRATE_BACKUP_LIMIT"
	DefaultLimit = 200
	CeilingLimit = 5000

	EndpointWarning = "the server connects to this endpoint from its own network: confirm it before enabling schedules"
)

Import outcomes. No type here has a credential field: keys and notify URLs go from the source straight into the create call and are never stored, printed or journaled.

Variables

View Source
var (

	// NameRE is the resource name rule a journal and an import accept.
	NameRE = regexp.MustCompile(`^[a-z][a-z0-9-]{0,62}$`)
)

Functions

func ApplyBackups

func ApplyBackups(ctx context.Context, client *apiclient.Client, imp *BackupImport, jr Journal)

ApplyBackups creates through the same API calls as a manual target create and schedule set, so scoping, encryption of keys, validation and audit match a manual create.

func ApplyChannels

func ApplyChannels(ctx context.Context, client *apiclient.Client, imp *ChannelImport, jr Journal)

ApplyChannels creates through the same API call as a manual channel create, so scoping, URL validation, secret storage and audit match a manual create.

func ChannelFingerprint

func ChannelFingerprint(ch apiclient.NotificationChannelResource) string

ChannelFingerprint identifies a channel by id and timestamps, so any edit changes it.

func ChannelHint

func ChannelHint(c *Channel) string

ChannelHint is the manual create command. It carries placeholders only, never a token or address.

func CleanDetail

func CleanDetail(s string) string

CleanDetail keeps a provider or server message printable and short.

func EnvPositiveInt

func EnvPositiveInt(lookupEnv func(string) (string, bool), name string, def, ceiling int) int

EnvPositiveInt reads a positive int capped at ceiling, falling back to def.

func FingerprintOf

func FingerprintOf(t apiclient.BackupTargetResource) string

FingerprintOf is the fingerprint of a target as the API returns it.

func HasControlChar

func HasControlChar(s string) bool

HasControlChar reports control or format characters, which never go into a hint or a create call.

func ImportName

func ImportName(raw string) (string, bool)

ImportName maps a source name onto a journal-safe name; ok is false for names a person must pick.

func MapProvider

func MapProvider(endpoint string) (provider, keptEndpoint string)

MapProvider picks the target provider from the endpoint host, since source provider labels vary.

func PlanChannelUndo

func PlanChannelUndo(list []apiclient.NotificationChannelResource, err error, r Record) (bool, string)

PlanChannelUndo decides on one channel from a list read once per undo run.

func PlanUndo

func PlanUndo(ctx context.Context, client *apiclient.Client, r Record) (remove bool, reason string)

PlanUndo says whether a journaled resource may be removed: only when it still reads back by its recorded id with the recorded shape. A 404 may mean hidden, so it is never "gone".

func RedactNotify

func RedactNotify(msg, notify string) string

RedactNotify removes the notify URL and its path and query parts from a server message.

func ScheduleHint

func ScheduleHint(s *BackupSchedule, targetID string) string

ScheduleHint is the manual schedule command for a schedule that could not be bound.

func ServiceName

func ServiceName(name string) string

ServiceName maps free-text source names onto the lowercase, hyphenated form a resource accepts.

func ShQuote

func ShQuote(s string) string

ShQuote single-quotes a value so a printed hint command is safe to paste into a shell.

func TargetFingerprint

func TargetFingerprint(provider, endpoint, bucket, region string) string

TargetFingerprint identifies a backup target by its non-secret shape.

func TargetHint

func TargetHint(t *BackupTarget) string

TargetHint is the manual create command; it carries placeholders, never a key.

func Undo

func Undo(ctx context.Context, client *apiclient.Client, r Record) error

Undo removes one journaled resource by its recorded id; call PlanUndo first.

Types

type BackupImport

type BackupImport struct {
	Targets   []BackupTarget   `json:"targets"`
	Schedules []BackupSchedule `json:"schedules"`
	// UseKeys and Creds are set only for an apply that includes secret values.
	UseKeys bool                                                               `json:"-"`
	Creds   func(ctx context.Context, sourceID string) (string, string, error) `json:"-"`
}

BackupImport is the backup half of a Dokploy plan.

func PlanBackups

func PlanBackups(disc *platformimport.Discovery, o BackupOptions) *BackupImport

PlanBackups is pure apart from the endpoint check: names, endpoints and buckets only.

func (*BackupImport) FinishPlan

func (imp *BackupImport) FinishPlan(useKeys bool)

FinishPlan marks which targets an apply would create with keys and sets the manual command for the rest.

type BackupOptions

type BackupOptions struct {
	EnableSchedules bool
	Limit           int
	CheckEndpoint   func(string) error
}

BackupOptions tunes PlanBackups. CheckEndpoint is the import network policy check.

func NewBackupOptions

func NewBackupOptions(ctx context.Context, enable bool, policy platformimport.NetworkPolicy, lookupEnv func(string) (string, bool)) BackupOptions

NewBackupOptions wires the per-run cap from env and the endpoint check from policy.

type BackupSchedule

type BackupSchedule struct {
	Database string `json:"database"`
	Target   string `json:"target"`
	Cron     string `json:"cron"`
	Retain   int    `json:"retain,omitempty"`
	// Paused is true unless schedules were explicitly enabled and the source schedule was on.
	Paused bool   `json:"paused"`
	State  string `json:"state"`
	Detail string `json:"detail,omitempty"`
}

BackupSchedule is one source database backup mapped onto a schedule.

type BackupTarget

type BackupTarget struct {
	SourceName string `json:"source_name"`
	Name       string `json:"name"`
	Provider   string `json:"provider"`
	Endpoint   string `json:"endpoint,omitempty"`
	Region     string `json:"region,omitempty"`
	Bucket     string `json:"bucket"`
	ID         string `json:"id,omitempty"`
	State      string `json:"state"`
	Detail     string `json:"detail,omitempty"`
	// HasKeys says the source holds keys for it; the keys themselves are never read at plan time.
	HasKeys  bool   `json:"has_keys"`
	SourceID string `json:"-"`
}

BackupTarget is one source destination mapped onto a backup target.

type Channel

type Channel struct {
	SourceName string `json:"source_name"`
	Name       string `json:"name"`
	Kind       string `json:"kind"`
	Server     string `json:"server,omitempty"`
	// Enabled is false unless channels were explicitly enabled.
	Enabled bool   `json:"enabled"`
	ID      string `json:"id,omitempty"`
	State   string `json:"state"`
	Detail  string `json:"detail,omitempty"`
	// HasSecret says the source holds a token or webhook URL; the value is never read at plan time.
	HasSecret  bool   `json:"has_secret"`
	SourceID   string `json:"-"`
	SourceKind string `json:"-"`
	Recipient  string `json:"-"`
	HasAuth    bool   `json:"-"`
}

Channel is one source notification provider mapped onto an alert channel.

type ChannelImport

type ChannelImport struct {
	Channels    []Channel            `json:"channels"`
	Unsupported []UnsupportedChannel `json:"unsupported,omitempty"`
	// UseSecrets and Target are set only for an apply that includes secret values.
	UseSecrets bool                                                                            `json:"-"`
	Target     func(ctx context.Context, sourceID string) (platformimport.NotifyTarget, error) `json:"-"`
	CheckURL   func(string) error                                                              `json:"-"`
}

ChannelImport is the alert channel half of a Dokploy plan.

func PlanChannels

func PlanChannels(disc *platformimport.Discovery, o ChannelOptions) *ChannelImport

PlanChannels is pure apart from the server URL check: names, kinds and hosts only.

func (*ChannelImport) FinishPlan

func (imp *ChannelImport) FinishPlan(useSecrets bool)

FinishPlan marks which channels an apply would create and sets the manual command for the rest.

type ChannelOptions

type ChannelOptions struct {
	Enable   bool
	Limit    int
	CheckURL func(string) error
}

ChannelOptions tunes PlanChannels. CheckURL is the import network policy check.

func NewChannelOptions

func NewChannelOptions(ctx context.Context, enable bool, policy platformimport.NetworkPolicy, lookupEnv func(string) (string, bool)) ChannelOptions

NewChannelOptions wires the per-run cap from env and the server URL check from policy.

type Journal

type Journal interface {
	FindCreated(kind, name string) (Record, bool)
	Created(r Record)
	Failed(kind, name string)
	// Resumed is called when an earlier run's record still matches, so it stays undoable.
	Resumed(r Record)
}

Journal records what an apply created so a later run resumes and undo removes only that.

type Record

type Record struct {
	Kind        string `json:"kind"`
	Name        string `json:"name"`
	ID          string `json:"id,omitempty"`
	Fingerprint string `json:"fingerprint,omitempty"`
	Cron        string `json:"cron,omitempty"`
	// PauseFailed marks a resource created but left running or enabled, kept so undo can remove it.
	PauseFailed bool `json:"pause_failed,omitempty"`
}

Record is what a journal keeps for one imported resource: names, ids and shapes, never a value.

type UnsupportedChannel

type UnsupportedChannel struct {
	SourceName string `json:"source_name"`
	SourceKind string `json:"source_kind"`
	Reason     string `json:"reason"`
}

UnsupportedChannel is a source provider with no matching channel kind here.

Jump to

Keyboard shortcuts

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