Commit Graph
18838 Commits
Author SHA1 Message Date
Lucas Bajolet 50ef9ce990 test: simplify plugin build function
The NewPluginBuildConfig function was essentially a shortcut to
`version.Must(version.NewSemver(v))', which is superfluous at this
point, we can directly pass the version string to BuildSimplePlugin and
let that function do the creation/check.
2024-06-10 09:59:32 -04:00
Lucas Bajolet c7e11f4bf2 test: remove unnecessary testing.T arg
Since the MakePluginDir function takes the TestSuite as receiver, we
don't need to additionally pass in a reference to testing.T, since the
test suite already contains one instance, and offers a function to get
it from.
2024-06-10 09:59:32 -04:00
Lucas Bajolet 99f3546e32 test: remove PluginVersionConfig struct
The PluginVersionConfig structure was first introduced when building
the early versions of the test package, but it was an unnecessary
abstraction over go-version.Version.

So we remove that structure definition, and instead we directly use the
version for building those temporary plugins.
2024-06-10 09:59:32 -04:00
Lucas Bajolet ba4b8b2b68 test: add CopyFile convenience function to pkg
The CopyFile function is essentially a go recreation of the `cp'
command, which copies one file from a source path to a destination
directory or file.

This can be used for several tests in the future.
2024-06-10 09:59:32 -04:00
Lucas Bajolet 2d7f523bd3 test/templates: add loading test templates
The loading_test had been added to the repository at first, but were not
versioned at that time, making those tests impossible to run on CI.
2024-06-10 09:59:32 -04:00
Lucas Bajolet 6a8e888b0d test: return cleanup function for temp plugin dirs
When creating a temporary plugin directory, we had to build a cleanup
function, which could be as simple as `os.Mkdirall` without any kind of
warning that a directory failed to be cleaned-up, or we could do some
more work in order to report the possible issues around this.

That code would quickly be redundant, as there's not a ton of
variability in the code that can be written for this step, so we
abstract it through a pre-defined cancellation function which can be
safely defer invoked.
2024-06-10 09:59:32 -04:00
Lucas Bajolet 0d3f1da016 test: call different packer cmds for loading tests 2024-06-10 09:59:32 -04:00
Lucas Bajolet 700bdd9630 test: infer gadget name from struct name
Creating the Name() function for every gadget we have is superfluous a
bit, as we're essentially parroting the name of the test itself as
implementation for the function.

