core

package
v0.0.0-...-de2237a Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HOME     = "data"
	TEMP_DIR = filepath.Join(HOME, "temp")
	HIS_FILE = filepath.Join(HOME, "history.yaml")
	SQUASHFS = true
	CONF     *YamlCfg
	INTERVAL = 60
)
View Source
var (
	// NoCache used to disable a blobinfocache
	NoCache = none.NoCache
)

Functions

func CheckIfIncludeTag

func CheckIfIncludeTag(repository string) bool

CheckIfIncludeTag checks if a repository string includes tag

func CheckInvalidChar

func CheckInvalidChar(text string) bool

func FormatByteSize

func FormatByteSize(sizeInByte int64) (size string)

func FormatSeconds

func FormatSeconds(seconds int64) string

func GenRepoUrl

func GenRepoUrl(srcReg string, dstReg string, dstRepo string, rawURL string) (src string, dst string)

we support two cases: hub.docker.com/myrepo/img:tag https://hub.docker.com/myrepo/img:tag hub.docker.com/myrepo/img:tag -> newname:newtag hub.docker.com/myrepo/img:tag -> mynewrepo/newname:newtag hub.docker.com/myrepo/img:tag -> newhub.docker.com/mynewrepo/newname:newtag

func GetBlobSuffix

func GetBlobSuffix(b types.BlobInfo) string

func InitI18nPrinter

func InitI18nPrinter(defaultLang string)

func InitLogger

func InitLogger(logConfig []byte)

func MakeSquashfs

func MakeSquashfs(logger CtxLogger, path string, fs string) error

func ManifestHandler

func ManifestHandler(m []byte, t string, i *ImageSource) ([]manifest.Manifest, error)

ManifestHandler expends the ability of handling manifest list in schema2, but it's not finished yet return the digest array of manifests in the manifest list if exist.

func NewReadCloserWrapper

func NewReadCloserWrapper(r io.Reader, closer func() error) io.ReadCloser

func NewSqfsFileSystem

func NewSqfsFileSystem(sqfsFile string, home string) (*sqfsFileSystem, error)

func NewStderrWrapper

func NewStderrWrapper(logger CtxLogger) io.Writer

func NewStdoutWrapper

func NewStdoutWrapper(logger CtxLogger) io.Writer

func NewWriteCloserWrapper

func NewWriteCloserWrapper(r io.Writer, closer func() error) io.WriteCloser

func ShortenString

func ShortenString(str string, n int) string

func TestSquashfs

func TestSquashfs() bool

func TestTar

func TestTar() bool

func UnSquashfs

func UnSquashfs(logger CtxLogger, path string, fs string, noCmd bool) error

Types

type Client

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

Client describes a syncronization client

func NewClient

func NewClient(routineNum int, retries int, logger *TaskContext) (*Client, error)

NewClient creates a syncronization client

func (*Client) ClearInvalidTask

func (c *Client) ClearInvalidTask()

func (*Client) GenerateOfflineDownTask

func (c *Client) GenerateOfflineDownTask(url string, username string, password string) error

func (*Client) GenerateOfflineUploadTask

func (c *Client) GenerateOfflineUploadTask(srcUrl string, url string, path string, username string, password string) error

func (*Client) GenerateOnlineTask

func (c *Client) GenerateOnlineTask(imgSrc string, userSrc string, pswdStr string, imgDst string, userDst string, pswdDst string) error

func (*Client) GetAFailedTask

func (c *Client) GetAFailedTask() (Task, bool)

GetAFailedTask gets a failed task from failedTaskList

func (*Client) GetATask

func (c *Client) GetATask() (Task, bool)

GetATask return a Task struct if the task list ids not empty

func (*Client) PutAFailedTask

func (c *Client) PutAFailedTask(failedTask Task)

PutAFailedTask puts a failed task to failedTaskList

func (*Client) PutAInvalidTask

