compose

package
v0.0.0-...-4f79b3b Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: BSD-3-Clause Imports: 44 Imported by: 9

Documentation

Index

Constants

View Source
const (
	BlobStateUndefined BlobState = iota
	BlobOk
	BlobFetching
	BlobMissing
	BlobSizeInvalid
	BlobDigestInvalid

	BlobTypeUnknown          BlobType = "unknown blob type"
	BlobTypeAppManifest      BlobType = "app manifest"
	BlobTypeAppBundle        BlobType = "app bundle"
	BlobTypeAppIndex         BlobType = "app index"
	BlobTypeAppLayersMeta    BlobType = "app meta"
	BlobTypeImageIndex       BlobType = "index"
	BlobTypeSkopeoImageIndex BlobType = "skopeo index"
	BlobTypeImageManifest    BlobType = "manifest"
	BlobTypeImageConfig      BlobType = "config"
	BlobTypeImageLayer       BlobType = "layer"
)
View Source
const (
	AppServiceHashLabelKey = "io.compose-spec.config-hash"
	ServiceLabel           = "com.docker.compose.service"
)
View Source
const (
	DefaultPollInterval = 300 // Default interval between polling/checking blob download status in milliseconds
)
View Source
const (
	ImageRootMaxSize = 100 * 1024
)
View Source
const (
	MaxMerkleTreeDepth = 10
)

Variables

View Source
var (
	ErrAppNotFound      = errors.New("app not found")
	ErrAppHasNoIndex    = errors.New("app has no bundle index")
	ErrAppIndexNotFound = errors.New("app blob index is not found")
)
View Source
var (
	ErrUninstallRunningApps = errors.New("failed to uninstall apps: some apps are still running, please stop them first")
)

Functions

func AlignToBlockSize

func AlignToBlockSize(value int64, blockSize int64) (aligned int64)

func CopyBlob

func CopyBlob(ctx context.Context, r io.ReadCloser, ref string, desc ocispec.Descriptor, store content.Store, force bool) error

func FetchBlobs

func FetchBlobs(ctx context.Context, cfg *Config, blobs BlobsInfo, options ...FetchOption) error

func FormatBytesInt64

func FormatBytesInt64(size int64) string

func FormatBytesUint64

func FormatBytesUint64(size uint64) string

func GetBlobsRootFor

func GetBlobsRootFor(storeRoot string) string

func GetDockerClient

func GetDockerClient(dockerHost string) (*dockerclient.Client, error)

func GetServiceHealth

func GetServiceHealth(ctx context.Context, dockerClient *dockerClient.Client, containerID string) (health string)

func Install

func Install(ctx context.Context,
	cfg *Config,
	appURI string,
	options ...InstallOption) error

func InstallCompose

func InstallCompose(ctx context.Context, app App, provider BlobProvider, composeRoot string) error

func LoadImages

func LoadImages(ctx context.Context,
	client *client.Client,
	app App,
	blobsRoot string,
	opts ...LoadImageOption) error

func NewHttpClient

func NewHttpClient(connectTimeout time.Duration, readTimeout time.Duration) *http.Client

func NewReadMonitor

func NewReadMonitor(ctx context.Context, r io.ReadSeekCloser, b *BlobFetchProgress) *readMonitor

func NewRegistryAuthorizer

func NewRegistryAuthorizer(cfg *configfile.ConfigFile, client *http.Client) docker.Authorizer

func NewResolver

func NewResolver(authorizer docker.Authorizer, client *http.Client) remotes.Resolver

func NewSecureReadCloser

func NewSecureReadCloser(srcReadCloser io.ReadCloser, opts ...SecureReadOptions) (io.ReadCloser, error)

func NewTarStreamer

func NewTarStreamer() *tarStreamer

func ParseImageRootAsManifest

func ParseImageRootAsManifest(root *ImageRoot) (*ocispec.Descriptor, []*ocispec.Descriptor, error)

func ReadBlob

func ReadBlob(ctx context.Context, provider BlobProvider, ref string, digest digest.Digest, size int64) ([]byte, error)

func ReadBlobWithReadLimit

