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/plan/task/copy.go
Tom Chauveau 19c0f999f4
Fix export cache issue
Resolve #1551 and #1020.
We are never returning the result of solved operations so Buildkit could not
cache the layer.
This commit implements a simple system to forward operations' result to the
main build to cache it.

Signed-off-by: Vasek - Tom C <tom.chauveau@epitech.eu>
2022-03-31 20:36:50 +02:00

79 lines
1.5 KiB
Go

package task
import (
"context"
"github.com/moby/buildkit/client/llb"
"go.dagger.io/dagger/compiler"
"go.dagger.io/dagger/plancontext"
"go.dagger.io/dagger/solver"
)
func init() {
Register("Copy", func() Task { return &copyTask{} })
}
type copyTask struct {
}
func (t *copyTask) Run(ctx context.Context, pctx *plancontext.Context, s *solver.Solver, v *compiler.Value) (*compiler.Value, error) {
var err error
input, err := pctx.FS.FromValue(v.Lookup("input"))
if err != nil {
return nil, err
}
inputState, err := input.State()
if err != nil {
return nil, err
}
contents, err := pctx.FS.FromValue(v.Lookup("contents"))
if err != nil {
return nil, err
}
contentsState, err := contents.State()
if err != nil {
return nil, err
}
sourcePath, err := v.Lookup("source").String()
if err != nil {
return nil, err
}
destPath, err := v.Lookup("dest").String()
if err != nil {
return nil, err
}
outputState := inputState.File(
llb.Copy(
contentsState,
sourcePath,
destPath,
// FIXME: allow more configurable llb options
// For now we define the following convenience presets:
&llb.CopyInfo{
CopyDirContentsOnly: true,
CreateDestPath: true,
AllowWildcard: true,
},
),
withCustomName(v, "Copy %s %s", sourcePath, destPath),
)
result, err := s.Solve(ctx, outputState, pctx.Platform.Get())
if err != nil {
return nil, err
}
fs := pctx.FS.New(result)
return compiler.NewValue().FillFields(map[string]interface{}{
"output": fs.MarshalCUE(),
})
}