func (c *Client) PutAInvalidTask(invalidTask string)

func (*Client) PutATask

func (c *Client) PutATask(task Task)

PutATask puts a Task struct to task list

func (*Client) Run

func (c *Client) Run()

Run ids main function of a syncronization client

func (*Client) TaskLen

func (c *Client) TaskLen() int

type CmdLogger

type CmdLogger struct {
}

func (*CmdLogger) Debug

func (t *CmdLogger) Debug(logStr string)

func (*CmdLogger) Error

func (t *CmdLogger) Error(logStr string)

func (*CmdLogger) Errorf

func (t *CmdLogger) Errorf(format string, args ...interface{}) error

func (*CmdLogger) Info

func (t *CmdLogger) Info(logStr string)

type CompressionMetadata

type CompressionMetadata struct {
	Datafiles  map[string]int64
	Compressor string
	Blobs      map[string][]string
	Manifests  map[string]string
	BlobDoing  map[string]int
	// contains filtered or unexported fields
}

func NewCompressionMetadata

func NewCompressionMetadata(compressor string) (*CompressionMetadata, error)

func (*CompressionMetadata) AddDatafile

func (c *CompressionMetadata) AddDatafile(name string, num int64)

func (*CompressionMetadata) AddImage

func (c *CompressionMetadata) AddImage(name string, manifest string)

func (*CompressionMetadata) BlobDone

func (c *CompressionMetadata) BlobDone(sha256 string, ref string)

func (*CompressionMetadata) BlobExists

func (c *CompressionMetadata) BlobExists(sha256 string) bool

func (*CompressionMetadata) BlobStart

func (c *CompressionMetadata) BlobStart(sha256 string, tid int) bool

func (*CompressionMetadata) ClearDoing

func (c *CompressionMetadata) ClearDoing(tid int)

type CtxLogger

type CtxLogger interface {
	Debug(logStr string)
	Info(logStr string)
	Error(logStr string)
	Errorf(string, ...interface{}) error
}

func NewCmdLogger

func NewCmdLogger() CtxLogger

type DingTalkAccess

type DingTalkAccess struct {
	Token  string
	Secret string
}

type DingTalkWapper

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

func (*DingTalkWapper) Send

func (d *DingTalkWapper) Send(text string)

type DockerSaver

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

Save image with docker tar format

func NewDockerSaver

func NewDockerSaver(ctx *TaskContext, target string) *DockerSaver

func (*DockerSaver) AppendFileStream

func (d *DockerSaver) AppendFileStream(filename string, size int64, reader io.Reader) error

func (*DockerSaver) AppendMeta

func (d *DockerSaver) AppendMeta(m *Manifest, url string)

func (*DockerSaver) Close

func (d *DockerSaver) Close()

type History

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

func NewHistory

func NewHistory(fileName string) (*History, error)

func (*History) Add

func (h *History) Add(url string)

func (*History) Skip

func (h *History) Skip(url string) bool

type ImageCompressedTarReader

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

func NewImageCompressedTarReader

func NewImageCompressedTarReader(filename string, compression string) (*ImageCompressedTarReader, error)

func (*ImageCompressedTarReader) Close

func (img *ImageCompressedTarReader) Close() error

func (*ImageCompressedTarReader) ReadFileStream

func (img *ImageCompressedTarReader) ReadFileStream(skip int) (io.Reader, string, int64, bool, error)

func (*ImageCompressedTarReader) ReadFileStreamByName

func (img *ImageCompressedTarReader) ReadFileStreamByName(hex string) (io.Reader, string, int64, bool, error)

type ImageCompressedTarWriter

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

func NewImageCompressedTarWriter

func NewImageCompressedTarWriter(filename string, compression string) (*ImageCompressedTarWriter, error)

func (*ImageCompressedTarWriter) AppendFileStream

func (img *ImageCompressedTarWriter) AppendFileStream(filename string, size int64, reader io.ReadCloser) error