func ReadBlobWithReadLimit(ctx context.Context, provider BlobProvider, ref string, limit int64) ([]byte, error)

func ReadBlobWithResolving

func ReadBlobWithResolving(ctx context.Context, provider BlobProvider, ref string, size int64) ([]byte, error)

func ReadImageManifest

func ReadImageManifest(ctx context.Context, provider BlobProvider, ref string, size int64) (*ocispec.Manifest, error)

func ReadImageRoot

func ReadImageRoot(ctx context.Context, provider BlobProvider, ref string) (*ImageRef, *ImageRoot, *ocispec.Descriptor, error)

func RemoveApps

func RemoveApps(ctx context.Context, cfg *Config, appRefs []string, options ...RemoveOpt) error

func StartApps

func StartApps(ctx context.Context, cfg *Config, appURIs []string, options ...StartOption) error

func StopApps

func StopApps(ctx context.Context, cfg *Config, appRefs []string) error

func UninstallApps

func UninstallApps(ctx context.Context, cfg *Config, appRefs []string, options ...UninstallOpt) error

func WithAppRef

func WithAppRef(ctx context.Context, ref *AppRef) context.Context

func WithBlobType

func WithBlobType(ctx context.Context, blobType BlobType) context.Context

func WithDescriptor

func WithDescriptor(desc ocispec.Descriptor) func(opts *SecureReadParams)

func WithExpectedDigest

func WithExpectedDigest(digest digest.Digest) func(opts *SecureReadParams)

func WithExpectedSize

func WithExpectedSize(size int64) func(opts *SecureReadParams)

func WithReadLimit

func WithReadLimit(limit int64) func(opts *SecureReadParams)

func WithRef

func WithRef(ref string) func(opts *SecureReadParams)

func WithSecureReadOff

func WithSecureReadOff() func(opts *SecureReadParams)

Types

type App

type App interface {
	Name() string
	Tree() *AppTree
	NodeCount() int
	Ref() *AppRef
	HasLayersMeta(arch string) bool
	GetBlobRuntimeSize(desc *ocispec.Descriptor, arch string, blockSize int64) int64
	GetComposeRoot() *TreeNode
	GetCompose(ctx context.Context, provider BlobProvider) (*composetypes.Project, error)
	CheckComposeInstallation(ctx context.Context, provider BlobProvider, installationRootDir string) (AppBundleErrs, error)
}

func ListApps

func ListApps(ctx context.Context, cfg *Config) ([]App, error)

type AppBundleErrs

type AppBundleErrs map[string]string

type AppInstallCheckResult

type AppInstallCheckResult struct {
	AppName       string        `json:"app_name"`
	MissingImages []string      `json:"missing_images"`
	BundleErrors  AppBundleErrs `json:"bundle_errors"`
}

type AppInstallState

type AppInstallState string
const (
	AppInstallStateComposeInstalling AppInstallState = "app:install:compose:install"
	AppInstallStateComposeChecking   AppInstallState = "app:install:compose:check"
	AppInstallStateImagesLoading     AppInstallState = "app:install:images:loading"
)

type AppLoader

type AppLoader interface {
	LoadAppTree(context.Context, BlobProvider, platforms.MatchComparer, string) (App, error)
}

type AppRef

type AppRef struct {
	Spec   reference.Spec
	Repo   string
	Name   string
	Tag    string
	Digest digest.Digest
}

func GetAppRef

func GetAppRef(ctx context.Context) *AppRef

func ParseAppRef

func ParseAppRef(ref string) (*AppRef, error)

func (*AppRef) GetBlobRef

func (r *AppRef) GetBlobRef(digest digest.Digest) string

func (*AppRef) String

func (r *AppRef) String() string

type AppStartProgress

type AppStartProgress func(app App, status AppStartStatus, any interface{})

type AppStartStatus

type AppStartStatus string
const (
	AppStartStatusStarting AppStartStatus = "starting"
	AppStartStatusStarted  AppStartStatus = "started"
	AppStartStatusFailed   AppStartStatus = "failed"
)

type AppStore

