Merge pull request #1983 from aluzzardi/copy-filters

copy: support for include/exclude
This commit is contained in:
Helder Correia 2022-04-01 17:52:36 +00:00 committed by GitHub
commit b482c19b7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 7 deletions

View File

@ -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
}

View File

@ -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 & {

View File

@ -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),
)