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 e10025d688 Refactor op/script/component loading and spec validation
Signed-off-by: Solomon Hykes <sh.github.6811@hykes.org>
2021-01-25 11:36:18 -08:00

49 lines
1.1 KiB
Go

package dagger
import (
"context"
"fmt"
"github.com/moby/buildkit/client/llb"
"github.com/pkg/errors"
)
type Mount struct {
dest string
v *Value
}
func newMount(v *Value, dest string) (*Mount, error) {
if !v.Exists() {
return nil, ErrNotExist
}
return &Mount{
v: v,
dest: dest,
}, nil
}
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 := newExecutable(mnt.v.Lookup("from"))
if err != nil {
return nil, errors.Wrap(err, "from")
}
fromFS, err := from.Execute(ctx, s.Scratch(), nil)
if err != nil {
return nil, err
}
return llb.AddMount(mnt.dest, fromFS.LLB()), nil
}