Commit graph

18492 commits

Author SHA1 Message Date
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
Lucas Bajolet
266c4d99d2 website: update discovery/envvar documentation
With the changes coming up for 1.11.0, we update the Packer
configuration docs so they describe the one way to load plugins, and the
two environment variables which can be set to change this behaviour.
2024-05-14 14:05:17 -04:00
Lucas Bajolet
f52502c464 website: remove trailing whitespace 2024-05-14 14:05:17 -04:00
Wilken Rivera
9f2d6ce1fc docs/plugins/remove: Update command usage text
* Add an example of piping the results of `plugins installed` to `plugins remove`
2024-05-14 13:13:22 -04:00
Lucas Bajolet
d2ade9a783 packer: register plugin components only once
When running a packer command on an HCL2 template, depending on whether
or not there are required_plugin blocks defined, Packer may need to
discover and register a plugin's components multiple times.

This is the behaviour ever since those blocks were introduced to Packer,
but given we are doing the operation multiple times, this is suboptimal.

This commit changes the way things works by first doing the restricted
discovery of plugins (as dictated by required_plugins), then proceeding
to the global discovery, with the change that subsequent component
discoveries will not have precedence over those pre-discovered anymore.

This allows us to invert the call order of both discovery phases safely,
and maintains the constraints described in the templates.
2024-05-14 11:41:18 -04:00
Lucas Bajolet
f80ba2821b packer: error multiple paths in PACKER_PLUGIN_PATH
When a user defines PACKER_PLUGIN_PATH in their environment, we need to
error if their path defines multiple directories separated by `:`.

This used to be supported, but this is removed with 1.11 as we're
simplifying the loading process for plugins, so we opted to fall-back to
only one plugin directory supported.
2024-05-10 15:11:41 -04:00
Lucas Bajolet
5ced785f2f docs: fix typo in HCP Packer artifact/version docs
In the full example for both the hcp-packer-artifact and
hcp-packer-version the hcp-packer-version reference in the example
template was mistakenly spelled as "hcp_packer_version", which won't
work, so we fix that typo here.
2024-05-10 09:36:47 -04:00
Wilken Rivera
20345f9118 Add check to prevent the installation of version constraints matching a prerelease
* Refactor InstallError string messages
2024-05-08 16:01:29 -04:00
Wilken Rivera
11dc684334 Add ConintuableInstallError for continuing installation on version mismatches 2024-05-08 16:01:29 -04:00
Wilken Rivera
2e8bdb5c4a Use single buffer for storing binary file before writes
* Only create plugin directories if there is  potential plugin install
2024-05-08 16:01:29 -04:00
Wilken Rivera
2ca5b2707c Add PrereleaseError for handling failed pre-release version installs
```
~>  packer init mondoo_req.pkr.hcl
Failed getting the "github.com/mondoohq/cnspec" plugin:
error:
Remote installation of the plugin version 10.8.1-dev is unsupported.
This is likely an upstream issue with the 10.8.1 release, which should be reported.
If you require this specific version of the plugin, download the binary and install it manually.

packer plugins install --path '<plugin_binary>' github.com/mondoohq/cnspec

```
2024-05-08 16:01:29 -04:00
Wilken Rivera
eafdda8a94 Update plugin-getter version matching check
This change is an attempt to remove the need for additional temporary files, along with
calls to stat the temp files, to reduce the number of files being created, opened, and closed.
In addition to this change, the logic for falling back to a previous version if the highest matched version
is a pre-release has been removed. Instead we will assume that any prior versions will exhibit the same issue and
return immediately. A user can install the version manually if they will or they can modify their version constraint
to a properly released version.
2024-05-08 16:01:29 -04:00
Lucas Bajolet
35bd020a3e plugin-getter: rm vocal log on checksum entries
When a checksum file for a release is downloaded and iterated upon to
find the compatible binary for a release, we used to log each
non-compatible entry in the logs.

This is noisy as we know there's going to be multiple entries that don't
match the host's os/arch, and there's no good reason to show those, so
we silence them.
2024-05-08 16:01:29 -04:00
Lucas Bajolet
b24ab44a55 command: list releases only for remote installs
When installing a plugin from a remote source, we list the installed
plugins that match the constraints specified, and if the constraint is
already satisfied, we don't do anything.

However, since remote installation is only relevant for releases of a
plugin, we should only look at the installed releases of a plugin, and
not consider pre-releases for that step.

This wasn't the case before this commit, as if a prerelease version of a
commit (ex: 10.8.1-dev), and we try to invoke `packer init` with a
constraint on this version specifically, Packer would locate that
pre-release and assume it was already installed, so would silently
succeed the command and do nothing.

This isn't the expected behaviour as we should install the final release
of that plugin, regardless of any prerelease installation of the plugin.
So this commit fixes that by only listing releases, so we don't report
the plugin being already installed if a prerelease is what's installed.
2024-05-08 16:01:29 -04:00
Lucas Bajolet
2d8aa69779 init: fix --force and pre-releases installed case
When packer init is invoked with a --force argument, but no --update, we
clamp the version to install based on the last one locally installed.