func (*ImageCompressedTarWriter) Cleanup

func (img *ImageCompressedTarWriter) Cleanup()

func (*ImageCompressedTarWriter) Close

func (img *ImageCompressedTarWriter) Close() error

func (*ImageCompressedTarWriter) Flush

func (img *ImageCompressedTarWriter) Flush()

type ImageDestination

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

ImageDestination ids a reference of a remote image we will push to

func NewImageDestination

func NewImageDestination(pCtx context.Context, registry, repository, tag, username, password string, insecure bool) (*ImageDestination, error)

NewImageDestination generates a ImageDestination by repository, the repository string must include "tag". If username or password ids empty, access to repository will be anonymous.

func (*ImageDestination) CheckBlobExist

func (i *ImageDestination) CheckBlobExist(blobInfo types.BlobInfo) (bool, error)

CheckBlobExist checks if a blob exist for destination and reuse exist blobs

func (*ImageDestination) Close

func (i *ImageDestination) Close() error

Close a ImageDestination

func (*ImageDestination) GetRegistry

func (i *ImageDestination) GetRegistry() string

GetRegistry returns the registry of a ImageDestination

func (*ImageDestination) GetRepository

func (i *ImageDestination) GetRepository() string

GetRepository returns the repository of a ImageDestination

func (*ImageDestination) GetTag

func (i *ImageDestination) GetTag() string

GetTag return the tag of a ImageDestination

func (*ImageDestination) PushManifest

func (i *ImageDestination) PushManifest(manifestByte []byte) error

PushManifest push a manifest file to destinate image

func (*ImageDestination) PutABlob

func (i *ImageDestination) PutABlob(blob io.ReadCloser, blobInfo types.BlobInfo) error

PutABlob push a blob to destinate image

type ImageSource

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

ImageSource ids a reference to a remote image need to be pulled.

func NewImageSource

func NewImageSource(pCtx context.Context, registry, repository, tag, username, password string, insecure bool) (*ImageSource, error)

NewImageSource generates a PullTask by repository, the repository string must include "tag", if username or password ids empty, access to repository will be anonymous. a repository string ids the rest part of the images url except "tag" and "registry"

func (*ImageSource) Close

func (i *ImageSource) Close() error

Close an ImageSource

func (*ImageSource) GetABlob

func (i *ImageSource) GetABlob(blobInfo types.BlobInfo) (io.ReadCloser, int64, error)

GetABlob gets a blob from remote image

func (*ImageSource) GetBlobInfos

func (i *ImageSource) GetBlobInfos(manifestByte []byte, manifestType string) ([]types.BlobInfo, error)

GetBlobInfos get blobs from source image.

func (*ImageSource) GetManifest

func (i *ImageSource) GetManifest() ([]byte, string, error)

GetManifest get manifest file from source image

func (*ImageSource) GetRegistry

func (i *ImageSource) GetRegistry() string

GetRegistry returns the registry of a ImageSource

func (*ImageSource) GetRepository

func (i *ImageSource) GetRepository() string

GetRepository returns the repository of a ImageSource

func (*ImageSource) GetSourceRepoTags

func (i *ImageSource) GetSourceRepoTags() ([]string, error)

GetSourceRepoTags gets all the tags of a repository which ImageSource belongs to

func (*ImageSource) GetTag

func (i *ImageSource) GetTag() string

GetTag returns the tag of a ImageSource

type LocalCache

type LocalCache struct {
	Pathname string `yaml:"pathname"`
	KeepDays int    `yaml:"keepdays"`
	KeepSize int    `yaml:"keepsize"`
}

func NewLocalCache

func NewLocalCache(pathname string, keepDays int, keepSize int) *LocalCache

func (*LocalCache) Clean

func (c *LocalCache) Clean()

func (*LocalCache) Match

func (c *LocalCache) Match(blobName string, size int64) (bool, string)

func (*LocalCache) Reuse

