pack

package
v0.0.0-...-3bfe646 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 31 Imported by: 17

Documentation

Overview

package pack defines packaging format used by gravity

package pack implements simple package management capabilities

Index

Constants

View Source
const (
	// CollectionRepositories means access on all repositories that exist
	CollectionRepositories = "repositories"
	// CollectionRepository means access on a particular repository
	CollectionRepository = "repository"
)
View Source
const (
	// InstalledLabel is used to mark installed packages
	InstalledLabel = "installed"
	// LatestLabel is a pseudo label that allows system to find the latest version
	LatestLabel = "latest"
	// ConfigLabel means that this is a configuration package for another package
	ConfigLabel = "config-package-for"
	// PurposeLabel describes the package purpose
	PurposeLabel = "purpose"
	// AdvertiseIPLabel contains advertise IP of the server the package is for
	AdvertiseIPLabel = "advertise-ip"
	// OperationIDLabel contains ID of the operation the package was configured for
	OperationIDLabel = "operation-id"

	// PurposeCA marks the planet certificate authority package
	PurposeCA = "ca"
	// PurposeExport marks the package with cluster export data
	PurposeExport = "export"
	// PurposeLicense marks the package with cluster license
	PurposeLicense = "license"
	// PurposeResources marks the package with user resources
	PurposeResources = "resources"
	// PurposePlanetSecrets marks packages with planet secrets
	PurposePlanetSecrets = "planet-secrets"
	// PurposePlanetConfig marks packages with planet config
	PurposePlanetConfig = "planet-config"
	// PurposeRuntime marks a package as a runtime container package
	PurposeRuntime = "runtime"
	// PurposeRuntimeUpgrade marks a package as part of an intermediate upgrade step
	PurposeRuntimeUpgrade = "intermediate-upgrade"
	// PurposeTeleportMasterConfig marks package with teleport master config
	PurposeTeleportMasterConfig = "teleport-master-config"
	// PurposeTeleportNodeConfig marks package with teleport node config
	PurposeTeleportNodeConfig = "teleport-node-config"
	// PurposeLegacyTeleportNodeConfig specifies how the teleport node configuration packages
	// were marked in previous version
	PurposeLegacyTeleportNodeConfig = "teleport-config"
	// PurposeMetadata defines a label to use for application packages
	// that represent another package on a remote cluster.
	// A metadata package only contains a metadata block w/o actual contents of the
	// remote counterpart.
	PurposeMetadata = "metadata"
	// PurposeRPCCredentials marks a package as a package with agent RPC credentials
	PurposeRPCCredentials = "rpc-secrets"
)
View Source
const ManifestFilename = "orbit.manifest.json"

ManifestFilename names the manifest file inside a package

View Source
const Version = "0.0.1"

Variables

View Source
var (
	// RuntimePackageLabels identifies the runtime package
	RuntimePackageLabels = map[string]string{
		PurposeLabel: PurposeRuntime,
	}

	// RuntimeSecretsPackageLabels identifies the runtime secrets package
	RuntimeSecretsPackageLabels = map[string]string{
		PurposeLabel: PurposePlanetSecrets,
	}

	// RuntimeConfigPackageLabels identifies the runtime configuration package
	RuntimeConfigPackageLabels = map[string]string{
		PurposeLabel: PurposePlanetConfig,
	}

	// TeleportNodeConfigPackageLabels identifies the teleport node configuration package
	TeleportNodeConfigPackageLabels = map[string]string{
		PurposeLabel: PurposeTeleportNodeConfig,
	}

	// TeleportLegacyNodeConfigPackageLabels identifies the teleport node configuration package in previous versions.
	// TODO(dmitri): remove when no longer supported
	TeleportLegacyNodeConfigPackageLabels = map[string]string{
		PurposeLabel: PurposeLegacyTeleportNodeConfig,
	}

	// TeleportMasterConfigPackageLabels identifies the teleport master configuration package
	TeleportMasterConfigPackageLabels = map[string]string{
		PurposeLabel: PurposeTeleportMasterConfig,
	}

	// InstalledLabels defines a label set for an installed package
	InstalledLabels = map[string]string{
		InstalledLabel: InstalledLabel,
	}
)
View Source
var DiscardReporter = nopReporter{}

