Signed-off-by: Solomon Hykes <sh.github.6811@hykes.org>
This commit is contained in:
Solomon Hykes
2021-01-05 00:37:29 -08:00
parent 22500ad9db
commit 3162ca0991
25 changed files with 1664 additions and 1296 deletions

66
dagger/component.go Normal file
View File

@@ -0,0 +1,66 @@
package dagger
import (
"context"
)
type Component struct {
v *Value
}
func (c *Component) Value() *Value {
return c.v
}
func (c *Component) Exists() bool {
// Does #dagger exist?
if c.Config().Err() != nil {
return false
}
return true
}
// Return the contents of the "#dagger" annotation.
func (c *Component) Config() *Value {
return c.Value().Get("#dagger")
}
// Verify that this component respects the dagger component spec.
//
// NOTE: calling matchSpec("#Component") is not enough because
// it does not match embedded scalars.
func (c Component) Validate() error {
return c.Config().Validate("#ComponentConfig")
}
// Return this component's compute script.
func (c Component) ComputeScript() (*Script, error) {
return c.Value().Get("#dagger.compute").Script()
}
// Compute the configuration for this component.
// Note that we simply execute the underlying compute script from an
// empty filesystem state.
// (It is never correct to pass an input filesystem state to compute a component)
func (c *Component) Compute(ctx context.Context, s Solver, out Fillable) (FS, error) {
return c.Execute(ctx, s.Scratch(), out)
}
// A component implements the Executable interface by returning its
// compute script.
// See Value.Executable().
func (c *Component) Execute(ctx context.Context, fs FS, out Fillable) (FS, error) {
script, err := c.ComputeScript()
if err != nil {
return fs, err
}
return script.Execute(ctx, fs, out)
}
func (c *Component) Walk(fn func(*Op) error) error {
script, err := c.ComputeScript()
if err != nil {
return err
}
return script.Walk(fn)
}