util

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2018 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// RetrieveRemoteImage downloads an image from a remote location
	RetrieveRemoteImage = remoteImage
)

Functions

func AddVolumePathToWhitelist added in v0.4.0

func AddVolumePathToWhitelist(path string) error

AddVolumePathToWhitelist adds the given path to the whitelist with PrefixMatchOnly set to true. Snapshotting will ignore paths prefixed with the volume, but the volume itself will not be ignored.

func CacheHasher added in v0.4.0

func CacheHasher() func(string) (string, error)

CacheHasher takes into account everything the regular hasher does except for mtime

func CheckWhitelist added in v0.3.0

func CheckWhitelist(path string) (bool, error)

func ChildDirInWhitelist

func ChildDirInWhitelist(path, directory string) bool

ChildDirInWhitelist returns true if there is a child file or directory of the path in the whitelist

func ConfigureLogging added in v0.4.0

func ConfigureLogging(logLevel string) error

ConfigureLogging sets the logrus logging level and forces logs to be colorful (!)

func ContainsWildcards

func ContainsWildcards(paths []string) bool

ContainsWildcards returns true if any entry in paths contains wildcards

func CopyDir

func CopyDir(src, dest string) ([]string, error)

CopyDir copies the file or directory at src to dest It returns a list of files it copied over

func CopyFile

func CopyFile(src, dest string) error

CopyFile copies the file at src to dest

func CopySymlink(src, dest string) error

CopySymlink copies the symlink at src to dest

func CreateFile

func CreateFile(path string, reader io.Reader, perm os.FileMode, uid uint32, gid uint32) error

CreateFile creates a file at path and copies over contents from the reader

func DeleteFilesystem

func DeleteFilesystem() error

DeleteFilesystem deletes the extracted image file system

func DestinationFilepath

func DestinationFilepath(src, dest, cwd string) (string, error)

DestinationFilepath returns the destination filepath from the build context to the image filesystem If source is a file:

If dest is a dir, copy it to /dest/relpath
If dest is a file, copy directly to dest

If source is a dir:

Assume dest is also a dir, and copy to dest/relpath

If dest is not an absolute filepath, add /cwd to the beginning

func DetectFilesystemWhitelist added in v0.7.0

func DetectFilesystemWhitelist(path string) error

Get whitelist from roots of mounted files Each line of /proc/self/mountinfo is in the form: 36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue (1)(2)(3) (4) (5) (6) (7) (8) (9) (10) (11) Where (5) is the mount point relative to the process's root From: https://www.kernel.org/doc/Documentation/filesystems/proc.txt

func DownloadFileToDest

func DownloadFileToDest(rawurl, dest string) error

DownloadFileToDest downloads the file at rawurl to the given dest for the ADD command From add command docs:

  1. If <src> is a remote file URL: - destination will have permissions of 0600 - If remote file has HTTP Last-Modified header, we set the mtime of the file to that timestamp

func FilepathExists

func FilepathExists(path string) bool

FilepathExists returns true if the path exists

func GetBucketAndItem added in v0.2.0

func GetBucketAndItem(context string) (string, string)

func GetFSFromImage

func GetFSFromImage(root string, img v1.Image) ([]string, error)

GetFSFromImage extracts the layers of img to root It returns a list of all files extracted

func GetUserFromUsername added in v0.2.0

func GetUserFromUsername(userStr string, groupStr string) (string, string, error)

func HasFilepathPrefix

func HasFilepathPrefix(path, prefix string, prefixMatchOnly bool) bool

HasFilepathPrefix checks if the given file path begins with prefix

func Hasher

func Hasher() func(string) (string, error)

Hasher returns a hash function, used in snapshotting to determine if a file has changed

func IsDestDir

func IsDestDir(path string) bool

func IsFileLocalTarArchive

func IsFileLocalTarArchive(src string) bool

IsFileLocalTarArchive returns true if the file is a local tar archive

func IsInWhitelist added in v0.7.0

func IsInWhitelist(path string) bool