DiscardReporter is a ProgressReporter that discards all input

View Source
var LatestVersion = fmt.Sprintf("0.0.0+%v", LatestLabel)

LatestVersion is the meta version representing the latest version

Functions

func CheckUpdatePackage

func CheckUpdatePackage(from, to loc.Locator) error

CheckUpdatePackage makes sure that "to" package is acceptable when updating from "from" package

func ConfigLabels

func ConfigLabels(loc loc.Locator, purpose string) map[string]string

ConfigLabels returns the label set to assign a configuration role for the specified package loc

func ConfigurePackage

func ConfigurePackage(p PackageService, loc loc.Locator, confLoc loc.Locator, args []string, labels map[string]string) error

ConfigurePackage reads the given package, and configures it using arguments passed, the resulting package is created within the scope of the same package service

func CreateCertificateAuthority

func CreateCertificateAuthority(p CreateCAParams) error

CreateCertificateAuthority creates the OpsCenter certificate authority package in the provided package service using the provided key pair

func ExecutePackageCommand

func ExecutePackageCommand(p PackageService, cmd string, loc loc.Locator, confLoc *loc.Locator, execArgs []string, storageDir string) ([]byte, error)

ExecutePackageCommand executes command specified in the package and returns results of CombinedOutput call on the package binary

func ExportExecutable

func ExportExecutable(packages PackageService, locator loc.Locator, path, label string) error

ExportExecutable downloads the specified package from the package service into the provided path as an executable.

func FindAnyRuntimePackage

func FindAnyRuntimePackage(packages PackageService) (runtimePackage *loc.Locator, err error)

FindAnyRuntimePackage searches for the runtime package in the specified package service. It looks up both legacy packages and packages marked as runtime

func FindAnyRuntimePackageWithConfig

func FindAnyRuntimePackageWithConfig(packages PackageService) (runtimePackage *loc.Locator, runtimeConfig *loc.Locator, err error)

FindAnyRuntimePackageWithConfig searches for the runtime package and the corresponding configuration package in the specified package service. It looks up both legacy packages and packages marked as runtime

func FindConfigPackage

func FindConfigPackage(packages PackageService, filter loc.Locator) (*loc.Locator, error)

FindConfigPackage returns configuration package for given package

func FindInstalledConfigPackage

func FindInstalledConfigPackage(packages PackageService, filter loc.Locator) (*loc.Locator, error)

FindInstalledConfigPackage returns an installed configuration package for given package

func FindInstalledPackage

func FindInstalledPackage(packages PackageService, filter loc.Locator) (*loc.Locator, error)

FindInstalledPackage finds package currently installed on the host

func FindInstalledPackageWithConfig

func FindInstalledPackageWithConfig(packages PackageService, filter loc.Locator) (installed, config *loc.Locator, err error)

FindInstalledPackageWithConfig finds installed package and associated configuration package

func FindLatestPackage

func FindLatestPackage(packages PackageService, filter loc.Locator) (*loc.Locator, error)

FindLatestPackage returns package the latest package matching the provided locator

func FindLatestPackageByName

func FindLatestPackageByName(packages PackageService, name string) (*loc.Locator, error)

FindLatestPackageByName returns latest package with the specified name (across all repositories)

func FindLatestPackageCustom

func FindLatestPackageCustom(req FindLatestPackageRequest) (pkg *loc.Locator, err error)

FindLatestPackageCustom searches for the latest version of the package given with req

func FindLatestPackageWithLabels

func FindLatestPackageWithLabels(packages PackageService, repository string, labels map[string]string) (*loc.Locator, error)

FindLatestPackageWithLabels returns the latest package matching the provided labels

func FindLegacyRuntimeConfigPackage

func FindLegacyRuntimeConfigPackage(packages PackageService) (configPackage *loc.Locator, err error)

FindLegacyRuntimeConfigPackage locates the configuration package for the legacy runtime package in the specified package service

func FindLegacyRuntimePackage

func FindLegacyRuntimePackage(packages PackageService) (runtimePackage *loc.Locator, err error)

FindLegacyRuntimePackage locates the planet package using the obsolete master/node flavors.

