repository

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2023 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ManifestFileName is the filename of the manifest.
	ManifestFileName = "tiup-manifest.index"

	// DefaultMirror is the location of the mirror to use if none is specified by the user via `EnvMirrors`.
	DefaultMirror = "https://tiup-mirrors.pingcap.com/"

	// EnvMirrors is the name of an env var the user can set to specify a mirror.
	EnvMirrors = "TIUP_MIRRORS"

	// TiUPBinaryName is the name of the tiup binary, both in the repository and locally.
	TiUPBinaryName = "tiup"
)
View Source
const (
	// OptionYanked is the key that represents a component is yanked or not
	OptionYanked = "yanked"
	// OptionStandalone is the key that represents a component is standalone or not
	OptionStandalone = "standalone"
	// OptionHidden is the key that represents a component is hidden or not
	OptionHidden = "hidden"
)

Variables

View Source
var (
	ErrNotFound       = stderrors.New("not found") // resource does not exists
	ErrManifestTooOld = stderrors.New("component manifest is too old, update it before publish")
)

predefined errors

View Source
var ErrUnknownComponent = errors.New("unknown component")

ErrUnknownComponent represents the specific component cannot be found in index.json

View Source
var ErrUnknownVersion = errors.New("unknown version")

ErrUnknownVersion represents the specific component version cannot be found in component.json

Functions

func CloneMirror

func CloneMirror(repo *V1Repository,
	components []string,
	tidbClusterVersionMapper func(string) string,
	targetDir string,
	selectedVersions []string,
	options CloneOptions) error

CloneMirror clones a local mirror from the remote repository

func FnameWithVersion

func FnameWithVersion(fname string, version uint) string

FnameWithVersion returns a filename, which contains the specific version number

func MergeMirror

func MergeMirror(keys map[string]*v1manifest.KeyInfo, base Mirror, additions ...Mirror) error

MergeMirror merges two or more mirrors

func PlatformString

func PlatformString(os, arch string) string

PlatformString returns a string identifying the current system.

func UpdateManifestForPublish

func UpdateManifestForPublish(m *v1manifest.Component,
	name, ver, entry, os, arch, desc string,
	filehash v1manifest.FileHash) *v1manifest.Component

UpdateManifestForPublish set corresponding field for component manifest

Types

type CloneOptions

type CloneOptions struct {
	Archs      []string
	OSs        []string
	Versions   []string
	Full       bool
	Components map[string]*[]string
	Prefix     bool
	Jobs       uint
}

CloneOptions represents the options of clone a remote mirror

type ComponentSpec

type ComponentSpec struct {
	// TargetDir it the target directory of the component,
	// Will use the default directory of Profile if it's empty.
	TargetDir string
	// ID is the id of the component
	ID string
	// Version describes the versions which are desirable; "" = use the most recent, compatible version.
	Version string
	// Force is true means overwrite any existing installation.
	Force bool
}

ComponentSpec describes a component a user would like to have or use.

type DisableProgress

type DisableProgress struct{}

DisableProgress implement the DownloadProgress interface and disable download progress

func (DisableProgress) Finish

func (d DisableProgress) Finish()

Finish implement the DownloadProgress interface

func (DisableProgress) SetCurrent

func (d DisableProgress) SetCurrent(size int64)

SetCurrent implement the DownloadProgress interface

func (DisableProgress) Start

func (d DisableProgress) Start(url string, size int64)

Start implement the DownloadProgress interface

type DownloadProgress

type DownloadProgress interface {
	Start(url string, size int64)
	SetCurrent(size int64)
	Finish()
}

DownloadProgress represents the download progress notifier

type Mirror

type Mirror interface {
	model.Backend
	// Source returns the address of the mirror
	Source() string
	// Open initialize the mirror.
	Open() error
	// Download fetches a resource to disk.
	// The implementation must return ErrNotFound if the resource not exists.
	Download(resource, targetDir string) error
	// Fetch fetches a resource into memory. The caller must close the returned reader. Id the size of the resource
	// is greater than maxSize, Fetch returns an error. Use maxSize == 0 for no limit.
	// The implementation must return ErrNotFound if the resource not exists.
	Fetch(resource string, maxSize int64) (io.ReadCloser, error)
	// Close closes the mirror and release local stashed files.
	Close() error
}

Mirror represents a repository mirror, which can be remote HTTP server or a local file system directory

func NewMirror

func NewMirror(mirror string, options MirrorOptions) Mirror

NewMirror returns a mirror instance Base on the schema of mirror

type MirrorOptions

type MirrorOptions struct {
	Progress DownloadProgress
	Upstream string
	KeyDir   string
}

MirrorOptions is used to customize the mirror download options

type MockMirror

type MockMirror struct {
	// Resources is a map from resource name to resource content.
	Resources map[string]string
}

MockMirror is a mirror for testing

func (*MockMirror) Close

func (l *MockMirror) Close() error

Close implements Mirror.

func (*MockMirror) Download

func (l *MockMirror) Download(resource, targetDir string) error

Download implements Mirror.

func (*MockMirror) Fetch

func (l *MockMirror) Fetch(resource string, maxSize int64) (io.ReadCloser, error)

Fetch implements Mirror.

func (*MockMirror) Grant

