utils

package
v1.5.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HangarGitHubURL         = "https://github.com/cnrancher/hangar"
	DockerLoginURL          = "https://hub.docker.com/v2/users/login/"
	DockerHubRegistry       = "docker.io"
	DockerConfigFile        = ".docker/config.json"
	SavedImageListFile      = "saved-images-list.json"
	CacheImageDirectory     = "saved-image-cache"
	CacheCloneRepoDirectory = "charts-repo-cache"
	ETC_SSL_FILE            = "/etc/ssl/certs/ca-certificates.crt"
	MAX_WORKER_NUM          = 20
	MIN_WORKER_NUM          = 1
)

Variables

View Source
var (
	EnvDestUsername   = os.Getenv("DEST_USERNAME")
	EnvDestPassword   = os.Getenv("DEST_PASSWORD")
	EnvDestRegistry   = os.Getenv("DEST_REGISTRY")
	EnvSourceUsername = os.Getenv("SOURCE_USERNAME")
	EnvSourcePassword = os.Getenv("SOURCE_PASSWORD")
	EnvSourceRegistry = os.Getenv("SOURCE_REGISTRY")
)

environment variables of source and destination registry url, username and password

View Source
var (
	ErrReadJsonFailed       = errors.New("failed to read value from json")
	ErrSkopeoNotFound       = errors.New("skopeo not found")
	ErrDockerNotFound       = errors.New("docker not found")
	ErrLoginFailed          = errors.New("login failed")
	ErrNoAvailableImage     = errors.New("no image available for specified arch list")
	ErrInvalidParameter     = errors.New("invalid parameter")
	ErrInvalidMediaType     = errors.New("invalid media type")
	ErrInvalidSchemaVersion = errors.New("invalid schema version")
	ErrNilPointer           = errors.New("nil pointer")
	ErrDockerBuildxNotFound = errors.New("docker buildx not found")
	ErrDirNotEmpty          = errors.New("directory is not empty")
	ErrCredsStore           = errors.New("docker config use credsStore to store password")
	ErrCredsStoreUnsupport  = errors.New("unsupported credsStore, only 'deskstop' supported")
	ErrVersionIsEmpty       = errors.New("version is empty string")
)
View Source
var (
	Version   = "v1.5.0-rc"
	GitCommit = ""
)

Functions

func AddSourceToImage

func AddSourceToImage(
	imagesSet map[string]map[string]bool,
	image string,
	sources ...string,
)

AddSourceToImage adds image into map[image][source]bool

func AppendFileLine

func AppendFileLine(fileName string, line string) error

func Base64

func Base64(s string) string

func ConstructRegistry

func ConstructRegistry(image, registryOverride string) string

ConstructRegistry will re-construct the image url:

If `registryOverride` is empty string, example:

nginx --> docker.io/nginx (add docker.io prefix)
reg.io/nginx --> reg.io/nginx (nothing changed)
reg.io/user/nginx --> reg.io/user/nginx (nothing changed)

If `registryOverride` set, example:

nginx --> ${registryOverride}/nginx (add ${registryOverride} prefix)
reg.io/nginx --> ${registryOverride}/nginx (set registry ${registryOverride})
reg.io/user/nginx --> ${registryOverride}/user/nginx (same as above)

func DecodeBase64

func DecodeBase64(s string) (string, error)

func DefaultRunCommandFunc

func DefaultRunCommandFunc(p string, i io.Reader, o io.Writer, args ...string) error

DefaultRunCommandFunc executes the command and specifies the stdin and stdout in parameters

func DeleteIfExist

func DeleteIfExist(name string) error

func EnsureDirExists

func EnsureDirExists(directory string) error

func EnsureSemverValid

func EnsureSemverValid(v string) (string, error)

func GetAbsPath

func GetAbsPath(dir string) (string, error)

func GetProjectName

func GetProjectName(image string) string

GetProjectName gets the project name of the image, example:

nginx -> ""
docker.io/nginx -> ""
library/nginx -> library
docker.io/library/nginx -> library

func GetRegistryName

func GetRegistryName(image string) string

GetRegistryName gets the registry name of the image, example:

nginx -> docker.io
reg.io/nginx -> reg.io
library/nginx -> docker.io
reg.io/library/nginx -> reg.io

func IsDirEmpty

func IsDirEmpty(name string) (bool, error)

func ReadUsernamePasswd

func ReadUsernamePasswd() (username, passwd string, err error)

func ReplaceProjectName

func ReplaceProjectName(image, project string) string

ReplaceProjectName will replace the image project name:

If `project` is empty string, the project name will be removed:

nginx --> nginx (nothing changed)
reg.io/nginx --> reg.io/nginx (nothing changed)
reg.io/user/nginx --> reg.io/nginx (remove project name)

If `project` set, example:

nginx --> ${project}/nginx (add project name)
reg.io/nginx --> reg.io/${project}/nginx (same as above)
reg.io/user/nginx --> reg.io/${project}/nginx (same as above)

func SaveJson

func SaveJson(data interface{}, fileName string) error

func SaveSlice

func SaveSlice(fileName string, data []string) error

func SemverCompare

func SemverCompare(a, b string) (int, error)

SemverCompare compares two semvers

func SemverMajorEqual

func SemverMajorEqual(a, b string) bool

func SemverMajorMinorEqual

func SemverMajorMinorEqual(a, b string) bool

func Sha256Sum

func Sha256Sum(s string) string

func ToObj

func ToObj(data interface{}, into interface{}) error

Types

type RunCmdFuncType

type RunCmdFuncType func(name string, in io.Reader, out io.Writer, args ...string) error

RunCmdFuncType defines the type of the function to execute command

Jump to

Keyboard shortcuts

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