func IsSrcRemoteFileURL

func IsSrcRemoteFileURL(rawurl string) bool

func IsSrcsValid

func IsSrcsValid(srcsAndDest instructions.SourcesAndDest, resolvedSources []string, root string) error

func MtimeHasher

func MtimeHasher() func(string) (string, error)

MtimeHasher returns a hash function, which only looks at mtime to determine if a file has changed. Note that the mtime can lag, so it's possible that a file will have changed but the mtime may look the same.

func ParentDirectories

func ParentDirectories(path string) []string

ParentDirectories returns a list of paths to all parent directories Ex. /some/temp/dir -> [/, /some, /some/temp, /some/temp/dir]

func RelativeFiles

func RelativeFiles(fp string, root string) ([]string, error)

RelativeFiles returns a list of all files at the filepath relative to root

func ResolveEnvironmentReplacement

func ResolveEnvironmentReplacement(value string, envs []string, isFilepath bool) (string, error)

ResolveEnvironmentReplacement resolves replacing env variables in some text from envs It takes in a string representation of the command, the value to be resolved, and a list of envs (config.Env) Ex: fp = $foo/newdir, envs = [foo=/foodir], then this should return /foodir/newdir The dockerfile/shell package handles processing env values It handles escape characters and supports expansion from the config.Env array Shlex handles some of the following use cases (these and more are tested in integration tests) ""a'b'c"" -> "a'b'c" "Rex\ The\ Dog \" -> "Rex The Dog" "a\"b" -> "a"b"

func ResolveEnvironmentReplacementList

func ResolveEnvironmentReplacementList(values, envs []string, isFilepath bool) ([]string, error)

ResolveEnvironmentReplacementList resolves a list of values by calling resolveEnvironmentReplacement

func ResolveSources

func ResolveSources(srcsAndDest instructions.SourcesAndDest, root string) ([]string, error)

ResolveSources resolves the given sources if the sources contains wildcards It returns a list of resolved sources

func RetrieveConfigFile added in v0.4.0

func RetrieveConfigFile(sourceImage partial.WithConfigFile) (*v1.ConfigFile, error)

RetrieveConfigFile returns the config file for an image

func RetrieveSourceImage added in v0.3.0

func RetrieveSourceImage(stage config.KanikoStage, opts *config.KanikoOptions) (v1.Image, error)

RetrieveSourceImage returns the base image of the stage at index

func SHA256 added in v0.4.0

func SHA256(r io.Reader) (string, error)

SHA256 returns the shasum of the contents of r

func URLDestinationFilepath

func URLDestinationFilepath(rawurl, dest, cwd string) string

URLDestinationFilepath gives the destination a file from a remote URL should be saved to

func UnpackCompressedTar

func UnpackCompressedTar(path, dir string) error

UnpackCompressedTar unpacks the compressed tar at path to dir

func UnpackLocalTarArchive

func UnpackLocalTarArchive(path, dest string) ([]string, error)

UnpackLocalTarArchive unpacks the tar archive at path to the directory dest Returns the files extracted from the tar archive

func UpdateConfigEnv

func UpdateConfigEnv(newEnvs []instructions.KeyValuePair, config *v1.Config, replacementEnvs []string) error

Types

type Tar added in v0.4.0

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

Tar knows how to write files to a tar file.

func NewTar added in v0.4.0

func NewTar(f io.Writer) Tar

NewTar will create an instance of Tar that can write files to the writer at f.

func (*Tar) AddFileToTar added in v0.4.0

func (t *Tar) AddFileToTar(p string) error

AddFileToTar adds the file at path p to the tar

func (*Tar) Close added in v0.4.0

func (t *Tar) Close()

Close will close any open streams used by Tar.

func (*Tar) Whiteout added in v0.4.0

func (t *Tar) Whiteout(p string) error

type WhitelistEntry added in v0.4.0

type WhitelistEntry struct {
	Path            string
	PrefixMatchOnly bool
}

Jump to

Keyboard shortcuts

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