func FindNewerPackages

func FindNewerPackages(packages PackageService, filter loc.Locator) ([]loc.Locator, error)

FindNewerPackages returns packages with versions greater than in the provided package

func FindPackageUpdate

func FindPackageUpdate(packages PackageService, pkg loc.Locator) (*storage.PackageUpdate, error)

FindPackageUpdate determines if an update is available for package specified with pkg and returns a descriptor object to go from existing version to a new one. If no update can be found, returns a nil descriptor and an instance of trace.NotFound as error

func FindRuntimePackage

func FindRuntimePackage(packages PackageService) (runtimePackage *loc.Locator, err error)

FindRuntimePackage locates the installed runtime package

func FindSecretsPackage

func FindSecretsPackage(packages PackageService) (*loc.Locator, error)

FindSecretsPackage returns the first secrets package from the given package service

func ForeachPackage

func ForeachPackage(packages PackageService, fn func(e PackageEnvelope) error) error

ForeachPackage executes function fn for each package in each repository

func ForeachPackageInRepo

func ForeachPackageInRepo(packages PackageService, repo string, fn func(e PackageEnvelope) error) error

ForeachPackageInRepo executes fn for each package found in repository

func GetConfigPackage

func GetConfigPackage(p PackageService, loc loc.Locator, confLoc loc.Locator, args []string) (io.Reader, error)

GetConfigPackage creates the config package without saving it into package service

func HasCertificateAuthority

func HasCertificateAuthority(packages PackageService) (bool, error)

HasCertificateAuthority returns boolean indicating whether the provided package service has the OpsCenter certificate authority in it

func IsPlanetConfigPackage

func IsPlanetConfigPackage(loc loc.Locator, labels map[string]string) bool

IsPlanetConfigPackage returns true if the specified package is a runtime configuration package

func IsPlanetPackage

func IsPlanetPackage(packageLoc loc.Locator, labels map[string]string) bool

IsPlanetPackage returns true if the specified package is a runtime package

func IsSecretsPackage

func IsSecretsPackage(loc loc.Locator, labels map[string]string) bool

IsSecretsPackage returns true if the specified package is a runtime secrets package

func IsUnpacked

func IsUnpacked(targetDir string) (bool, error)

IsUnpacked checks if the package has been unpacked at the provided directory (currently just by checking if the dir exists)

func Less

func Less(a, b *semver.Version) bool

Less is the standard version comparator that returns whether a < b. If versions are equal, it compares their metadata

func PackagePath

func PackagePath(baseDir string, loc loc.Locator) string

PackagePath generates a path to the package composed of base directory, repository name, package name and version

func ProcessMetadata

func ProcessMetadata(packages PackageService, loc *loc.Locator) (*loc.Locator, error)

ProcessMetadata processes some special metadata conventions, e.g. 'latest' metadata label

func ReadCertificateAuthority

func ReadCertificateAuthority(packages PackageService) (*authority.TLSKeyPair, error)

ReadCertificateAuthority reads the OpsCenter certificate authority package from the provided package service and returns its key pair

func ReadConfigPackage

func ReadConfigPackage(r io.Reader) (map[string]string, error)

func ReadPackage

func ReadPackage(r io.Reader) (*Manifest, []PackageFile, error)

func Tar

func Tar(path string, checkManifest bool) (io.ReadCloser, error)

Tar packs the directory into orbit archive. Manifest is always checked if present. If it's not present and checkManifest is set to false, orbit still packs the archive - manifests are optional

func Unpack

func Unpack(p PackageService, loc loc.Locator, targetDir string, opts *dockerarchive.TarOptions) error

Unpack reads the package from the package service and unpacks its contents to base directory targetDir

func UnpackIfNotUnpacked

func UnpackIfNotUnpacked(p PackageService, loc loc.Locator, targetDir string, opts *dockerarchive.TarOptions) error

UnpackIfNotUnpacked unpacks the specified package only if it's not yet unpacked

func WriteConfigPackage

func WriteConfigPackage(m *Manifest, w io.Writer) error

func WritePackage

func WritePackage(m Manifest, w io.Writer, files []PackageFile) error

Types

type ACLService