type AppStore interface {
	BlobProvider
	AddApps(appURIs []string) error
	ListApps(ctx context.Context) ([]*AppRef, error)
	RemoveApps(ctx context.Context, apps []*AppRef, prune bool) error
	Prune(ctx context.Context) ([]string, error)
}

type AppTree

type AppTree TreeNode

func (*AppTree) Print

func (t *AppTree) Print()

func (*AppTree) Walk

func (t *AppTree) Walk(fn NodeProcessor) error

type AppsStatus

type AppsStatus struct {
	Apps []App
	*FetchStatus
	*InstallStatus
	*RunningStatus
}

func CheckAppsStatus

func CheckAppsStatus(
	ctx context.Context,
	cfg *Config,
	appRefs []string,
	options ...CheckAppsStatusOption) (*AppsStatus, error)

func (*AppsStatus) AreFetched

func (s *AppsStatus) AreFetched() bool

func (*AppsStatus) AreInstalled

func (s *AppsStatus) AreInstalled() bool

func (*AppsStatus) AreRunning

func (s *AppsStatus) AreRunning() bool

type BlobFetchProgress

type BlobFetchProgress struct {
	BlobInfo       `json:"blob_info"`
	BytesFetched   int64         `json:"bytes_fetched"` // overall bytes read for this blob and written to the local storage;
	FetchStartTime time.Time     `json:"fetch_start_time"`
	BytesRead      int64         `json:"bytes_read"`      // total blob bytes read from network during the last fetch attempt
	ReadTime       time.Duration `json:"read_time"`       // aggregate time spent reading this blob data from the network
	ReadSpeedAvg   int64         `json:"read_speed_avg"`  // average read speed in bytes per second
	ReadSpeedCur   int64         `json:"read_speed_curr"` // current read speed in bytes per second
}

type BlobInfo

type BlobInfo struct {
	Descriptor   *ocispec.Descriptor `json:"descriptor"`
	State        BlobState           `json:"state"`
	Type         BlobType            `json:"type"`
	StoreSize    int64               `json:"store_size"`
	RuntimeSize  int64               `json:"runtime_size"`
	BytesFetched int64               `json:"bytes_fetched"`
}

func (*BlobInfo) HasRef

func (bi *BlobInfo) HasRef() bool

func (*BlobInfo) Ref

func (bi *BlobInfo) Ref() string

type BlobProvider

type BlobProvider interface {
	content.InfoProvider
	Type() BlobProviderType
	GetReadCloser(ctx context.Context, opts ...SecureReadOptions) (io.ReadCloser, error)
}

func NewLocalBlobProvider

func NewLocalBlobProvider(fileProvider content.Store) BlobProvider

func NewMemoryBlobProvider

func NewMemoryBlobProvider(blobs map[digest.Digest][]byte) BlobProvider

func NewRemoteBlobProviderFromConfig

func NewRemoteBlobProviderFromConfig(config *Config) BlobProvider

func NewStoreBlobProvider

func NewStoreBlobProvider(blobRoot string) BlobProvider

type BlobProviderType

type BlobProviderType string
const (
	BlobProviderTypeRemote BlobProviderType = "blob-provider:remote"
	BlobProviderTypeLocal  BlobProviderType = "blob-provider:local"
	BlobProviderTypeStore  BlobProviderType = "blob-provider:store"
	BlobProviderTypeMemory BlobProviderType = "blob-provider:memory"
)

type BlobState

type BlobState int

func CheckBlob

func CheckBlob(ctx context.Context, provider BlobProvider, dgst digest.Digest, opts ...SecureReadOptions) (BlobState, error)

func ErrToBlobState

func ErrToBlobState(err error) BlobState

func (BlobState) String

func (s BlobState) String() string

type BlobType

type BlobType string

func GetBlobType

func GetBlobType(ctx context.Context) BlobType

type BlobsFetchProgress

type BlobsFetchProgress map[digest.Digest]*BlobFetchProgress

type BlobsInfo

type BlobsInfo map[digest.Digest]*BlobInfo

type CheckAppsStatusOption

type CheckAppsStatusOption func(*CheckAppsStatusOptions)

func WithAppTreeBlobProvider

func WithAppTreeBlobProvider(bp BlobProvider) CheckAppsStatusOption

