From 57770d347f5da3d7116f85b7ebee428c154e85b0 Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Thu, 31 Mar 2022 18:13:49 -0700 Subject: [PATCH] copy: support for include/exclude Signed-off-by: Andrea Luzzardi --- pkg/dagger.io/dagger/core/fs.cue | 4 ++++ pkg/universe.dagger.io/docker/build.cue | 6 ++++++ plan/task/copy.go | 27 ++++++++++++++++++------- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/pkg/dagger.io/dagger/core/fs.cue b/pkg/dagger.io/dagger/core/fs.cue index 77efee8c..3aa35479 100644 --- a/pkg/dagger.io/dagger/core/fs.cue +++ b/pkg/dagger.io/dagger/core/fs.cue @@ -76,6 +76,10 @@ import "dagger.io/dagger" source: string | *"/" // Destination path (optional) dest: string | *"/" + // Optionally exclude certain files + include: [...string] + // Optionally include certain files + exclude: [...string] // Output of the operation output: dagger.#FS } diff --git a/pkg/universe.dagger.io/docker/build.cue b/pkg/universe.dagger.io/docker/build.cue index d578e79e..9ffddd19 100644 --- a/pkg/universe.dagger.io/docker/build.cue +++ b/pkg/universe.dagger.io/docker/build.cue @@ -45,6 +45,10 @@ import ( contents: dagger.#FS source: string | *"/" dest: string | *"/" + // Optionally exclude certain files + include: [...string] + // Optionally include certain files + exclude: [...string] // Execute copy operation _copy: core.#Copy & { @@ -52,6 +56,8 @@ import ( "contents": contents "source": source "dest": dest + "include": include + "exclude": exclude } output: #Image & { diff --git a/plan/task/copy.go b/plan/task/copy.go index 172cb064..f2c759d7 100644 --- a/plan/task/copy.go +++ b/plan/task/copy.go @@ -49,18 +49,31 @@ func (t *copyTask) Run(ctx context.Context, pctx *plancontext.Context, s *solver return nil, err } + var filters struct { + Include []string + Exclude []string + } + + if err := v.Decode(&filters); err != nil { + return nil, err + } + + // FIXME: allow more configurable llb options + // For now we define the following convenience presets. + opts := &llb.CopyInfo{ + CopyDirContentsOnly: true, + CreateDestPath: true, + AllowWildcard: true, + IncludePatterns: filters.Include, + ExcludePatterns: filters.Exclude, + } + 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, - }, + opts, ), withCustomName(v, "Copy %s %s", sourcePath, destPath), )