type ACLService struct {
	// contains filtered or unexported fields
}

ACLService is permission aware service that wraps regular service and applies checks before every operation

func (*ACLService) CreatePackage

func (a *ACLService) CreatePackage(loc loc.Locator, data io.Reader, options ...PackageOption) (*PackageEnvelope, error)

CreatePackage creates package and adds it to to the existing repository

func (*ACLService) DeletePackage

func (a *ACLService) DeletePackage(loc loc.Locator) error

DeletePackage deletes package from all repositories

func (*ACLService) DeleteRepository

func (a *ACLService) DeleteRepository(repository string) error

DeleteRepository deletes repository - packages will remain in the packages repository

func (*ACLService) GetPackages

func (a *ACLService) GetPackages(repository string) ([]PackageEnvelope, error)

GetPackages returns a list of packages in repository

func (*ACLService) GetRepositories

func (a *ACLService) GetRepositories() ([]string, error)

GetRepositories repositories returns a list of repositories

func (*ACLService) GetRepository

func (a *ACLService) GetRepository(repository string) (storage.Repository, error)

GetRepository returns repository by name, returns error if it does not exist

func (*ACLService) PackageDownloadURL

func (a *ACLService) PackageDownloadURL(loc loc.Locator) string

func (*ACLService) PortalURL

func (a *ACLService) PortalURL() string

func (*ACLService) ReadPackage

func (a *ACLService) ReadPackage(loc loc.Locator) (*PackageEnvelope, io.ReadCloser, error)

ReadPackage package opens and returns package contents

func (*ACLService) ReadPackageEnvelope

func (a *ACLService) ReadPackageEnvelope(loc loc.Locator) (*PackageEnvelope, error)

ReadPackageEnvelope returns package envelope

func (*ACLService) UpdatePackageLabels

func (a *ACLService) UpdatePackageLabels(loc loc.Locator, addLabels map[string]string, removeLabels []string) error

func (*ACLService) UpsertPackage

func (a *ACLService) UpsertPackage(loc loc.Locator, data io.Reader, options ...PackageOption) (*PackageEnvelope, error)

UpsertPackage creates package and adds it to to the existing repository

func (*ACLService) UpsertRepository

func (a *ACLService) UpsertRepository(repository string, expires time.Time) error

type Command

type Command struct {
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Args        []string `json:"args"`
}

type CreateCAParams

type CreateCAParams struct {
	// Packages is the package service to create the package in
	Packages PackageService
	// KeyPair is the CA certificate / key pair
	KeyPair authority.TLSKeyPair
	// Upsert if true upserts the package
	Upsert bool
}

CreateCAParams combines parameters for creating a CA package

type FindLatestPackageRequest

type FindLatestPackageRequest struct {
	// Packages specifies the package service to use with the request
	Packages PackageService
	// Repository specifies the optional repository for search.
	// If unspecifed, all repositories are searched
	Repository string
	// Match specifies the package matcher
	Match MatchFunc
	// Less specifies the optional version comparator.
	// If unspecified, default comparator will be used
	Less LessFunc
}

FindLatestPackageRequest defines the request to search for the latest version of a package

type Label

type Label struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type LabelUpdate

type LabelUpdate struct {
	// Locator identifies the package
	loc.Locator
	// Remove is the list of labels to remove
	Remove []string
	// Add is the map of labels to add
	Add Labels
}

LabelUpdate defines an intent to update package's labels

func (LabelUpdate) String

func (r LabelUpdate) String() string

String formats this update as readable text

type Labels

type Labels map[string]string

Labels is a set of labels

func RuntimeUpgradeLabels

func RuntimeUpgradeLabels(version string) Labels

RuntimeUpgradeLabels returns the labels to mark a package as part of an upgrade step for the specified runtime version

func (Labels) HasPurpose

func (r Labels) HasPurpose(values ...string) bool

HasPurpose returns true if these labels contain the purpose label for any of the given values

type LessFunc

type LessFunc func(a, b *semver.Version) bool

LessFunc defines a version comparator

type Manifest

type Manifest struct {
	Version  string                                  `json:"version"`
	Config   *schema.Config                          `json:"config,omitempty"`
	Commands []Command                               `json:"commands,omitempty"`
	Labels   []Label                                 `json:"labels,omitempty"`
	Service  *systemservice.NewPackageServiceRequest `json:"service,omitempty"`
}

func GetPackageManifest

func GetPackageManifest(p PackageService, loc loc.Locator) (*Manifest, error)

GetPackageManifest will retrieve the manifest file for the specified package

func OpenManifest

func OpenManifest(dir string) (*Manifest, error)

func ParseManifestJSON

func ParseManifestJSON(r io.Reader) (*Manifest, error)

func ReadManifest

func ReadManifest(tarball *tar.Reader) (*Manifest, error)

ReadManifest returns the contents of the manifest file from the specified tarball

func Untar

func Untar(r io.Reader, target string) (*Manifest, error)

func (*Manifest) Command

func (m *Manifest) Command(name string) (*Command, error)

func (*Manifest) EncodeJSON

func (m *Manifest) EncodeJSON() ([]byte, error)

func (*Manifest) Label

func (m *Manifest) Label(name string) string

func (*Manifest) NeedsConfig

func (m *Manifest) NeedsConfig() bool

type MatchFunc

type MatchFunc func(PackageEnvelope) bool

MatchFunc defines a predicate to match a package. Matcher returns true to indicate that the given package matches a specific condition

func PackageMatch

func PackageMatch(filter loc.Locator) MatchFunc

PackageMatch returns a matcher for the specified package filter

type PackageEnvelope

type PackageEnvelope struct {
	// Locator references the package
	Locator loc.Locator `json:"locator"`
	// SizeBytes is the size of the package in bytes
	SizeBytes int64 `json:"size_bytes"`
	// SHA512 specifies the sha-512 checksum of the package contents
	SHA512 string `json:"sha512"`
	// RuntimeLabels specifies a set of labels attached to the package
	RuntimeLabels map[string]string `json:"runtime_labels"`
	// Hidden is whether the package should not be displayed
	Hidden bool `json:"hidden"`
	// Encrypted is whether the package is encrypted
	Encrypted bool `json:"encrypted"`
	// Type specifies the application package type.
	// Empty for regular packages
	Type string `json:"type"`
	// Manifest contains the base64-encoded application manifest
	Manifest []byte `json:"manifest"`
	// Created specifies the package creation timestamp
	Created time.Time `json:"created"`
	// CreatedBy specifies the package creator
	CreatedBy string `json:"created_by"`
}

PackageEnvelope returns extended information about a package, such as name, version ,size in bytes, hash, manifest and date and time it was created and list of tags

func FindPackage

func FindPackage(packages PackageService, fn func(e PackageEnvelope) bool) (*PackageEnvelope, error)

FindPackage finds package matching the predicate fn

func FindRuntimePackageWithConfig

func FindRuntimePackageWithConfig(packages PackageService) (runtimePackage, runtimeConfig *PackageEnvelope, err error)

FindRuntimePackageWithConfig locates the planet package using the purpose label. Returns a pair - planet package with the corresponding configuration package.

func FindTeleportPackageWithConfig

func FindTeleportPackageWithConfig(packages PackageService) (teleportPackage, teleportConfig *PackageEnvelope, err error)

FindTeleportPackageWithConfig locates the teleport package using the purpose label. Returns a pair - teleport package with the corresponding configuration package.

func (*PackageEnvelope) HasAnyLabel

func (p *PackageEnvelope) HasAnyLabel(labels map[string][]string) bool

HasAnyLabel returns true if envelope has any of the provided labels

func (*PackageEnvelope) HasLabel

func (p *PackageEnvelope) HasLabel(key, val string) bool

HasLabel returns true if envelope has the requested label

func (*PackageEnvelope) HasLabels

func (p *PackageEnvelope) HasLabels(labels map[string]string) bool

HasLabels returns true if envelope has all of the provided labels

func (PackageEnvelope) Options

func (p PackageEnvelope) Options() []PackageOption

Options returns a list of options for this package envelope

func (PackageEnvelope) String

func (p PackageEnvelope) String() string

func (PackageEnvelope) ToPackage

func (p PackageEnvelope) ToPackage() storage.Package

