mirror of
https://github.com/hashicorp/packer.git
synced 2026-09-27 10:14:01 -04:00
* Update handling of registry artifacts This change uses the github.com/hashicorp/packer-plgin-sdk/packer/registryimage for querying Artifact State for HCP Registry Image metadata. To handle the conversion of the RPC response, mapstructure was introduced to conversion state data into an registryimage.Image before publishing to a image bucket. * Update to use registry image from packersdk * Rename internal registry service pkg * Update vendored plugins to latest version * The latest release of Amazon, GoogleCompute, and Azure have support for publishing images to the HCP Packer registry.
54 lines
979 B
Go
54 lines
979 B
Go
package file
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"path"
|
|
|
|
registryimage "github.com/hashicorp/packer-plugin-sdk/packer/registry/image"
|
|
)
|
|
|
|
type FileArtifact struct {
|
|
filename string
|
|
}
|
|
|
|
func (*FileArtifact) BuilderId() string {
|
|
return BuilderId
|
|
}
|
|
|
|
func (a *FileArtifact) Files() []string {
|
|
return []string{a.filename}
|
|
}
|
|
|
|
func (a *FileArtifact) Id() string {
|
|
return "File"
|
|
}
|
|
|
|
func (a *FileArtifact) String() string {
|
|
return fmt.Sprintf("Stored file: %s", a.filename)
|
|
}
|
|
|
|
func (a *FileArtifact) State(name string) interface{} {
|
|
if name == registryimage.ArtifactStateURI {
|
|
img, err := registryimage.FromArtifact(a,
|
|
registryimage.WithID(path.Base(a.filename)),
|
|
registryimage.WithRegion(path.Dir(a.filename)),
|
|
)
|
|
|
|
if err != nil {
|
|
log.Printf("[DEBUG] error encountered when creating a registry image %v", err)
|
|
return nil
|
|
}
|
|
|
|
return img
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (a *FileArtifact) Destroy() error {
|
|
log.Printf("Deleting %s", a.filename)
|
|
return os.Remove(a.filename)
|
|
}
|