func WithCheckInstallation

func WithCheckInstallation(check bool) CheckAppsStatusOption

func WithCheckRunning

func WithCheckRunning(check bool) CheckAppsStatusOption

func WithQuickCheckFetch

func WithQuickCheckFetch(quickCheck bool) CheckAppsStatusOption

type CheckAppsStatusOptions

type CheckAppsStatusOptions struct {
	CheckInstallation   bool
	CheckRunning        bool
	QuickCheckFetch     bool
	AppTreeBlobProvider BlobProvider
}

type Config

type Config struct {
	StoreRoot           string
	ComposeRoot         string
	DockerCfg           *configfile.ConfigFile
	DockerHost          string
	Platform            specs.Platform
	ConnectTimeout      time.Duration
	ReadTimeout         time.Duration
	AppLoader           AppLoader
	AppStoreFactoryFunc func(c *Config) (AppStore, error)
	BlockSize           int64
	DBFilePath          string
	Proxy               ProxyProvider
}

func (*Config) AppStoreFactory

func (c *Config) AppStoreFactory() (AppStore, error)

func (*Config) GetAppComposeDir

func (c *Config) GetAppComposeDir(appName string) string

func (*Config) GetBlobsRoot

func (c *Config) GetBlobsRoot() string

type ErrBlobDigestMismatch

type ErrBlobDigestMismatch struct {
	Expected   digest.Digest
	Calculated digest.Digest
}

func (*ErrBlobDigestMismatch) Error

func (e *ErrBlobDigestMismatch) Error() string

type ErrBlobSizeLimitExceed

type ErrBlobSizeLimitExceed struct {
	Limit int64
}

func (*ErrBlobSizeLimitExceed) Error

func (e *ErrBlobSizeLimitExceed) Error() string

type ErrBlobSizeMismatch

type ErrBlobSizeMismatch struct {
	Expected int64
	Read     int64
}

func (*ErrBlobSizeMismatch) Error

func (e *ErrBlobSizeMismatch) Error() string

type ErrComposeInstall

type ErrComposeInstall struct {
	Errs AppBundleErrs
}

func (*ErrComposeInstall) Error

func (e *ErrComposeInstall) Error() string

type ErrImageInstall

type ErrImageInstall struct {
	MissingImages []string
}

func (*ErrImageInstall) Error

func (e *ErrImageInstall) Error() string

type FetchOption

type FetchOption func(*FetchOptions)

func WithFetchProgress

func WithFetchProgress(pf FetchProgressFunc) FetchOption

func WithProgressPollInterval

func WithProgressPollInterval(pollInterval int) FetchOption

func WithSourcePath

func WithSourcePath(sourcePath string) FetchOption

type FetchOptions

type FetchOptions struct {
	ProgressHandler      FetchProgressFunc
	ProgressPollInterval int    // interval between polling/checking blob download status in milliseconds
	SourcePath           string // path to the source directory containing blobs to fetch, if specified, the blobs will be fetched from this directory instead of remote registry
}

type FetchProgress

type FetchProgress struct {
	Blobs        BlobsFetchProgress // per-blob metadata and progress
	FetchedCount int                // number of fully fetched blobs
	CurrentBytes int64              // total bytes downloaded so far
	TotalBytes   int64              // total bytes expected to download
}

type FetchProgressFunc

type FetchProgressFunc func(*FetchProgress)

type FetchReport

type FetchReport struct {
	BlobsStatus BlobsInfo
}

type FetchStatus

type FetchStatus struct {
	BlobsStatus  map[digest.Digest]FetchReport
	MissingBlobs BlobsInfo
}

func CheckAppsFetchStatus

func CheckAppsFetchStatus(
	ctx context.Context,
	cfg *Config,
	blobProvider BlobProvider,
	apps []App,
	quick bool) (*FetchStatus, error)

type ImageLoadState

