Skip to content

Add registry image pkg#76

Merged
nywilken merged 8 commits intomainfrom
registryimage-pkg
Sep 7, 2021
Merged

Add registry image pkg#76
nywilken merged 8 commits intomainfrom
registryimage-pkg

Conversation

@nywilken
Copy link
Copy Markdown
Contributor

@nywilken nywilken commented Aug 24, 2021

In order to assist in the creation of HCP Packer Registry Image metadata
for various Artifacts. A new package is being added to assist in the
creation of a registryimage.Image from an existing Artifact.

The FromArtifact function provides a simple approach of extracting the
required bits from an Artifact needed by the HCP Packer registry. The
default values, which can be overwritten by the use of a
ArtifactOverrideFunc , were selected to provide some standard defaults
that are set to be available for most plugins were bundled
with Packer prior to v1.7.0. When those defaults are not viable the
package provider override funcs that can be used by the consumer for
setting the appropriate values.

For those plugins that generate more than one registryimage.Image per
Artifact one can construct a []registryimage.Image and return that
information as the response of Packer core calling
artifact.State(registryimage.ArtifactStateURI).

When reviewing, I recommend checking out the godoc to see the examples tests in action.

> go install golang.org/x/tools/cmd/godoc@latest
> godoc -http=:8080
browse to http://localhost:8080/pkg/github.com/hashicorp/packer-plugin-sdk/packer/registry/image/

@nywilken nywilken marked this pull request as ready for review September 1, 2021 15:44
@nywilken nywilken requested a review from a team as a code owner September 1, 2021 15:44
// FromMappedData will make its best attempt to convert the input map into map[interface{}]interface{} before
// calling f(k,v). The func f is responsible for type asserting the expected type for the key and value before
// trying to create an Image from it.
func FromMappedData(mappedData interface{}, f func(key, value interface{}) (*Image, error)) ([]*Image, error) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As an alternative to this implementation which would allow for a map of any type. I'm considering just supporting a mappedData input of map[string]string, as this seems to be the std. map being used across most plugins that return multi-region artifacts.

It also removes the need for the consumer to do type assertions in the iteration function, which seems a bit complex.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Any specific reason you didn't go to map[string]string from the beginning?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Flexibility really. I thought maybe it would be useful to others if I didn't define the concrete type.

@nywilken nywilken changed the title Add registryimage pkg Add registry image pkg Sep 2, 2021
Wilken Rivera added 5 commits September 2, 2021 14:17
In order to assist in the creation of HCP Packer Registry Image metadata
for various Artifacts. A new package is being added to assist in the
  creation of a registryimage.Image from an existing Artifact.

The FromArtifact function provides a simple approach of extracting the
required bits from an Artifact needed by the HCP Packer registry. The
default values, which can be overwritten by the use of a
ArtifactOverrideFunc , were selected to provide some standard defaults
that are set to be available for most plugins were bundled
with Packer prior to v1.7.0. When those defaults are not viable the
package provider override funcs that can be used by the consumer for
setting the appropriate values.

For those  plugins that generate more than one registryimage.Image per
Artifact one can construct a []registryimage.Image and return that
information as the response of Packer core calling
artifact.State(registryimage.ArtifactStateURI).
* Move pkg around to remove a bit of the stutter.
* Add some example tests for a few of the functions provided by the
  package.
Copy link
Copy Markdown
Contributor

@azr azr left a comment

Choose a reason for hiding this comment

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

LGTM !

Copy link
Copy Markdown

@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.

👍🏼 this looks great!

@nywilken nywilken merged commit bb726f8 into main Sep 7, 2021
@nywilken nywilken deleted the registryimage-pkg branch September 7, 2021 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants