llbutil

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyContainerImageDigest = "containerimage.digest"
	KeyContainerImageConfig = "containerimage.config"
)

Variables

This section is empty.

Functions

func FilterLocalFiles

func FilterLocalFiles(localPath string, includePatterns, excludePatterns []string) (localPaths []string, err error)

func FirstUpInterface

func FirstUpInterface() (string, error)

FirstUpInterface returns the mac address for the first "UP" network interface.

func LocalID

func LocalID(ctx context.Context, absPath string, opts ...llb.LocalOption) (string, error)

LocalID returns a consistent hash for this local (path + options) so that the same content doesn't get transported multiple times when referenced repeatedly.

func LocalUniqueID

func LocalUniqueID(cwd string) (string, error)

LocalUniqueID returns a consistent string that is unique per host + cwd

func NewSession

func NewSession(ctx context.Context, opts ...SessionOption) (*session.Session, error)

func OutputFromWriter

func OutputFromWriter(w io.WriteCloser) func(map[string]string) (io.WriteCloser, error)

func PositionFromLexer

func PositionFromLexer(pos lexer.Position) pb.Position

func SSHID

func SSHID(paths ...string) string

func SecretID

func SecretID(path string) string

func ShimReadonlyMountpoints

func ShimReadonlyMountpoints(opts []llb.RunOption) error

ShimReadonlyMountpoints will modify the source for readonly mounts so subsequent mounts that mount onto the readonly-mounts will have the mountpoint present.

For example if we have this code:

```hlb

run "make" with option {
	dir "/src"
	mount fs {
		local "."
	} "/src" with readonly
		mount scratch "/src/output" as buildOutput
		# ^^^^^ FAIL cannot create `output` directory for mount on readonly fs
		secret "./secret/foo.pem" "/src/secret/foo.pem"
		# ^^^^^ FAIL cannot create `./secret/foo.pm` for secret on readonly fs
	}
}

```

When containerd tries to mount /src/output on top of the /src mountpoint it will fail because /src is mounted as readonly. The work around for this is to inline create the mountpoints so that they pre-exist and containerd will not have to create them.

It can be done with HLB like:

```hlb

run "make" with option {
	dir "/src"
	mount fs {
		local "."
		mkdir "output" 0o755 # <-- this is added to ensure mountpoint exists
		mkdir "secret" 0o755            # <-- added so the secret can be mounted
		mkfile "secret/foo.pm" 0o644 "" # <-- added so the secret can be mounted
	} "/src" with readonly
		mount scratch "/src/output" as buildOutput
	}
}

```

So this function is effectively automatically adding the `mkdir` and `mkfile` instructions when it detects that a mountpoint is required to be on a readonly fs.

func WithDir

func WithDir(dir string) llb.RunOption

func WithEnv

func WithEnv(name, value string) llb.RunOption

func WithExtraHost

func WithExtraHost(host string, ip net.IP) llb.RunOption

func WithNetwork

func WithNetwork(netMode pb.NetMode) llb.RunOption

func WithReadonlyRootFS

func WithReadonlyRootFS() llb.RunOption

func WithSSHSocket

func WithSSHSocket(target string, opts ...llb.SSHOption) llb.RunOption

func WithSecret

func WithSecret(dest string, opts ...llb.SecretOption) llb.RunOption

func WithSecurity

func WithSecurity(securityMode pb.SecurityMode) llb.RunOption

func WithUser

func WithUser(user string) llb.RunOption

Types

type AllowEmptyWildcard

type AllowEmptyWildcard bool

func WithAllowEmptyWildcard

func WithAllowEmptyWildcard(ok bool) AllowEmptyWildcard

func (AllowEmptyWildcard) SetCopyOption

func (ct AllowEmptyWildcard) SetCopyOption(ci *llb.CopyInfo)

type AllowWildcard

type AllowWildcard bool

func WithAllowWildcard

func WithAllowWildcard(ok bool) AllowWildcard

func (AllowWildcard) SetCopyOption

func (ct AllowWildcard) SetCopyOption(ci *llb.CopyInfo)

type AttemptUnpack

type AttemptUnpack bool

func WithAttemptUnpack

func WithAttemptUnpack(ok bool) AttemptUnpack