type ImageLoadState string
const (
	ImageLoadStateImageWaiting ImageLoadState = "image-load:image:waiting"
	ImageLoadStateLayerLoading ImageLoadState = "image-load:layer:loading"
	ImageLoadStateLayerSyncing ImageLoadState = "image-load:layer:syncing"
	ImageLoadStateLayerLoaded  ImageLoadState = "image-load:layer:loaded"
	ImageLoadStateImageLoaded  ImageLoadState = "image-load:image:loaded"
	ImageLoadStateImageExist   ImageLoadState = "image-load:image:exist"
)

type ImageRef

type ImageRef struct {
	reference.Spec
	Digest digest.Digest
}

func ParseImageRef

func ParseImageRef(ref string) (*ImageRef, error)

func (*ImageRef) GetBlobRef

func (r *ImageRef) GetBlobRef(digest digest.Digest) string

func (*ImageRef) GetTagRef

func (r *ImageRef) GetTagRef() string

type ImageRoot

type ImageRoot struct {
	specs.Versioned
	MediaType string          `json:"mediaType,omitempty"`
	Config    json.RawMessage `json:"config,omitempty"`
	Layers    json.RawMessage `json:"layers,omitempty"`
	Manifests json.RawMessage `json:"manifests,omitempty"`
	FSLayers  json.RawMessage `json:"fsLayers,omitempty"` // schema 1

	Type     BlobType
	Children []TreeNode
}

type ImageTree

type ImageTree TreeNode

func (*ImageTree) Print

func (t *ImageTree) Print(initDepth ...int)

type InstallCheckResult

type InstallCheckResult map[string]*AppInstallCheckResult

type InstallOption

type InstallOption func(*InstallOptions)

func WithInstallProgress

func WithInstallProgress(pf InstallProgressFunc) InstallOption

func WithLoadedImages

func WithLoadedImages(li map[string]struct{}) InstallOption

type InstallOptions

type InstallOptions struct {
	ProgressReporter progress.Reporter[InstallProgress]
	LoadedImages     map[string]struct{}
}

type InstallProgress

type InstallProgress struct {
	AppInstallState AppInstallState
	AppID           string
	ImageLoadState  ImageLoadState
	ImageID         string
	ID              string
	Current         int64
	Total           int64
}

type InstallProgressFunc

type InstallProgressFunc func(*InstallProgress)

type InstallReport

type InstallReport struct {
	Images       map[digest.Digest]bool
	BundleErrors AppBundleErrs
}

type InstallStatus

type InstallStatus struct {
	AppsInstallStatus   map[digest.Digest]*InstallReport
	NotInstalledImages  map[string]interface{}
	NotInstalledCompose map[digest.Digest]interface{}
}

func CheckAppsInstallStatus

func CheckAppsInstallStatus(
	ctx context.Context,
	cfg *Config,
	blobProvider BlobProvider,
	apps []App) (*InstallStatus, error)

type InstalledImagesInfo

type InstalledImagesInfo struct {
	// Image ID to image summary map (Image ID is the docker's internal ID for the image,
	// not the digest URI of the image).
	InstalledImages map[string]image.Summary
	// Image refs (both digest and tag) to image ID map.
	// The same image can have multiple references.
	InstalledImageRefs map[string]string
}

func GetInstalledImages

func GetInstalledImages(ctx context.Context, cfg *Config) (*InstalledImagesInfo, error)

type LoadImageOption

type LoadImageOption func(*LoadImageOptions)

func WithBlobReadingFromStore

func WithBlobReadingFromStore() LoadImageOption

func WithProgressReporting

func WithProgressReporting(pc ProgressCallbackFn) LoadImageOption

func WithRefWithDigest

func WithRefWithDigest() LoadImageOption

type LoadImageOptions

type LoadImageOptions struct {
	ReadBlobsFromStore bool
	RefWithDigest      bool
	ProgressReporter   progress.Reporter[LoadImageProgress]
	ProgressCallback   ProgressCallbackFn
}

type LoadImageProgress

type LoadImageProgress struct {
	State   ImageLoadState
	ImageID string
	ID      string
	Current int64
	Total   int64
}

type NodeProcessor

type NodeProcessor func(node *TreeNode, depth int) error

type ProgressCallbackFn

type ProgressCallbackFn func(*LoadImageProgress)

type ProxyConfig

type ProxyConfig struct {
	ProxyURL   *url.URL
	ProxyCerts *x509.CertPool
}