func (l *MockMirror) Grant(id, name string, key *v1manifest.KeyInfo) error

Grant implements the model.Backend interface

func (*MockMirror) Open

func (l *MockMirror) Open() error

Open implements Mirror.

func (*MockMirror) Publish

func (l *MockMirror) Publish(manifest *v1manifest.Manifest, info model.ComponentInfo) error

Publish implements the Mirror interface

func (*MockMirror) Rotate

func (l *MockMirror) Rotate(m *v1manifest.Manifest) error

Rotate implements the model.Backend interface

func (*MockMirror) Source

func (l *MockMirror) Source() string

Source implements the Mirror interface

type Options

type Options struct {
	SkipVersionCheck  bool
	GOOS              string
	GOARCH            string
	DisableDecompress bool
}

Options represents options for a repository

type ProgressBar

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

ProgressBar implement the DownloadProgress interface with download progress

func (*ProgressBar) Finish

func (p *ProgressBar) Finish()

Finish implement the DownloadProgress interface

func (*ProgressBar) SetCurrent

func (p *ProgressBar) SetCurrent(size int64)

SetCurrent implement the DownloadProgress interface

func (*ProgressBar) Start

func (p *ProgressBar) Start(url string, size int64)

Start implement the DownloadProgress interface

type Repository

type Repository struct {
	Options
}

Repository represents a components repository. All logic concerning manifests and the locations of tarballs is contained in the Repository object. Any IO is delegated to mirrorSource, which in turn will delegate fetching files to a Mirror.

type V1Repository

type V1Repository struct {
	Options
	// contains filtered or unexported fields
}

V1Repository represents a remote repository viewed with the v1 manifest design.

func NewV1Repo

func NewV1Repo(mirror Mirror, opts Options, local v1manifest.LocalManifests) *V1Repository

NewV1Repo creates a new v1 repository from the given mirror local must exists a trusted root.

func (*V1Repository) BinaryPath

func (r *V1Repository) BinaryPath(installPath string, componentID string, ver string) (string, error)

BinaryPath return the binary path of the component. Support you have install the component, need to get entry from local manifest. Load the manifest locally only to get then Entry, do not force do something need access mirror.

func (*V1Repository) ComponentVersion

func (r *V1Repository) ComponentVersion(id, ver string, includeYanked bool) (*v1manifest.VersionItem, error)

ComponentVersion returns version item of a component

func (*V1Repository) DownloadComponent

func (r *V1Repository) DownloadComponent(item *v1manifest.VersionItem, target string) error

DownloadComponent downloads the component specified by item into local file, the component will be removed if hash is not correct

func (*V1Repository) DownloadTiUP

func (r *V1Repository) DownloadTiUP(targetDir string) error

DownloadTiUP downloads the tiup tarball and expands it into targetDir

func (*V1Repository) FetchComponentManifest

func (r *V1Repository) FetchComponentManifest(id string, withYanked bool) (com *v1manifest.Component, err error)

FetchComponentManifest fetch the component manifest.

func (*V1Repository) FetchIndexManifest

func (r *V1Repository) FetchIndexManifest() (index *v1manifest.Index, err error)

FetchIndexManifest fetch the index manifest.

func (*V1Repository) FetchRootManifest

func (r *V1Repository) FetchRootManifest() (root *v1manifest.Root, err error)

FetchRootManifest fetch the root manifest.

func (*V1Repository) LatestNightlyVersion

func (r *V1Repository) LatestNightlyVersion(id string) (utils.Version, *v1manifest.VersionItem, error)

LatestNightlyVersion returns the latest nightly version of specific component

func (*V1Repository) LatestStableVersion

func (r *V1Repository) LatestStableVersion(id string, withYanked bool) (utils.Version, *v1manifest.VersionItem, error)

LatestStableVersion returns the latest stable version of specific component

func (*V1Repository) Local

Local returns the local cached manifests

func (*V1Repository) Mirror

func (r *V1Repository) Mirror() Mirror

Mirror returns Mirror

func (*V1Repository) PlatformString

func (r *V1Repository) PlatformString() string

PlatformString returns a string identifying the current system.

func (*V1Repository) PurgeTimestamp

func (r *V1Repository) PurgeTimestamp()

PurgeTimestamp remove timestamp cache from repository

func (*V1Repository) ResolveComponentVersion

func (r *V1Repository) ResolveComponentVersion(id, constraint string) (utils.Version, error)

ResolveComponentVersion resolves the latest version of a component that satisfies the constraint

func (*V1Repository) ResolveComponentVersionWithPlatform

func (r *V1Repository) ResolveComponentVersionWithPlatform(id, constraint, platform string) (utils.Version, error)

ResolveComponentVersionWithPlatform resolves the latest version of a component that satisfies the constraint

func (*V1Repository) UpdateComponentManifests

func (r *V1Repository) UpdateComponentManifests() error

UpdateComponentManifests updates all components's manifest to the latest version

func (*V1Repository) UpdateComponents

func (r *V1Repository) UpdateComponents(specs []ComponentSpec) error

UpdateComponents updates the components described by specs.

func (*V1Repository) WithOptions

func (r *V1Repository) WithOptions(opts Options) *V1Repository

WithOptions clone a new V1Repository with given options

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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