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

Support packer plugins installed plugins in JSON (and HCL without required block) #11712

Merged
merged 17 commits into from Apr 21, 2022

Conversation

JenGoldstrich
Copy link
Contributor

@JenGoldstrich JenGoldstrich commented Apr 13, 2022

This makes it so plugins installed via the packer plugins installed command will be detected in both JSON builds, and HCL builds not using the required block field. This duplicates some logic used by the required block plugin scanner.

Previously many plugin unit tests were disabled on Darwin arm64, My development machine is an Apple Silicon mac so I was able to verify these tests pass locally.

Closes #11697
Closes #11696

@JenGoldstrich JenGoldstrich changed the title Parse plugins from nested installed directories in json/non-required … [WIP] Support packer plugins installed plugins in JSON (and HCL without required block) Apr 13, 2022
@JenGoldstrich JenGoldstrich added command/plugins Issues related to the plugins management commands hcl2 labels Apr 13, 2022
Copy link
Member

@nywilken nywilken left a comment

Choose a reason for hiding this comment

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

Nice, looking at the code so far. I think we might be able to simplify the splitting logic a bit. I left a comment about looking into go-version for version checking.

I deleted the comment about version checking because I see that you are loading all found versions with the highest one being the last load plugin.

packer/plugin.go Outdated Show resolved Hide resolved
packer/plugin.go Outdated Show resolved Hide resolved
packer/plugin.go Outdated Show resolved Hide resolved
packer/plugin.go Outdated Show resolved Hide resolved
Co-authored-by: Wilken Rivera <wilken@hashicorp.com>
Co-authored-by: Wilken Rivera <wilken@hashicorp.com>
Co-authored-by: Wilken Rivera <wilken@hashicorp.com>
… an Apple Silicon specific issue (which would explain the darwin_arm64 logic I'm removing in this commit, will reintroduce if that's the case
@JenGoldstrich JenGoldstrich changed the title [WIP] Support packer plugins installed plugins in JSON (and HCL without required block) Support packer plugins installed plugins in JSON (and HCL without required block) Apr 15, 2022
@JenGoldstrich JenGoldstrich marked this pull request as ready for review April 15, 2022 20:43
@JenGoldstrich JenGoldstrich requested a review from a team as a code owner April 15, 2022 20:43
Copy link
Member

@nywilken nywilken left a comment

Choose a reason for hiding this comment

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

This looks great. I would like to pull it down and bang on it a little before merging. The added tests are so dope. Thank you for that. I did a quick search to find some other valid plugin names (e.g packer-plugin-arm-image) https://sourcegraph.com/search?q=context:global+repo:packer-plugin-*&patternType=literal.

Maybe we can take one an add it to the list for future regression testing

packer/plugin.go Outdated Show resolved Hide resolved
packer/plugin.go Outdated Show resolved Hide resolved
packer/plugin_discover_test.go Outdated Show resolved Hide resolved
packer/plugin_discover_test.go Outdated Show resolved Hide resolved
packer/plugin.go Outdated Show resolved Hide resolved
Co-authored-by: Wilken Rivera <wilken@hashicorp.com>
JenGoldstrich and others added 4 commits April 18, 2022 14:32
Co-authored-by: Wilken Rivera <wilken@hashicorp.com>
Co-authored-by: Wilken Rivera <wilken@hashicorp.com>
Co-authored-by: Wilken Rivera <wilken@hashicorp.com>
fmt.Sprintf("bird_%s", getFormattedInstalledPluginSuffix()): pluginsdk.Set{
Builders: map[string]packersdk.Builder{
"feather": nil,
"guacamole": nil,
Copy link
Member

Choose a reason for hiding this comment

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

😋

return err
}
}

pluginPaths, err = c.discoverSingle(filepath.Join(path, "packer-plugin-*"))
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible that these will overwrite the plugins installed with plugins install?

Copy link
Member

@nywilken nywilken Apr 20, 2022

Choose a reason for hiding this comment

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

You are correct. Manually installed plugins will still be the last plugins to be processed as the user may want to use a developer build of the plugin. This essentially keeps things as they are. Given that the the required_plugins block forces Packer to load the correct version of a plugin. We can safely say that a required_plugins block will always use the plugins installed with packer init or packer plugins.

That said I think having a Debug log statement here indicating that a local development plugin for packer-plugin-happycloud was loaded here would be info to provide to the user.

Looking at the Debug log adding another log line would be unnecessary

2022/04/20 15:01:59 [DEBUG] Discovered plugin: amazon = /Users/packertester/.packer.d/plugins/github.com/hashicorp/amazon/packer-plugin-amazon_v1.0.7_x5.0_darwin_amd64
2022/04/20 15:01:59 [DEBUG] Discovered plugin: amazon = /Users/packertester/.packer.d/plugins/github.com/hashicorp/amazon/packer-plugin-amazon_v1.0.8_x5.0_darwin_amd64
2022/04/20 15:01:59 [DEBUG] Discovered plugin: amazon = /Users/packertester/.packer.d/plugins/github.com/hashicorp/amazon/packer-plugin-amazon_v1.0.9_x5.0_darwin_amd64
2022/04/20 15:01:59 [DEBUG] Discovered plugin: docker = /Users/packertester/.packer.d/plugins/github.com/hashicorp/docker/packer-plugin-docker_v1.0.3_x5.0_darwin_amd64
2022/04/20 15:01:59 [DEBUG] Discovered plugin: ami-copy = /Users/packertester/.packer.d/plugins/github.com/martinbaillie/ami-copy/packer-plugin-ami-copy_v1.8.0_x5.0_darwin_amd64
2022/04/20 15:01:59 [DEBUG] Discovered plugin: comment = /Users/packertester/.packer.d/plugins/github.com/sylviamoss/comment/packer-plugin-comment_v0.2.24_x5.0_darwin_amd64
2022/04/20 15:01:59 [INFO] found external [chroot ebs ebssurrogate ebsvolume instance] builders from amazon plugin
2022/04/20 15:01:59 [INFO] found external [import] post-processors from amazon plugin
2022/04/20 15:01:59 found external [ami parameterstore secretsmanager] datasource from amazon plugin
2022/04/20 15:01:59 [INFO] found external [-packer-default-plugin-name-] builders from docker plugin
2022/04/20 15:01:59 [INFO] found external [import push save tag] post-processors from docker plugin
2022/04/20 15:01:59 [INFO] found external [-packer-default-plugin-name-] post-processors from ami-copy plugin
2022/04/20 15:01:59 found external [-packer-default-plugin-name-] provisioner from comment plugin
2022/04/20 15:01:59 [DEBUG] Discovered plugin: amazon = /Users/packertester/.packer.d/plugins/packer-plugin-amazon
2022/04/20 15:01:59 [DEBUG] Discovered plugin: comment = /Users/packertester/.packer.d/plugins/packer-plugin-comment
2022/04/20 15:01:59 [DEBUG] Discovered plugin: docker = /Users/packertester/.packer.d/plugins/packer-plugin-docker

Copy link
Member

@sylviamoss sylviamoss left a comment

Choose a reason for hiding this comment

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

I haven't tried it myself, but it looks good :thu]

Copy link
Member

@nywilken nywilken left a comment

Choose a reason for hiding this comment

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

Nice work these changes look great. I'm going to merge in the checksum changes PR before merging this PR.

…packer plugins subcommand (#11732)

* Update multi-component plugin discover logic

This change copies a bit of the logic in hcl2template/plugin in order to
strengthen the check for multi-component plugins installed via the
`packer plugins install` commands.

* Replace ioutil with os pkg

In go1.16 the ioutil std lib package was deprecated in favor of the os
and io packages. This change just updates all Temp creation methods to
their os pkg equivalents.
packer/plugin.go Outdated Show resolved Hide resolved
packer/plugin.go Outdated Show resolved Hide resolved
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
command/plugins Issues related to the plugins management commands hcl2
Projects
None yet
3 participants