func (AttemptUnpack) SetCopyOption

func (ct AttemptUnpack) SetCopyOption(ci *llb.CopyInfo)

type CacheMountOption

type CacheMountOption struct {
	ID      string
	Sharing llb.CacheMountSharingMode
}

func WithPersistentCacheDir

func WithPersistentCacheDir(id string, sharing llb.CacheMountSharingMode) CacheMountOption

type Chmod

type Chmod os.FileMode

func WithChmod

func WithChmod(mode os.FileMode) Chmod

func (Chmod) SetCopyOption

func (c Chmod) SetCopyOption(ci *llb.CopyInfo)

func (Chmod) SetSSHOption

func (c Chmod) SetSSHOption(si *llb.SSHInfo)

func (Chmod) SetSecretOption

func (c Chmod) SetSecretOption(si *llb.SecretInfo)

type Chown

type Chown string

func WithChown

func WithChown(owner string) Chown

func (Chown) SetCopyOption

func (c Chown) SetCopyOption(ci *llb.CopyInfo)

type CopyDirContentsOnly

type CopyDirContentsOnly bool

func WithCopyDirContentsOnly

func WithCopyDirContentsOnly(ok bool) CopyDirContentsOnly

func (CopyDirContentsOnly) SetCopyOption

func (ct CopyDirContentsOnly) SetCopyOption(ci *llb.CopyInfo)

type CreateDestPath

type CreateDestPath bool

func WithCreateDestPath

func WithCreateDestPath(ok bool) CreateDestPath

func (CreateDestPath) SetCopyOption

func (ct CreateDestPath) SetCopyOption(ci *llb.CopyInfo)

type CreatedTime

type CreatedTime time.Time

func WithCreatedTime

func WithCreatedTime(t time.Time) CreatedTime

func (CreatedTime) SetCopyOption

func (ct CreatedTime) SetCopyOption(ci *llb.CopyInfo)

type DirOption

type DirOption struct {
	Dir string
}

func (DirOption) SetRunOption

func (dir DirOption) SetRunOption(ei *llb.ExecInfo)

type EnvOption

type EnvOption struct {
	Name  string
	Value string
}

func (EnvOption) SetRunOption

func (env EnvOption) SetRunOption(ei *llb.ExecInfo)

type ExcludePatterns

type ExcludePatterns []string

func WithExcludePatterns

func WithExcludePatterns(excludePatterns []string) ExcludePatterns

func (ExcludePatterns) SetCopyOption

func (ep ExcludePatterns) SetCopyOption(ci *llb.CopyInfo)

func (ExcludePatterns) SetLocalOption

func (ep ExcludePatterns) SetLocalOption(li *llb.LocalInfo)

type FileInfo

type FileInfo struct {
	*types.Stat
}

func (*FileInfo) IsDir

func (fi *FileInfo) IsDir() bool

func (*FileInfo) ModTime

func (fi *FileInfo) ModTime() time.Time

func (*FileInfo) Mode

func (fi *FileInfo) Mode() os.FileMode

func (*FileInfo) Name

func (fi *FileInfo) Name() string

func (*FileInfo) Size

func (fi *FileInfo) Size() int64

func (*FileInfo) Sys

func (fi *FileInfo) Sys() interface{}
type FollowSymlinks bool
func WithFollowSymlinks(ok bool) FollowSymlinks

func (FollowSymlinks) SetCopyOption

func (ct FollowSymlinks) SetCopyOption(ci *llb.CopyInfo)

type GID

type GID int

func WithGID

func WithGID(gid int) GID

func (GID) SetSSHOption

func (gid GID) SetSSHOption(si *llb.SSHInfo)

func (GID) SetSecretOption

func (gid GID) SetSecretOption(si *llb.SecretInfo)

type GatewayOption

type GatewayOption func(r *gateway.SolveRequest)

func FrontendInput

func FrontendInput(key string, def *llb.Definition) GatewayOption

func FrontendOpt

func FrontendOpt(key, value string) GatewayOption

type HostOption

type HostOption struct {
	Host string
	IP   net.IP
}

func (HostOption) SetRunOption

func (host HostOption) SetRunOption(ei *llb.ExecInfo)

type IDOption

type IDOption string

