utils

package
v1.7.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HangarGitHubURL         = "https://github.com/cnrancher/hangar"
	DockerHubRegistry       = "docker.io"
	CacheCloneRepoDirectory = "charts-repo-cache"
	MAX_WORKER_NUM          = 20
	MIN_WORKER_NUM          = 1

	// Deprecated
	SavedImageListFile = "saved-images-list.json"
	// Deprecated
	CacheImageDirectory = "saved-image-cache"
)

Variables

View Source
var (
	ErrVersionIsEmpty   = errors.New("version is empty string")
	ErrNoAvailableImage = errors.New("no avaiable image for specified arch and os")
)
View Source
var (
	Version   = "v1.7.0-dev"
	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 CopyPolicy added in v1.7.0

func CopyPolicy(src *signature.Policy) (*signature.Policy, error)

func CopySystemContext added in v1.7.0

func CopySystemContext(src *types.SystemContext) *types.SystemContext

func DecodeBase64

func DecodeBase64(s string) (string, error)

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 GetImageName added in v1.5.0

func GetImageName(image string) string

GetImageName gets the image name, example:

nginx:latest -> nginx
reg.io/nginx:latest -> nginx
library/nginx:latest -> nginx
reg.io/library/nginx -> nginx

func GetImageTag added in v1.7.0

func GetImageTag(image string) string

GetImageTag gets the image tag, example:

nginx:latest -> latest
reg.io/nginx:1.22 -> 1.22
library/nginx -> latest
reg.io/library/nginx -> latest

func GetProjectName

func GetProjectName(image string) string

GetProjectName gets the project name of the image, example:

nginx -> "library"
docker.io/nginx -> "library"
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 PrintObject added in v1.7.0

func PrintObject(a any) string

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)
user/nginx --> nginx (remove project name)
reg.io/user/nginx --> reg.io/nginx (remove project name)

If `project` set, example:

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

func SaveJson

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

func SaveSlice

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

func Scanf added in v1.7.0

func Scanf(ctx context.Context, format string, a ...any) (int, 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 SystemContextWithSharedBlobDir added in v1.7.0

func SystemContextWithSharedBlobDir(sysctx *types.SystemContext, dir string) *types.SystemContext

func SystemContextWithTlsVerify

func SystemContextWithTlsVerify(sysctx *types.SystemContext, tlsVerify bool) *types.SystemContext

func ToObj

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

Types

This section is empty.

Jump to

Keyboard shortcuts

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