type ProxyProvider

type ProxyProvider func() *ProxyConfig

type RemoveOpt

type RemoveOpt func(*RemoveOpts)

func WithBlobPruning

func WithBlobPruning(prune bool) RemoveOpt

func WithCheckStatus

func WithCheckStatus(checkStatus bool) RemoveOpt

type RemoveOpts

type RemoveOpts struct {
	Prune       bool
	CheckStatus bool
}

type RunningReport

type RunningReport struct {
	Services []*Service
	Health   string
}

type RunningStatus

type RunningStatus struct {
	AppsRunningStatus map[digest.Digest]RunningReport
	NotRunningApps    map[digest.Digest]interface{}
}

func CheckAppsRunningStatus

func CheckAppsRunningStatus(
	ctx context.Context,
	cfg *Config,
	apps []App) (*RunningStatus, error)

type SecureReadOptions

type SecureReadOptions func(opts *SecureReadParams)

type SecureReadParams

type SecureReadParams struct {
	Ref               string
	ExpectedDigest    digest.Digest
	ExpectedSize      int64
	ReadLimit         int64
	Descriptor        ocispec.Descriptor
	DisableSecureRead bool
}

func GetSecureReadParams

func GetSecureReadParams(opts ...SecureReadOptions) (p SecureReadParams)

type Service

type Service struct {
	Name   string `json:"name"`
	Image  string `json:"image"`
	Hash   string `json:"hash"`
	CtrID  string `json:"ctr-id"`
	State  string `json:"state"`
	Status string `json:"status"`
	Health string `json:"health,omitempty"`
}

type Services

type Services []*Service

func GetAppServicesStatus

func GetAppServicesStatus(ctx context.Context, cfg *Config) (Services, error)

type StartOption

type StartOption func(*StartOptions)

func WithStartProgressHandler

func WithStartProgressHandler(handler AppStartProgress) StartOption

func WithVerboseStart

func WithVerboseStart(verbose bool) StartOption

type StartOptions

type StartOptions struct {
	Verbose         bool
	ProgressHandler AppStartProgress
}

type StatFS

type StatFS struct {
	BlockSize int64
	Blocks    uint64
	Bfree     uint64
}

func GetFsStat

func GetFsStat(path string) (StatFS, error)

type TreeNode

type TreeNode struct {
	Descriptor *ocispec.Descriptor
	Type       BlobType
	Children   []*TreeNode
}

func LoadImageTree

func LoadImageTree(ctx context.Context, provider BlobProvider, platform platforms.MatchComparer, ref string) (*TreeNode, error)

func (*TreeNode) GetImageConfigAndLayers

func (t *TreeNode) GetImageConfigAndLayers() (*ocispec.Descriptor, []*ocispec.Descriptor, error)

func (*TreeNode) GetServiceHash

func (t *TreeNode) GetServiceHash() string

func (*TreeNode) HasRef

func (t *TreeNode) HasRef() bool

func (*TreeNode) NodeCount

func (t *TreeNode) NodeCount() (counter int)

func (*TreeNode) Ref

func (t *TreeNode) Ref() string

func (*TreeNode) Walk

func (t *TreeNode) Walk(fn NodeProcessor) error

type UninstallOpt

type UninstallOpt func(*UninstallOpts)

func WithImagePruning

func WithImagePruning() UninstallOpt

type UninstallOpts

type UninstallOpts struct {
	Prune bool
}

type UsageInfo

type UsageInfo struct {
	Path       string  `json:"path"`
	SizeB      uint64  `json:"size_b"`
	Free       uint64  `json:"free"`
	FreeP      float32 `json:"free_p"`
	Reserved   uint64  `json:"reserved"`
	ReservedP  float32 `json:"reserved_p"`
	Available  uint64  `json:"available"`
	AvailableP float32 `json:"available_p"`
	Required   uint64  `json:"required"`
	RequiredP  float32 `json:"required_p"`
}

func GetUsageInfo

func GetUsageInfo(path string, required int64, watermark uint) (*UsageInfo, error)

func (*UsageInfo) Print

func (u *UsageInfo) Print()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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