func WithID

func WithID(id string) IDOption

func (IDOption) SetSSHOption

func (id IDOption) SetSSHOption(si *llb.SSHInfo)

func (IDOption) SetSecretOption

func (id IDOption) SetSecretOption(si *llb.SecretInfo)

type IncludePatterns

type IncludePatterns []string

func WithIncludePatterns

func WithIncludePatterns(includePatterns []string) IncludePatterns

func (IncludePatterns) SetCopyOption

func (ip IncludePatterns) SetCopyOption(ci *llb.CopyInfo)

func (IncludePatterns) SetLocalOption

func (ip IncludePatterns) SetLocalOption(li *llb.LocalInfo)

type MountRunOption

type MountRunOption struct {
	Source llb.State
	Target string
	Opts   []interface{}
}

MountRunOption gives access to capture custom MountOptions so we can easily capture if the mount is to be readonly

func (*MountRunOption) IsReadonly

func (m *MountRunOption) IsReadonly() bool

func (*MountRunOption) SetRunOption

func (m *MountRunOption) SetRunOption(es *llb.ExecInfo)

type NetworkOption

type NetworkOption struct {
	pb.NetMode
}

func (NetworkOption) SetRunOption

func (network NetworkOption) SetRunOption(ei *llb.ExecInfo)

type ReadonlyMountOption

type ReadonlyMountOption struct{}

func WithReadonlyMount

func WithReadonlyMount() ReadonlyMountOption

type ReadonlyRootFSOption

type ReadonlyRootFSOption struct{}

func (ReadonlyRootFSOption) SetRunOption

func (readonlyRootfs ReadonlyRootFSOption) SetRunOption(ei *llb.ExecInfo)

type SSHOption

type SSHOption struct {
	Dest string
	Opts []llb.SSHOption
}

func (SSHOption) SetRunOption

func (sshOpt SSHOption) SetRunOption(ei *llb.ExecInfo)

type SecretOption

type SecretOption struct {
	Dest string
	Opts []llb.SecretOption
}

func (SecretOption) SetRunOption

func (secret SecretOption) SetRunOption(ei *llb.ExecInfo)

type SecurityOption

type SecurityOption struct {
	pb.SecurityMode
}

func (SecurityOption) SetRunOption

func (security SecurityOption) SetRunOption(ei *llb.ExecInfo)

type SessionInfo

type SessionInfo struct {
	SyncTargetDir   *string
	SyncTarget      func(map[string]string) (io.WriteCloser, error)
	SyncedDirByID   map[string]filesync.SyncedDir
	FileSourceByID  map[string]secretsprovider.Source
	AgentConfigByID map[string]sockproxy.AgentConfig
}

type SessionOption

type SessionOption func(*SessionInfo)

func WithAgentConfig

func WithAgentConfig(id string, cfg sockproxy.AgentConfig) SessionOption

func WithSecretSource

func WithSecretSource(id string, source secretsprovider.Source) SessionOption

func WithSyncTarget

func WithSyncTarget(f func(map[string]string) (io.WriteCloser, error)) SessionOption

func WithSyncTargetDir

func WithSyncTargetDir(dir string) SessionOption

func WithSyncedDir

func WithSyncedDir(id string, dir filesync.SyncedDir) SessionOption

type SourcePathMountOption

type SourcePathMountOption struct {
	Path string
}

func WithSourcePath

func WithSourcePath(path string) SourcePathMountOption

type Target

type Target string

func WithTarget

func WithTarget(t string) Target

func (Target) SetSSHOption

func (t Target) SetSSHOption(si *llb.SSHInfo)

type TmpfsMountOption

type TmpfsMountOption struct{}

func WithTmpfs

func WithTmpfs() TmpfsMountOption

type UID

type UID int

func WithUID

func WithUID(uid int) UID

func (UID) SetSSHOption

func (uid UID) SetSSHOption(si *llb.SSHInfo)

func (UID) SetSecretOption

func (uid UID) SetSecretOption(si *llb.SecretInfo)

type UserOption

type UserOption struct {
	User string
}

func (UserOption) SetRunOption

func (user UserOption) SetRunOption(ei *llb.ExecInfo)

Jump to

Keyboard shortcuts

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