Skip to content

add include/exclude support - #3583

Merged
vito merged 5 commits into
dagger:mainfrom
vito:include-exclude
Oct 29, 2022
Merged

vito merged 5 commits into
dagger:mainfrom
vito:include-exclude

Conversation

@vito

@vito vito commented Oct 28, 2022 •

Copy link
Copy Markdown
Contributor

Adds include/exclude filters to the following APIs:

type Directory {
  withDirectory(path: String!, directory: DirectoryID!, exclude: [String!], include: [String!]): Directory!
}

type Host {
  workdir(exclude: [String!], include: [String!]): Directory!
  directory(path: String!, exclude: [String!], include: [String!]): Directory!
}

@vito
vito force-pushed the include-exclude branch 2 times, most recently from 47176e8 to 40ea699 Compare October 28, 2022 20:07
Comment thread core/directory.go Outdated

@jlongtine jlongtine Oct 28, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vito I'm wondering if we should allow setting AllowWildcard in llb.CopyInfo. Thoughts?

This should allow (dir *Directory) WithDirectory() to work the same as (host *Host) Directory()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should just always set it to true. It looks like we did that before. 🤔 I'll make that change and @sipsma can tell me if it's a bad idea. :P

AllowWildcard: true,

@jlongtine jlongtine Oct 28, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, @vito! I'm excited to have this!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, I'm not actually sure how this would be used, since the wildcard is applied to the source directory meaning you'd need to have a DirectoryID with a wildcard in it.

You would have to do something like this:

func TestDirectoryWithDirectoryWildcard(t *testing.T) {
	t.Parallel()

	c, ctx := connect(t)
	defer c.Close()

	dir := c.Directory().
		WithNewFile("a.txt").
		WithNewFile("b.txt").
		WithNewFile("c.txt.rar").
		WithNewFile("subdir/d.txt").
		WithNewFile("subdir/e.txt").
		WithNewFile("subdir/f.txt.rar")

	dirID, err := dir.Directory("s*").ID(ctx)
	require.NoError(t, err)

	entries, err := c.Directory().WithDirectory(dirID, "").Entries(ctx)
	require.NoError(t, err)
	require.Equal(t, []string{"d.txt", "e.txt", "f.txt.rar"}, entries)
}

The dir.Directory("s*") is what feels weird, because that gives you an object that presumes it's going to be used for copying in to somewhere.

@sipsma sipsma Oct 28, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with that. The corner case is that it's technically possible for files and directories to have * in their name, but like... it's hard to think of a more obscure situation. We can have an optional field to disallow wildcards too to handle that if we want, but defaulting on is good with me.

EDIT: I loaded the page before the most recent comment, above was in response to whether it should default on

@jlongtine jlongtine Oct 28, 2022 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vito Ah... I think I was misunderstanding how AllowWildcard works. (Include|Exclude)Patterns already allows wildcards, I'm guessing?

I wish the docs for buildkit were... existent... sometimes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EDIT: I loaded the page before the most recent comment, above was in response to whether it should default on

😆 Well, I added it, we can decide whether we want to keep it. It feels a little weird to me since a wildcarded DirectoryID won't work for every directory API call, but maybe it'll be useful in actual code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vito Ah... I think I was misunderstanding how AllowWildcard works. (Include|Exclude)Patterns already allows wildcards, I'm guessing?

Yeah, they already support wildcards.

Sounds like this is redundant then, I'll just revert the commit. :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically I may need it to fully implement the 0.2 API. But that might be something we can just say we won't allow.

Pull it for now. :shipit:

@vito
vito requested review from aluzzardi, shykes and sipsma October 28, 2022 21:00
vito added 2 commits October 28, 2022 17:12
this is weird since it results in a DirectoryID that only makes sense
for being used in WithDirectory.

wildcards are already supported through include/exclude where the
semantics are much more clear.

This reverts commit b9226b4.

Signed-off-by: Alex Suraci <[email protected]>

@aluzzardi aluzzardi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants