Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] file: use excludes list to excl files when uploading a directory #12280

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion command/configtype_enumer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packer/fixconfigmode_enumer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion provisioner/file/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ type Config struct {
// the Packer run, but realize that there are situations where this may be
// unavoidable.
Generated bool `mapstructure:"generated" required:"false"`
// A list of files or directories to exclude from the upload. This is
// useful if you have a directory with many files and you only want to
// upload a few of them. This only works if you are uploading a directory
// and not a single file.
Excludes []string `mapstructure:"excludes" required:"false"`
Glyphack marked this conversation as resolved.
Show resolved Hide resolved

ctx interpolate.Context
}
Expand Down Expand Up @@ -227,7 +232,7 @@ func (p *Provisioner) ProvisionUpload(ui packersdk.Ui, comm packersdk.Communicat

// If we're uploading a directory, short circuit and do that
if info.IsDir() {
if err = comm.UploadDir(dst, src, nil); err != nil {
if err = comm.UploadDir(dst, src, p.config.Excludes); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is needed in order to path in the list of files to exclude. But the actually implementation for supporting the excludes would need to be made in the Packer SDK communicator, which this line is calling out to. At this present time the exclude argument is ignored.

https://github.com/hashicorp/packer-plugin-sdk/blob/b03e2b6b7bbc38ca6b92770b33873860e796a5e0/sdk-internals/communicator/ssh/communicator.go#L187

https://github.com/hashicorp/packer-plugin-sdk/blob/b03e2b6b7bbc38ca6b92770b33873860e796a5e0/sdk-internals/communicator/winrm/communicator.go#L149

For the excludes we will need to provide guidance on the allowed paths and/or globs that can be passed into exclude, which I think the file provisioner could take on the work of expanding.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for noticing this. I already started a PR on packer-sdk to address this. I also left a comment there about how the pattern matching should be. Could you also take a look?

hashicorp/packer-plugin-sdk#163

ui.Error(fmt.Sprintf("Upload failed: %s", err))
return err
}
Expand Down
2 changes: 2 additions & 0 deletions provisioner/file/provisioner.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion provisioner/powershell/executionpolicy_enumer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@
the Packer run, but realize that there are situations where this may be
unavoidable.

- `excludes` ([]string) - A list of files or directories to exclude from the upload. This is
useful if you have a directory with many files and you only want to
upload a few of them. This only works if you are uploading a directory
and not a single file.

<!-- End of code generated from the comments of the Config struct in provisioner/file/provisioner.go; -->