Doing this may however cause the constraint to always be false if the
latest available version of a plugin is a pre-release, as none of the
upstream constraints will match that.

Therefore this commit changes how the constraint is derived from the
local list of installations, so that only the last installation that
matches the original constraint will be used, and not a pre-release.
2024-05-08 16:01:29 -04:00
Lucas Bajolet
7823a40a25 packer: ensure versions match for remote installs
Since we're hardening what Packer is able to load locally when it comes
to plugins, we need also to harden the installation process a bit.

While testing we noticed some remotes had published their plugins with
version mismatches between the tag and the binary.
This was not a problem in the past, as Packer did not care for this,
only the binary name was important, and the plugin could be installed
without problem.

Nowadays however, since Packer enforces the plugin version reported in
the name to be the same as the plugin self-reported version, this makes
it impossible for the installed plugin to load anymore in such an
instance.

Therefore in order to limit confusion, and so users are able to
understand the problem and report it to the plugins with that mismatch,
we instead install the plugin as a dev version, and report it to the
user so they can still use it, but are able to report it to the plugin
developers.
2024-05-08 16:01:29 -04:00
Lucas Bajolet
77d537c389 packer: remove duplicate version variable
When listing installed plugins, we check that the plugin's reported
version through describe matches what's in the name of the file.

Doing do, we were parsing the same version string twice without
modifying it, which was not necessary, so this commit changes that.
2024-05-08 16:01:29 -04:00
Lucas Bajolet
32e64c98d1 packer: fix filename in verbose logs 2024-05-08 16:01:29 -04:00
Lucas Bajolet
04a2542a6f packer/getter: don't report other os/arch as errs
Whenever a Github release exposes an entry for another OS/arch
combination, this gets registered as an error, which in the event no
binary is compatible with the host's OS/arch, gets reported at the end
of the getter process.

While this is sound in theory, in practice we get the list of all the
combinations that don't match the host's, which is not something a
Packer user can act on, and might therefore be more confusing than
helping to solve the issue.

Therefore we opt in this commit to stop registering those cases as real
errors, and only log them as an INFO statement.
2024-05-08 16:01:29 -04:00
Lucas Bajolet
64ae3e8ea4 packer: alias version as goversion for getter
Since we named the version from the getter `version', this means we have
a naming conflict inside the loop that attempts to install a versioned
candidate for a plugin, making it impossible to invoke something from
the go-version package.

Since we'll introduce a change that needs the latter capability, we must
either rename the local variable to something else than `version', or we
need to alias the package locally.

This commit implements the latter, opting to call the package goversion.
2024-05-08 16:01:29 -04:00
Lucas Bajolet
d40df8e899 packer: check if errs is nil before getting length
When installing a remote plugin, and after we've either successfully
installed a binary, or exhausted all the possible sources, we print a
final error message if nothing was reported.