func (c *LocalCache) Reuse(blobName string) (io.ReadCloser, error)

func (*LocalCache) SaveFile

func (c *LocalCache) SaveFile(filename string, reader io.ReadCloser, size int64) (string, error)

func (*LocalCache) SaveStream

func (c *LocalCache) SaveStream(blobName string, reader io.Reader) (io.ReadCloser, io.WriteCloser, error)

type LocalTemp

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

func NewLocalTemp

func NewLocalTemp(pathname string) *LocalTemp

func (*LocalTemp) Clean

func (t *LocalTemp) Clean()

func (*LocalTemp) SaveFile

func (t *LocalTemp) SaveFile(filename string, reader io.ReadCloser, size int64) (string, error)

func (*LocalTemp) SavePath

func (t *LocalTemp) SavePath(path string) (string, error)

type Manifest

type Manifest struct {
	Config types.BlobInfo   `json:"config"`
	Layers []types.BlobInfo `json:"layers"`
}

type Notify

type Notify interface {
	Send(text string)
}

func NewDingTalkWapper

func NewDingTalkWapper(dtas []DingTalkAccess) Notify

type OfflineDownTask

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

func (*OfflineDownTask) Callback

func (t *OfflineDownTask) Callback(success bool, content string)

func (*OfflineDownTask) Name

func (t *OfflineDownTask) Name() string

func (*OfflineDownTask) Run

func (t *OfflineDownTask) Run(tid int) error

func (*OfflineDownTask) StatDown

func (t *OfflineDownTask) StatDown(size int64, duration time.Duration)

func (*OfflineDownTask) StatUp

func (t *OfflineDownTask) StatUp(size int64, duration time.Duration)

func (*OfflineDownTask) Status

func (t *OfflineDownTask) Status() string

type OfflineUploadTask

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

func (*OfflineUploadTask) Callback

func (t *OfflineUploadTask) Callback(bool, string)

func (*OfflineUploadTask) Name

func (t *OfflineUploadTask) Name() string

func (*OfflineUploadTask) Run

func (t *OfflineUploadTask) Run(tid int) error

func (*OfflineUploadTask) StatDown

func (t *OfflineUploadTask) StatDown(size int64, duration time.Duration)

func (*OfflineUploadTask) StatUp

func (t *OfflineUploadTask) StatUp(size int64, duration time.Duration)

func (*OfflineUploadTask) Status

func (t *OfflineUploadTask) Status() string

type OnlineTask

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

Task act as a action, it will pull a images from source to destination

func (*OnlineTask) Callback

func (t *OnlineTask) Callback(success bool, content string)

func (*OnlineTask) Name

func (t *OnlineTask) Name() string

func (*OnlineTask) Run

func (t *OnlineTask) Run(idx int) error

Run ids the main function of a task

func (*OnlineTask) StatDown

func (t *OnlineTask) StatDown(size int64, duration time.Duration)

func (*OnlineTask) StatUp

func (t *OnlineTask) StatUp(size int64, duration time.Duration)

func (*OnlineTask) Status

func (t *OnlineTask) Status() string

type ReaderSumWrapper

type ReaderSumWrapper struct {
	Size int64
	// contains filtered or unexported fields
}

func NewReaderSumWrapper

func NewReaderSumWrapper(reader io.Reader) *ReaderSumWrapper

func (*ReaderSumWrapper) Read

func (r *ReaderSumWrapper) Read(p []byte) (int, error)

type Repo

type Repo struct {
	Name       string `yaml:"name,omitempty"`
	User       string `yaml:"user"`
	Registry   string `yaml:"registry"`
	Password   string `yaml:"password"`
	Repository string `yaml:"repository,omitempty"`
}

type RepoURL

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

The RepoURL will divide a images url to <registry>/<namespace>/<repo>:<tag>

func NewRepoURL

func NewRepoURL(url string) (*RepoURL, error)

NewRepoURL creates a RepoURL

func (*RepoURL) GetNamespace

func (r *RepoURL) GetNamespace() string

GetNamespace returns the namespace in a url

func (*RepoURL) GetOriginURL

func (r *RepoURL) GetOriginURL() string

GetOriginURL returns the whole url

func (*RepoURL) GetRegistry

func (r *RepoURL) GetRegistry() string

GetRegistry returns the registry in a url

func (*RepoURL) GetRepo

func (r *RepoURL) GetRepo() string

GetRepo returns the repository in a url

func (*RepoURL) GetRepoWithNamespace

func (r *RepoURL) GetRepoWithNamespace() string

GetRepoWithNamespace returns namespace/repository in a url

func (*RepoURL) GetRepoWithTag

func (r *RepoURL) GetRepoWithTag() string

GetRepoWithTag returns repository:tag in a url

func (*RepoURL) GetTag

func (r *RepoURL) GetTag() string

GetTag returns the tag in a url

func (*RepoURL) GetURL

func (r *RepoURL) GetURL() string

GetURL returns the whole url

func (*RepoURL) GetURLWithoutTag

func (r *RepoURL) GetURLWithoutTag() string

GetURLWithoutTag returns registry/namespace/repository in a url

type SingleTarWriter

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

func NewSingleTarWriter

func NewSingleTarWriter(ctx *TaskContext, filename string, compression string) (*SingleTarWriter, error)

func (*SingleTarWriter) PutFile

func (s *SingleTarWriter) PutFile(filename string)

func (*SingleTarWriter) Run

func (s *SingleTarWriter) Run()

func (*SingleTarWriter) SaveDockerMeta

func (s *SingleTarWriter) SaveDockerMeta(cm *CompressionMetadata)

func (*SingleTarWriter) SetQuit

func (s *SingleTarWriter) SetQuit()

type SquashfsTar

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

func NewSquashfsTar

func NewSquashfsTar(tempPath string, workPath string, squashfsFileName string) (*SquashfsTar, error)

func (*SquashfsTar) AppendFileStream

func (w *SquashfsTar) AppendFileStream(blobName string, size int64, reader io.ReadCloser) error

func (*SquashfsTar) AssembleTarStream

func (w *SquashfsTar) AssembleTarStream(hex string) (io.Reader, error)

func (*SquashfsTar) DisassembleTarStream

func (w *SquashfsTar) DisassembleTarStream(hex string, size int64, reader io.ReadCloser) error

func (*SquashfsTar) GetFileStream

func (w *SquashfsTar) GetFileStream(hex string) (io.Reader, error)

func (*SquashfsTar) TarSplitReader

func (w *SquashfsTar) TarSplitReader(hex string) (io.ReadCloser, error)

type StderrWrapper

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

func (*StderrWrapper) Write

func (r *StderrWrapper) Write(p []byte) (int, error)

type StdoutWrapper

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

func (*StdoutWrapper) Write

func (r *StdoutWrapper) Write(p []byte) (int, error)

type Task

type Task interface {
	Run(int) error
	Name() string
	Callback(bool, string)
	StatDown(int64, time.Duration)
	StatUp(int64, time.Duration)
	Status() string
}

func NewOfflineDownTask

func NewOfflineDownTask(ctx *TaskContext, url string, is *ImageSource) Task

func NewOfflineUploadTask

func NewOfflineUploadTask(ctx *TaskContext, ids *ImageDestination, url string, path string) Task

func NewOnlineTask

func NewOnlineTask(source *ImageSource, destination *ImageDestination, ctx *TaskContext) Task

NewTask creates a task

func NewOnlineTaskCallback

func NewOnlineTaskCallback(source *ImageSource, destination *ImageDestination, ctx *TaskContext, callback func(bool, string)) Task

type TaskContext

