This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
dagger/dagger/mount.go
Solomon Hykes 3162ca0991 Refactor
Signed-off-by: Solomon Hykes <sh.github.6811@hykes.org>
2021-01-07 13:57:39 -08:00

39 lines
939 B
Go

package dagger
import (
"context"
"fmt"
"github.com/moby/buildkit/client/llb"
"github.com/pkg/errors"
)
type Mount struct {
dest string
v *Value
}
func (mnt *Mount) Validate(defs ...string) error {
return mnt.v.Validate(append(defs, "#Mount")...)
}
func (mnt *Mount) LLB(ctx context.Context, s Solver) (llb.RunOption, error) {
if err := mnt.Validate("#MountTmp"); err == nil {
return llb.AddMount(mnt.dest, llb.Scratch(), llb.Tmpfs()), nil
}
if err := mnt.Validate("#MountCache"); err == nil {
// FIXME: cache mount
return nil, fmt.Errorf("FIXME: cache mount not yet implemented")
}
// Compute source component or script, discarding fs writes & output value
from, err := mnt.v.Lookup("from").Executable()
if err != nil {
return nil, errors.Wrap(err, "from")
}
fromFS, err := from.Execute(ctx, s.Scratch(), Discard())
if err != nil {
return nil, err
}
return llb.AddMount(mnt.dest, fromFS.LLB()), nil
}