However, given that errs is a pointer to a structure, and if no errors
were produced, the the error list could be nil, leading to the call to
`Len()' to crash Packer.

This is exceedingly rare as in general the code attempts to read
multiple sources from Github, and therefore we almost always get some
error reported, but while changing the function's code, I managed to
make it crash while removing/changing some error statements.

Therefore to avoid future surprises, we first check that `errs' is not
nil before invoking `Len()' on it, as no errors and no plugins installed
mean that something went wrong all the same.
2024-05-08 16:01:29 -04:00
Lucas Bajolet
56fab30fa1 plugin: factorise calling describe on binaries
Given that calling the describe command on plugins and deserialising the
output as a plugin description is something done in multiple places in
the code, we factorise this operation so we don't need to copy/paste the
code around.
2024-05-08 16:01:29 -04:00
Lucas Bajolet
747cb00cdc packer: remove temp zipfile after installation
The zipfile containing the binaries we attempt to install from a remote
source is placed in the temporary directory of the host.
In general it is wiped automatically by the OS, but in some cases
(windows typically), it isn't.

To avoid cluttering the temporary directory, we clean-up after
ourselves, and remove the temporary zip file that we create when
attempting to install a plugin, regardless of it succeeding or not.
2024-05-08 16:01:29 -04:00
Wilken Rivera
61199aed0d Update internal HashiCorp actions to address Node 20 deprecation 2024-05-08 15:08:16 -04:00
Wilken Rivera
5e043ab3a0
Bump required actions to address Node.js 16 deprecation issue (#12958)
* Bump required actions to address Node.js 16 deprecation issue

* Update all tsccr approved actions

```shell
tsccr-helper gha update -latest .
```
2024-05-07 12:59:45 -04:00
Wilken Rivera
1a79aab50e
Bump actions/setup-go to address Node.js 16 deprecation issues (#12957) 2024-05-07 10:50:00 -04:00
Wilken Rivera
5f47c99ec4 Bump actions/checkout to address Node.js 16 deprecation issues 2024-05-07 10:39:37 -04:00
Devashish
403e35d2ff Add thread-safe add and get methods for plugin storage
* Add general code improvements
2024-05-01 16:19:30 -04:00
dependabot[bot]
26b2bb8dbf
build(deps): bump github.com/hashicorp/hcp-sdk-go from 0.92.0 to 0.93.0 (#12942)
Bumps [github.com/hashicorp/hcp-sdk-go](https://github.com/hashicorp/hcp-sdk-go) from 0.92.0 to 0.93.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.92.0...v0.93.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] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-30 09:52:54 -04:00
Lucas Bajolet
6fc1d154bd packer: relax constraints on sources
The source parsing logic was heavily directed towards Github compatible
source URIs, however if we want to support more cases, we need to make
sure we are able to specify those URIs, and to load plugins installed
from those sources.

Right now, since the getters available are only github.com, we will not
support remotely instlling plugins from sources other than github.com,
with the same set of constraints as before. However, we do support now
installing from a local plugin binary to any kind of source, and we
support loading them, including if a template wants this plugin
installed locally with version constraints.
2024-04-29 14:28:24 -04:00
Lucas Bajolet
1bf3e86ee1 hcl2template: fix invalid_inexplicit_source_2 test
The invalid_inexplicit_source_2 subtest for parse used to fail in
previous versions of Packer, but with the latest changes to plugin
source management, it won't, at least at parsing time, instead it fails
later when the Github getter (the only available for now) cannot get the
plugin binary from the source, as the source is not a valid Github URI.
2024-04-29 14:28:24 -04:00
Jiaqi Liu
00f39e72d3
Add missing option doc for 'packer fmt' (#12944) 2024-04-29 10:04:20 -04:00
Lucas Bajolet
410e59f141 version: compute SemVer from rawVersion
A bug in the SDK prevents us from calling SemVer on the PluginVersion
derived from the rawVersion, as when doing so, we reset the semVer
attribute to only use the core part of the version, thereby dropping any
information on pre-release/metadata.

This is not ideal, and arguably not wanted. So in order to not lose this
information, we re-compute the SemVer from rawVersion, this way we don't
overwrite it for both structures.
2024-04-23 11:10:43 -04:00
Wilken Rivera
f767d06f93 Dockerfile: Add Product directory to /usr/share/doc directory
Closes: #12939
2024-04-23 09:28:35 -04:00
Wilken Rivera
094e00ebd2 Update CHANGELOG 2024-04-23 09:26:25 -04:00
Wilken Rivera
baa67010de Add CHANGELOG entries for 1.10.3 2024-04-23 09:15:23 -04:00
dependabot[bot]
7526cd6e76
build(deps): bump github.com/hashicorp/hcp-sdk-go from 0.90.0 to 0.92.0 (#12935)
Bumps [github.com/hashicorp/hcp-sdk-go](https://github.com/hashicorp/hcp-sdk-go) from 0.90.0 to 0.92.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.90.0...v0.92.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] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-17 22:33:36 -04:00
Lucas Bajolet
cdaad0cde2 version: up version handling code for SDK update
Since the SDK was updated and now accepts raw version strings in
addition to also supporting metadata officially, we can start using
those functions in our version package as well.
2024-04-16 14:27:05 -04:00
Lucas Bajolet
33d9550903 packer: make Ui implementations match new SDK's
The SDK's Ui interface has had some additions recently for supporting
format-strings and their arguments as paramereters to Say, Ask and
Error.

These changes to the interface means that all the implementations of
that interface need to match the definition, so in this case the
implementations we had in packer/ui.go need to be updated to support
those functions.
2024-04-16 14:27:05 -04:00
Wilken Rivera
0b00f52653 Copy license into zip with txt extension 2024-04-16 13:04:48 -04:00
Wilken Rivera
98fd73ad74 Add LICENSE to Linux packages 2024-04-16 13:04:48 -04:00
Wilken Rivera
c37a892665 Add LICENSE details to Docker release binaries 2024-04-16 13:04:48 -04:00
Wilken Rivera
72a2604b34 Add LICENSE to zipped Go binaries 2024-04-16 13:04:48 -04:00
Lucas Bajolet
f05124e2a4 version: set version to 1.11.0-dev
Since we set the raw version string from version/VERSION now, we change
its information to point to 1.11.0-dev until we're ready to release.
2024-04-16 10:19:17 -04:00
Lucas Bajolet
93bec31ec9 version: embed version/VERSION as version string
Since we have both version/version.go and version/VERSION to specify
version strings, both are a bit redundant.

As version/VERSION is supposed to be the source of truth now, we are
using it to derive the version informaiton we used to rely on in Packer
and its subcommands.

Note: doing this prevents us from changing the version/prerelease
through ldflags though as we derive Version/VersionPrerelease from the
rawVersion variable.
2024-04-16 10:19:17 -04:00
Lucas Bajolet
27538f377b release/ci: remove trailing whitespace 2024-04-16 10:13:29 -04:00
Lucas Bajolet
55a11fe7f4 release/ci: disable automatic version bump 2024-04-16 10:13:29 -04:00