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

Pulling plugins from domains not github.com #11164

Open
johnypony3 opened this issue Jul 22, 2021 · 5 comments
Open

Pulling plugins from domains not github.com #11164

johnypony3 opened this issue Jul 22, 2021 · 5 comments
Labels
core-plugin-split enhancement sync to jira For issues that need to be imported to Packer internal JIRA backlog
Milestone

Comments

@johnypony3
Copy link

Community Note

Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request.
Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request.
If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Description

Allow pulling plugins from other vcs sites, in my case gitlab.

Use Case(s)

github is external to my build server and is therefore against company standards for use as an external dependency location

Potential configuration

packer {
  required_plugins {
    windows-update = {
      version = "0.12.0"
      source = "gitlab.company.com/mercedes/windows-update"
    }
  }
}

Potential References

This is documented as an eventual here: plugins source-addresses

@SwampDragons
Copy link
Contributor

Hi, thanks for reaching out. This is definitely on our roadmap for something we want to do in the future, hence the "eventual" comment.

As a workaround, you can manually download plugins and place them into the plugins directory on your build server in order to make them discoverable by Packer without being downloaded. Full details can be found here: https://www.packer.io/docs/plugins (click the "manual (multi-component plugin)" tab)

@tomsiewert
Copy link

For us, we sometimes hit the GitHub rate limit on our CI runners which made us require to create mirrors of the used plugins. Those mirrors are located in Sub-Groups in our internal GitLab, but Packer force-validates / requires the source in a hostname/namespace/name format.

Error: Invalid plugin source string

  on debian/config.pkr.hcl line 7, in packer:
   7:     ansible = {
   8:       version = ">= 1.0.0"
   9:       source  = "git.company.com/mirror/github.com/hashicorp/ansible"
  10:     }

The "source" attribute must be in the format "hostname/namespace/name"

@azr
Copy link
Contributor

azr commented Aug 12, 2021

Hello there, thanks for opening, Packer is meant to support other plugin getters than GitHub ! We just did not have the time to do it due to other priorities. If you would like to do that, I will try to give code pointers though, we would be more than happy to review PRs on this !

First, you will have to implement a new plugin getter, the GitHub one is being used here:

packer/command/init.go

Lines 85 to 86 in 0e3fcb5

getters := []plugingetter.Getter{
&github.Getter{

and being implemented in here:

type Getter struct {
Client *github.Client
UserAgent string
}

The getter interface is defined here, I'd recommend reading it first :) :

// A Getter helps get the appropriate files to download a binary.
type Getter interface {
// Get allows Packer to know more information about releases of a plugin in
// order to decide which version to install. Get behaves similarly to an
// HTTP server. Packer will stream responses from get in order to do what's
// needed. In order to minimize the amount of requests done, Packer is
// strict on filenames and we highly recommend on automating releases.
// In the future, Packer will make it possible to ship plugin getters as
// binaries this is why Packer streams from the output of get, which will
// then be a command.
//
// * 'releases', get 'releases' should return the complete list of Releases
// in JSON format following the format of the Release struct. It is also
// possible to read GetOptions to filter for a smaller response. Some
// getters don't. Packer will then decide the highest compatible
// version of the plugin to install by using the sha256 function.
//
// * 'sha256', get 'sha256' should return a SHA256SUMS txt file. It will be
// called with the highest possible & user allowed version from get
// 'releases'. Packer will check if the release has a binary matching what
// Packer can install and use. If so, get 'binary' will be called;
// otherwise, lower versions will be checked.
// For version 1.0.0 of the 'hashicorp/amazon' builder, the GitHub getter
// will fetch the following URL:
// https://github.com/hashicorp/packer-plugin-amazon/releases/download/v1.0.0/packer-plugin-amazon_v1.0.0_SHA256SUMS
// This URL can be parameterized to the following one:
// https://github.com/{plugin.path}/releases/download/{plugin.version}/packer-plugin-{plugin.name}_{plugin.version}_SHA256SUMS
// If Packer is running on Linux AMD 64, then Packer will check for the
// existence of a packer-plugin-amazon_v1.0.0_x5.0_linux_amd64 checksum in
// that file. This filename can be parameterized to the following one:
// packer-plugin-{plugin.name}_{plugin.version}_x{proto_ver.major}.{proto_ver._minor}_{os}_{arch}
//
// See
// https://github.com/hashicorp/packer-plugin-scaffolding/blob/main/.goreleaser.yml
// and
// https://www.packer.io/docs/plugins/creation#plugin-development-basics
// to learn how to create and automate your releases and for docs on
// plugin development basics.
//
// * get 'zip' is called once we know what version we want and that it is
// compatible with the OS and Packer. Zip expects an io stream of a zip
// file containing a binary. For version 1.0.0 of the 'hashicorp/amazon'
// builder and on darwin_amd64, the GitHub getter will fetch the
// following ZIP:
// https://github.com/hashicorp/packer-plugin-amazon/releases/download/v1.0.0/packer-plugin-amazon_v1.0.0_x5.0_darwin_amd64.zip
// this zip is expected to contain a
// packer-plugin-amazon_v1.0.0_x5.0_linux_amd64 file that will be checksum
// verified then copied to the correct plugin location.
Get(what string, opts GetOptions) (io.ReadCloser, error)
}

@azr azr added this to the 1.7.7 milestone Oct 6, 2021
@nywilken nywilken modified the milestones: 1.7.7, 1.7.8 Oct 6, 2021
@azr azr removed this from the 1.7.8 milestone Oct 7, 2021
@ianblackshere
Copy link

Hello, I am interested in working this issue. My team has a use-case for this where we would like to build on our private networks without having to copy the plugins to each host as we are spread across multiple sites.

@johnypony3
Copy link
Author

@ianblackshere we got around this by pulling the packages in and pulling them from local.

@nywilken nywilken added this to the 1.11.0 milestone Oct 16, 2023
@nywilken nywilken modified the milestones: 1.11.0, 1.12.0 Apr 17, 2024
@nywilken nywilken added sync to jira For issues that need to be imported to Packer internal JIRA backlog and removed track-internal labels Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-plugin-split enhancement sync to jira For issues that need to be imported to Packer internal JIRA backlog
Projects
None yet
Development

No branches or pull requests

6 participants