type TaskContext struct {
	Cache        *LocalCache
	Temp         *LocalTemp
	History      *History
	TarWriter    []*ImageCompressedTarWriter
	SingleWriter *SingleTarWriter
	CompMeta     *CompressionMetadata
	SquashfsTar  *SquashfsTar
	Context      context.Context
	CancelFunc   context.CancelFunc
	Notify       Notify
	DockerTarget string
	// contains filtered or unexported fields
}

func NewTaskContext

func NewTaskContext(log CtxLogger, lc *LocalCache, lt *LocalTemp) *TaskContext

func (*TaskContext) Cancel

func (t *TaskContext) Cancel() bool

func (*TaskContext) CloseTarWriter

func (t *TaskContext) CloseTarWriter()

func (*TaskContext) CreateCompressionMetadata

func (t *TaskContext) CreateCompressionMetadata(compressor string) error

func (*TaskContext) CreateSingleWriter

func (t *TaskContext) CreateSingleWriter(pathname string, filename string, compression string) error

func (*TaskContext) CreateSquashfsTar

func (t *TaskContext) CreateSquashfsTar(tempPath string, workPath string, squashfsFileName string) error

func (*TaskContext) CreateTarWriter

func (t *TaskContext) CreateTarWriter(pathname string, filename string, compression string, num int) error

func (*TaskContext) Debug

func (t *TaskContext) Debug(logStr string)

func (*TaskContext) Error

func (t *TaskContext) Error(logStr string)

func (*TaskContext) Errorf

func (t *TaskContext) Errorf(format string, args ...interface{}) error

func (*TaskContext) GetLogger

func (t *TaskContext) GetLogger() CtxLogger

func (*TaskContext) GetStatus

func (t *TaskContext) GetStatus() string

func (*TaskContext) GetTotalTask

func (t *TaskContext) GetTotalTask() int

func (*TaskContext) Info

func (t *TaskContext) Info(logStr string)

func (*TaskContext) Reset

func (t *TaskContext) Reset()

func (*TaskContext) StatDown

func (t *TaskContext) StatDown(size int64, duration time.Duration)

func (*TaskContext) StatUp

func (t *TaskContext) StatUp(size int64, duration time.Duration)

func (*TaskContext) UpdateCurrentConn

func (t *TaskContext) UpdateCurrentConn(n int)

func (*TaskContext) UpdateFailedTask

func (t *TaskContext) UpdateFailedTask(n int)

func (*TaskContext) UpdateInvalidTask

func (t *TaskContext) UpdateInvalidTask(n int)

func (*TaskContext) UpdateSecEnd

func (t *TaskContext) UpdateSecEnd(n int64)

func (*TaskContext) UpdateSecStart

func (t *TaskContext) UpdateSecStart(n int64)

func (*TaskContext) UpdateTotalTask

func (t *TaskContext) UpdateTotalTask(n int)

func (*TaskContext) UpdateWaitTask

func (t *TaskContext) UpdateWaitTask(n int)

type YamlCfg

type YamlCfg struct {
	SrcRepos   []Repo           `yaml:"source,omitempty"`
	DstRepos   []Repo           `yaml:"target,omitempty"`
	MaxConn    int              `yaml:"maxconn,omitempty"`
	Retries    int              `yaml:"retries,omitempty"`
	SingleFile bool             `yaml:"singlefile,omitempty"`
	DockerFile bool             `yaml:"dockerfile,omitempty"`
	Compressor string           `yaml:"compressor,omitempty"`
	Squashfs   string           `yaml:"squashfs,omitempty"`
	Cache      LocalCache       `yaml:"cache,omitempty"`
	Lang       string           `yaml:"lang,omitempty"`
	KeepTemp   bool             `yaml:"keeptemp,omitempty"`
	OutPrefix  string           `yaml:"outprefix,omitempty"`
	Interval   int              `yaml:"interval,omitempty"`
	DingTalk   []DingTalkAccess `yaml:"dingtalk,omitempty"`
}

Jump to

Keyboard shortcuts

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