So instead of requiring every checker implements `Name', we now default
to returning the type name, but if the Name function exists for the
checker, we invoke it and return the value for that function.

This allows us to only define the function where needed, and not
systematically.
2024-06-10 09:59:32 -04:00
Lucas Bajolet 1a80508c26 test/suite: compile plugins in parallel
Since compiling plugins is quick, but each invocation still takes a bit
of time, we run those compilation jobs in parallel to shave of a couple
seconds from a test run.
2024-06-10 09:59:32 -04:00
Lucas Bajolet 486c1d3dcb test: add base suite for core acceptance testing
Acceptance testing, i.e. running Packer core commands in a controlled
environment and ensuring the behaviour is consistent to what we
expect/document, is not something we have a robust and usable framework
for at the moment.

This commit is a proposal for a base testing framework of the sort, that
is meant to be shipped with packer core, and which will eventually host
most of the tests we currently do in command where we mock an
environment.
2024-06-10 09:59:32 -04:00
Lucas Bajolet 664a230930 test: add mini plugin for testing
The mini plugin implemented here is a minimal Packer plugin that we use
for acceptance testing Packer core.

There's a few components exposed so we can write templates using it, and
make sure Packer interprets it all as it should, and runs/errors as we
expect it.
2024-06-10 09:59:32 -04:00
Lucas BajoletandWilken Rivera 280266163c docs: add plugin loading spec documentation (#13024)
* docs: add plugin loading spec documentation

The logic for discovering and loading plugins is not well documented on
the current documentation.
This causes issues for users that have to troubleshoot why a particular
plugin cannot be found or installed, so this commit adds a specification
document, detailing what are Packer's expectations when it comes to
discovering plugins.

* Apply suggestions from code review

* Update plugin loading specification navbar

---------
Co-authored-by: Wilken Rivera <[email protected]>
2024-06-10 09:56:14 -04:00
Lucas Bajolet 3d453f54f8 Makefile: bump golangci-lint to 1.54.0
The acceptance tests were failing to be run on CI as the linter reported
some typecheck mismatches.

This could be due to an older version of golangci-lint running on them,
so we bump it to v1.54.0, empirically determined as when the lint
started being adequately reported.
2024-06-07 14:36:39 -04:00
Lucas Bajolet 39856d3d58 golangci: remove deadcode/varcheck
Both linters are not supported anymore and trigger warnings every time
we try to lint our code.

To not see those warnings anymore, we remove them from the
configuration.
2024-06-07 14:36:39 -04:00
David Guo deee49de54 add missing return value when creating new XZ reader and writer (#13021) 2024-06-05 10:14:19 -04:00
hashicorp-tsccr[bot] 4bd7e951b7 Result of tsccr-helper -log-level=info gha update . 2024-06-03 14:20:36 -04:00
Alex Boutin 3fb6b76701 Fixed wrong parameter in doc 2024-06-03 10:09:35 -04:00
komisan19 9390f717ca refactor: remove deprecated function 2024-06-03 10:07:33 -04:00
IAMDAVID0920 d625694a88 refactor: remove deprecated InitializePluginVersion, replace with NewPluginVersion 2024-06-03 09:37:30 -04:00
Lucas Bajolet 361a432eac version: bump main to 1.12.0-dev
Since we released 1.11.0 today, we need to have main point to the next
minor release of Packer so CI succeeds, otherwise we get an unexpected
output for the version being out-of-date.
2024-05-31 15:17:52 -04:00
d75975821f Update plugins install docs for v1.11.0 (#12995)
* IPE-727 first commit, adds release notes

* content for the 1.11 release notes

* updates to init CLI reference

* updates to install plugins CLI reference

* updates to source information on the packer block configuration reference

* updated Packer configuration page

* updated plugins installation overview page

* updated plugins installation usage page

* added Upgrades section

* added outline for an upgrade page for this version

* added comments for upgrade page outline

* renamed install plugins mdx and added redirects

* Apply suggestions from code review

Co-authored-by: Lucas Bajolet <[email protected]>

* fix nav

* fix bad links

* applying additional feedback

* Apply suggestions from code review

Co-authored-by: Lucas Bajolet <[email protected]>

* integrated rationale into release notes

* removed 'upgrade from older version' section in the upgrade instructions

* docs: fill-in the upgrade/1.11 document

* Apply suggestions from code review

Co-authored-by: Wilken Rivera <[email protected]>

* edits to upgrade 1.11 and release note

* Apply suggestions from code review

Co-authored-by: Lucas Bajolet <[email protected]>

* Apply suggestions from code review

Co-authored-by: Lucas Bajolet <[email protected]>

---------

Co-authored-by: Lucas Bajolet <[email protected]>
Co-authored-by: Lucas Bajolet <[email protected]>
Co-authored-by: Wilken Rivera <[email protected]>
2024-05-31 14:52:47 -04:00
Steven Kalt 766c3d7fef docs: consistent code blocks around types 2024-05-31 11:15:55 -04:00
Wilken Rivera a5d220e0a2 CHANGELOG: Update release date for 1.11 2024-05-31 09:18:24 -04:00
Lucas Bajolet 2ea0889441 scripts: re-add wait for changelog listing (#13002)
This got committed by accident into another PR, and since the change was
not approved to begin with, its inclusion was a mistake, so we revert it
now.
2024-05-31 05:49:23 -04:00
Lucas Bajolet 3591d64bb3 scripts: remove wait for changelog listing 2024-05-30 13:35:48 -04:00
Lucas Bajolet bfd264beda CHANGELOG: update changelog for Packer 1.11.0
Since the release will happen soon, we are updating the changelog to
list all the changes before that happens.
2024-05-30 13:35:48 -04:00
Lucas Bajolet b4a843c4e2 commands: reject constraints with pre-releases (#12999)
When remotely installing a plugin, constraints are used by Packer to
determine which version of a plugin to install.

These constraints can be arbitrarily complex, including operators and
ranges in which to look for valid versions.

However, the versions specified in those constraints should always be
final releases, and not a pre-release since we don't explicitly support
remotely installing pre-releases.

This commit therefore addds checks to make sure these are reported ASAP,
even before the source is contacted to list releases and picking one to
install.
2024-05-30 14:25:21 +02:00
Lucas Bajolet 8d4a9d66ab config: rm mono-component support from config file (#12998)
The global `PACKER_CONFIG` config file was already deprecated from
Packer core, but now with 1.11.0 since we remove support for
mono-component plugins, we are also removing the capability for that
config file to declare them.

Instead of silently not using those, Packer will now error with a
message pointing to the web docs on how to manage their plugins with the
updated workflows for Packer 1.11 and above.
2024-05-30 14:25:08 +02:00
Lucas Bajolet accbe97e1e hcl2template: add text(encode|decode)base64 funcs (#12997)
Compared to Terraform, Packer was lacking a capability to encode/decode
strings to/from base64-encoded text encoded with another encoding.

This could be problematic in some cases, mainly when working with
Windows, as most of the OS uses UTF-16LE as its standard encoding for
many operations.

Therefore, we take a page from Terraform here, and add those functions
to what Packer supports in an HCL2 context.
2024-05-30 14:24:46 +02:00
Wilken Rivera 92aabc7c2e Bump github.com/hashicorp/go-getter/v2 modules to v2.2.2 2024-05-22 09:25:43 -04:00
Lucas Bajolet 5d43239654 datasource/http: don't error on 2xx code
When a server returns a code that is not 200, we error in the current
state.

This is not conformant to the HTTP norm, as anything in the 2xx range is
considered a success, so the datasource should not error in this case.

Therefore, this commit fixes the condition in which we report an error,
so that anything in the 2xx range is now considered a success by the
datasource.
2024-05-21 14:26:26 -04:00
dependabot[bot] 493ddb1f2b build(deps): bump github.com/hashicorp/hcp-sdk-go from 0.95.0 to 0.96.0
Bumps [github.com/hashicorp/hcp-sdk-go](https://github.com/hashicorp/hcp-sdk-go) from 0.95.0 to 0.96.0.
- [Release notes](https://github.com/hashicorp/hcp-sdk-go/releases)
- [Changelog](https://github.com/hashicorp/hcp-sdk-go/blob/main/CHANGELOG.md)
- [Commits](https://github.com/hashicorp/hcp-sdk-go/compare/v0.95.0...v0.96.0)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/hcp-sdk-go
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
2024-05-20 12:39:47 -04:00
Lucas Bajolet a9ba14f505 website: fix myawesomecloud reference
When updating the docs in prevision for Packer 1.11.0, we changed the
templates that show how plugins are installed/discovered with commands
like packer init.

While doing so, a template had its component renamed to coolcloud, but
the following prose did not change, making the text inconsistent.

Since there are other mentions of myawesomecloud in the codebase, we
choose to settle on this one for that example too.
2024-05-20 12:39:14 -04:00
Wilken Rivera f1efdee2dd Bump Go version to 1.12.10 to address CVE-2024-24787
Packer does not rely on CGO and is not susceptible to CVE-2024-24787 vulnerabilities,
but we are upgrading as a safeguard.
2024-05-17 10:21:10 -04:00
Lucas Bajolet 97db9d82c4 packer: fix splitting error message on pathsep 2024-05-16 13:27:50 -04:00
Lucas Bajolet ec92d231bc packer: use filepath for getting plugin basename
When Discovering plugins installed through the `Discover` function, we
use the base name of the plugin binary we discovered preliminarly, then
we match its name against a regex to extract the prefix for the plugin's
components.

Extracting the base path used to be done with `path.Base`, which while
working perfectly on UNIX systems, does not on Windows as it uses `\\`
as their path separator.

To circumvent this problem, we use the `filepath` package to extract the
base name of the plugin instead, making the discovery logic work again
on Windows.
2024-05-16 13:27:50 -04:00
Lucas Bajolet a852434410 packer: fix listing on windows with .exe ext
Listing installed plugins on Windows requires the extension to be set in
the ListOptions, otherwise they are not discovered.

While working on the discovery code, and consolidating it in a single
location, we've forgotten to pass the argument to ListInstallations, so
that makes it impossible to automatically discover installed components
on Windows.

This commit fixes this issue for the plugins required, and the general
discovery process during build/validate.
2024-05-16 13:27:50 -04:00
Lucas Bajolet 682968d0df packer: don't load plugins with metadata in name
If a plugin is installed in the PACKER_PLUGIN_PATH, and its version
contains metadata, we reject it. This is because metadata is free-form
data, which could then make it possible to have multiple conflicting
versions of a plugin installed, so we don't support it and explicitely
reject plugins like those.

A valid plugin with metadata in its version information should be
installed without its metadata part, so there can only be one variant of
the plugin installed at a specific version.
2024-05-16 13:03:29 -04:00
Wilken Rivera e161367e28 Update CHANGELOG 2024-05-15 14:50:41 -04:00
Wilken Rivera a7591c950a Add details on the importance of using required_plugins 2024-05-15 14:50:24 -04:00
Wilken Rivera 27b5f27ec9 Add section for Non-GitHub source addresses 2024-05-15 14:50:24 -04:00
Wilken Rivera ce7205ed79 required_plugins:Add source addresses section
* Document the purpose of a source address
* Add a note about non-GitHub source addresses containing one of more sub-folder parts
2024-05-15 14:50:24 -04:00
Wilken Rivera 4015e4d7be init:Document force flag option for init command 2024-05-15 14:50:24 -04:00
Lucas Bajolet ec682afc4a addrs: require at least 3 parts to source URIs 2024-05-15 14:12:41 -04:00
Estelle PoulinandWilken Rivera 47d8df33e9 Update Example of Parsing a Manifest to Use Only jq (#12894)
* Update manifest.mdx

* Remove extra space in split function

---------

Co-authored-by: Wilken Rivera <[email protected]>
2024-05-15 11:27:30 -04:00
dependabot[bot] 4444623a16 build(deps): bump github.com/hashicorp/hcp-sdk-go from 0.93.0 to 0.95.0
Bumps [github.com/hashicorp/hcp-sdk-go](https://github.com/hashicorp/hcp-sdk-go) from 0.93.0 to 0.95.0.
- [Release notes](https://github.com/hashicorp/hcp-sdk-go/releases)
- [Changelog](https://github.com/hashicorp/hcp-sdk-go/blob/main/CHANGELOG.md)
- [Commits](https://github.com/hashicorp/hcp-sdk-go/compare/v0.93.0...v0.95.0)

---
updated-dependencies:
- dependency-name: github.com/hashicorp/hcp-sdk-go
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
2024-05-15 10:16:49 -04:00
Lucas Bajolet d8a95a741b docs: update plugins install command documentation
Since the plugins install subcommand can install both remotely and
locally sourced plugins, we update the documentation for it on the
web-docs to reflect this change.
2024-05-14 14:58:55 -04:00
Lucas Bajolet c7f2508373 addrs: return error on ParsePluginSource
The ParsePluginSource function can be invoked from either a HCL2 context
(when parsing a required_plugins block), or from the command-line
itself.

While in the first context a hcl.Diagnostics is coherent, in case the
source to parse is a command-line argument, for example when installing
or removing a plugin, the error message cannot have an HCL context,
leading to errors that are incorrectly prefixed by a <nil> string dure
to the lack of a reference to attach the diagnostic to.

Therefore, in order to fix this behaviour, the logic that parses plugin
sources now returns an error, and attaching the error to an HCL subject
is done independently, if needed.
2024-05-14 14:47:06 -04:00
Lucas Bajolet 9b38e0eb5c addrs: limit source component length to 16
When specifying/installing plugins, a source URI is required for Packer
to be able to locate or install a plugin to the local plugin hierarchy.

The plugin hierarchy is based on the plugin source, where each component
in this hierarchy will become a directory.

In order to avoid sources with too many levels of nesting, causing a lot
of mkdirs, we limit the number of sources to 16 in this commit, this
should be long enough for most of our users.
2024-05-14 14:47:06 -04:00
Lucas Bajolet 9f3dd5b72a website: update install plugins docs
Since we're changing how packer manages plugin installation with 1.11.0,
we reflect those changes to the website documentation.

Now, we only describe the packer init and packer plugins install
commands, along with the `--path` flag for installing from a local
source.

The explanations of how packer discovers and picks which version of a
plugin to load are also included, along with the list of constraints
that determine whether a plugin can be considered or not to be loadable.
2024-05-14 14:05:17 -04:00