ToPackage converts package envelope to the storage package format

func (PackageEnvelope) ToPackagePtr

func (p PackageEnvelope) ToPackagePtr() *storage.Package

ToPackagePtr converts package envelope to the storage package format

type PackageFile

type PackageFile struct {
	Path     string
	Contents []byte
}

type PackageOption

type PackageOption func(pkg *storage.Package)

PackageOption is a function that can make attribute modifications to the specified package

func WithCreatedBy

func WithCreatedBy(createdBy string) PackageOption

WithCreatedBy configures the package creator

func WithEncrypted

func WithEncrypted(encrypted bool) PackageOption

WithEncrypted configures the encryption status of a package

func WithHidden

func WithHidden(hidden bool) PackageOption

WithHidden configures a hidden flag for a package

func WithLabels

func WithLabels(labels map[string]string) PackageOption

WithLabels adds the specified labels as runtime labels to a package

func WithManifest

func WithManifest(packageType string, manifest []byte) PackageOption

WithManifest configures application-specific attributes like type and manifest for a package

type PackageService

type PackageService interface {
	// PackageDownloadURL returns download url for this package
	PackageDownloadURL(loc loc.Locator) string

	// PortalURL returns url for this portal
	PortalURL() string

	// UpsertRepository creates or updates repository, if expires is not
	// zero time the repository and all packages will be set to be expired
	UpsertRepository(repository string, expires time.Time) error

	// DeleteRepository deletes repository - packages will remain in the
	// packages repository
	DeleteRepository(repository string) error

	// GetRepository returns repository by name
	GetRepository(repository string) (storage.Repository, error)

	// Get repositories returns a list of repositories
	GetRepositories() ([]string, error)

	// GetPackages returns a list of packages in repository
	GetPackages(repository string) ([]PackageEnvelope, error)

	// CreatePackage creates package and adds it to to the existing repository
	CreatePackage(loc loc.Locator, data io.Reader, options ...PackageOption) (*PackageEnvelope, error)

	// UpsertPackage creates or updates package and adds it to to the existing repository
	UpsertPackage(loc loc.Locator, data io.Reader, options ...PackageOption) (*PackageEnvelope, error)

	// UpdatePackageLabels updates package's labels
	UpdatePackageLabels(loc loc.Locator, addLabels map[string]string, removeLabels []string) error

	// DeletePackage deletes package from repository
	DeletePackage(locator loc.Locator) error

	// Read package opens and returns package contents
	ReadPackage(loc loc.Locator) (*PackageEnvelope, io.ReadCloser, error)

	// ReadPackageEnvelope returns package envelope
	ReadPackageEnvelope(loc loc.Locator) (*PackageEnvelope, error)
}

func PackagesWithACL

func PackagesWithACL(packages PackageService, users users.Users, user storage.User, checker teleservices.AccessChecker) PackageService

type PackageSorter

type PackageSorter []PackageEnvelope

PackageSorter is a package sort helper, is used to return deterministic results by lexicographically sorting packages

func (PackageSorter) Len

func (s PackageSorter) Len() int

func (PackageSorter) Less

func (s PackageSorter) Less(i, j int) bool

func (PackageSorter) Swap

func (s PackageSorter) Swap(i, j int)

type ProgressReporter

type ProgressReporter interface {
	Report(current, target int64)
}

type ProgressReporterFn

type ProgressReporterFn func(current, target int64)

func (ProgressReporterFn) Report

func (f ProgressReporterFn) Report(current, target int64)

type ProgressWriter

type ProgressWriter struct {
	Size int64

	R ProgressReporter
	// contains filtered or unexported fields
}

func (*ProgressWriter) Write

func (w *ProgressWriter) Write(b []byte) (int, error)

type Status

type Status struct {
	Status string      `json:"status"` // Status of the running container, one of 'running', 'stopped', 'degraded'
	Info   interface{} `json:"info"`   // App-specific information about the container
}

Directories

Path Synopsis
Package suite contains a package service acceptance test suite that is backend implementation independent each storage will use the suite to test itself
Package suite contains a package service acceptance test suite that is backend implementation independent each storage will use the suite to test itself

Jump to

Keyboard shortcuts

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