artifact

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2025 License: MPL-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Artifact

type Artifact interface {
	Initialize(injector di.Injector) error
	AddFile(path string, content []byte, mode os.FileMode) error
	Create(outputPath string, tag string) (string, error)
	Push(registryBase string, repoName string, tag string) error
	Pull(ociRefs []string) (map[string][]byte, error)
	GetTemplateData(ociRef string) (map[string][]byte, error)
}

Artifact defines the interface for artifact creation operations

type ArtifactBuilder

type ArtifactBuilder struct {
	// contains filtered or unexported fields
}

ArtifactBuilder implements the Artifact interface

func NewArtifactBuilder

func NewArtifactBuilder() *ArtifactBuilder

NewArtifactBuilder creates a new ArtifactBuilder instance with default configuration. Initializes an empty file map for storing artifact contents and sets up default shims for system operations. The returned builder is ready for dependency injection and file operations.

func (*ArtifactBuilder) AddFile

func (a *ArtifactBuilder) AddFile(path string, content []byte, mode os.FileMode) error

AddFile stores a file with the specified path and content in the artifact for later packaging. Files are held in memory until Create() or Push() is called. The path becomes the relative path within the generated tar.gz archive. Multiple calls with the same path will overwrite the previous content. Special handling exists for "_templates/metadata.yaml" during packaging.

func (*ArtifactBuilder) Create

func (a *ArtifactBuilder) Create(outputPath string, tag string) (string, error)

Create generates a compressed tar.gz artifact file from stored files and metadata with optional tag override. Accepts optional tag in "name:version" format to override metadata.yaml values. Tag takes precedence over existing metadata. If no metadata.yaml exists, tag is required. OutputPath can be file or directory - generates filename from metadata if directory. Creates compressed tar.gz with all files plus generated metadata.yaml at root. Returns the final output path of the created artifact file.

func (*ArtifactBuilder) GetTemplateData

func (a *ArtifactBuilder) GetTemplateData(ociRef string) (map[string][]byte, error)

GetTemplateData extracts and returns template data from an OCI artifact reference. Downloads and caches the OCI artifact, decompresses the tar.gz payload, and returns a map with forward-slash file paths as keys and file contents as values. The returned map always includes "ociUrl" (the original OCI reference) and "name" (from metadata.yaml if present). Only .jsonnet files are included as template data. Returns an error on invalid reference, download failure, or extraction error.

func (*ArtifactBuilder) Initialize

func (a *ArtifactBuilder) Initialize(injector di.Injector) error

Initialize sets up the ArtifactBuilder with dependency injection and resolves required dependencies. Extracts the shell dependency from the injector for git operations and command execution. The shell is used for retrieving git provenance and builder information during metadata generation. Returns an error if the shell cannot be resolved from the injector.

func (*ArtifactBuilder) Pull

func (a *ArtifactBuilder) Pull(ociRefs []string) (map[string][]byte, error)

Pull downloads and extracts OCI artifacts in memory for use by other components. It takes a slice of OCI references and downloads unique artifacts, returning a map of cached artifacts keyed by their registry/repository:tag identifier. The method provides efficient caching to avoid duplicate downloads of the same artifact.

func (*ArtifactBuilder) Push

func (a *ArtifactBuilder) Push(registryBase string, repoName string, tag string) error

Push uploads the artifact to an OCI registry with explicit blob handling to prevent MANIFEST_BLOB_UNKNOWN errors. Implements robust blob upload strategy recommended by Red Hat for resolving registry upload issues. Creates tarball in memory, constructs OCI image, uploads blobs explicitly, then uploads manifest. Uses authenticated keychain for registry access and retry backoff for resilience. Registry base should be the base URL (e.g., "ghcr.io/namespace"), repoName the repository name, tag the version.

type BaseBundler

type BaseBundler struct {
	// contains filtered or unexported fields
}

BaseBundler provides common functionality for bundler implementations

func NewBaseBundler

func NewBaseBundler() *BaseBundler

NewBaseBundler creates a new BaseBundler instance

func (*BaseBundler) Bundle

func (b *BaseBundler) Bundle(artifact Artifact) error

Bundle provides a default implementation that can be overridden by concrete bundlers

func (*BaseBundler) Initialize

func (b *BaseBundler) Initialize(injector di.Injector) error

Initialize initializes the BaseBundler with dependency injection

type BlueprintMetadata

type BlueprintMetadata struct {
	Name        string        `json:"name"`
	Description string        `json:"description,omitempty"`
	Version     string        `json:"version,omitempty"`
	Author      string        `json:"author,omitempty"`
	Tags        []string      `json:"tags,omitempty"`
	Homepage    string        `json:"homepage,omitempty"`
	License     string        `json:"license,omitempty"`
	Timestamp   string        `json:"timestamp"`
	Git         GitProvenance `json:"git"`
	Builder     BuilderInfo   `json:"builder"`
}

BlueprintMetadata represents the complete metadata embedded in artifacts

type BlueprintMetadataInput

type BlueprintMetadataInput struct {
	Name        string   `yaml:"name"`
	Description string   `yaml:"description,omitempty"`
	Version     string   `yaml:"version,omitempty"`
	Author      string   `yaml:"author,omitempty"`
	Tags        []string `yaml:"tags,omitempty"`
	Homepage    string   `yaml:"homepage,omitempty"`
	License     string   `yaml:"license,omitempty"`
}

BlueprintMetadataInput represents the input metadata from contexts/_template/metadata.yaml

type BuilderInfo

type BuilderInfo struct {
	User  string `json:"user"`
	Email string `json:"email"`
}

BuilderInfo contains information about who/what built the artifact

type Bundler

type Bundler interface {
	Initialize(injector di.Injector) error
	Bundle(artifact Artifact) error
}

Bundler defines the interface for content bundling operations

type FileInfo

type FileInfo struct {
	Content []byte
	Mode    os.FileMode
}

FileInfo holds file content and permission information

type GitProvenance

type GitProvenance struct {
	CommitSHA string `json:"commitSHA"`
	Tag       string `json:"tag,omitempty"`
	RemoteURL string `json:"remoteURL"`
}

GitProvenance contains git repository information for traceability

type KustomizeBundler

type KustomizeBundler struct {
	BaseBundler
}

KustomizeBundler handles bundling of kustomize files

func NewKustomizeBundler

func NewKustomizeBundler() *KustomizeBundler

NewKustomizeBundler creates a new KustomizeBundler instance

func (*KustomizeBundler) Bundle

func (k *KustomizeBundler) Bundle(artifact Artifact) error

Bundle adds all files from kustomize directory to the artifact by recursively walking the directory tree. It checks if the kustomize directory exists and returns nil if not found (graceful handling). If the directory exists, it walks through all files preserving the directory structure. Each file is read and added to the artifact maintaining the original kustomize path structure. Directories are skipped and only regular files are processed for bundling.

type MockArtifact

type MockArtifact struct {
	InitializeFunc      func(injector di.Injector) error
	AddFileFunc         func(path string, content []byte, mode os.FileMode) error
	CreateFunc          func(outputPath string, tag string) (string, error)
	PushFunc            func(registryBase string, repoName string, tag string) error
	PullFunc            func(ociRefs []string) (map[string][]byte, error)
	GetTemplateDataFunc func(ociRef string) (map[string][]byte, error)
}

MockArtifact is a mock implementation of the Artifact interface

func NewMockArtifact

func NewMockArtifact() *MockArtifact

NewMockArtifact creates a new MockArtifact instance

func (*MockArtifact) AddFile

func (m *MockArtifact) AddFile(path string, content []byte, mode os.FileMode) error

AddFile calls the mock AddFileFunc if set, otherwise returns nil

func (*MockArtifact) Create

func (m *MockArtifact) Create(outputPath string, tag string) (string, error)

Create calls the mock CreateFunc if set, otherwise returns empty string and nil error

func (*MockArtifact) GetTemplateData

func (m *MockArtifact) GetTemplateData(ociRef string) (map[string][]byte, error)

GetTemplateData calls the mock GetTemplateDataFunc if set, otherwise returns empty map and nil error

func (*MockArtifact) Initialize

func (m *MockArtifact) Initialize(injector di.Injector) error

Initialize calls the mock InitializeFunc if set, otherwise returns nil

func (*MockArtifact) Pull

func (m *MockArtifact) Pull(ociRefs []string) (map[string][]byte, error)

Pull calls the mock PullFunc if set, otherwise returns empty map and nil error

func (*MockArtifact) Push

func (m *MockArtifact) Push(registryBase string, repoName string, tag string) error

Push calls the mock PushFunc if set, otherwise returns nil

type MockBundler

type MockBundler struct {
	InitializeFunc func(injector di.Injector) error
	BundleFunc     func(artifact Artifact) error
}

MockBundler is a mock implementation of the Bundler interface

func NewMockBundler

func NewMockBundler() *MockBundler

NewMockBundler creates a new MockBundler instance

func (*MockBundler) Bundle

func (m *MockBundler) Bundle(artifact Artifact) error

Bundle calls the mock BundleFunc if set, otherwise returns nil

func (*MockBundler) Initialize

func (m *MockBundler) Initialize(injector di.Injector) error

Initialize calls the mock InitializeFunc if set, otherwise returns nil

type OCIArtifactInfo

type OCIArtifactInfo struct {
	// Name is the name of the OCI artifact
	Name string
	// URL is the full OCI URL of the artifact
	URL string
	// Tag is the tag/version of the OCI artifact
	Tag string
}

OCIArtifactInfo contains information about the OCI artifact source for blueprint data

func ParseOCIReference

func ParseOCIReference(ociRef string) (*OCIArtifactInfo, error)

ParseOCIReference parses a blueprint reference string in OCI URL or org/repo:tag format and returns an OCIArtifactInfo struct. Accepts full OCI URLs (e.g., oci://ghcr.io/org/repo:v1.0.0) and org/repo:v1.0.0 formats only. Returns nil if the reference is empty, missing a version, or not in a supported format.

type Shims

type Shims struct {
	Stat              func(name string) (os.FileInfo, error)
	Create            func(name string) (io.WriteCloser, error)
	ReadFile          func(name string) ([]byte, error)
	Walk              func(root string, walkFn filepath.WalkFunc) error
	NewGzipWriter     func(w io.Writer) *gzip.Writer
	NewTarWriter      func(w io.Writer) TarWriter
	YamlUnmarshal     func(data []byte, v any) error
	FilepathRel       func(basepath, targpath string) (string, error)
	YamlMarshal       func(data any) ([]byte, error)
	ReadAll           func(reader io.Reader) ([]byte, error)
	ParseReference    func(ref string, opts ...name.Option) (name.Reference, error)
	RemoteImage       func(ref name.Reference, options ...remote.Option) (v1.Image, error)
	ImageLayers       func(img v1.Image) ([]v1.Layer, error)
	LayerUncompressed func(layer v1.Layer) (io.ReadCloser, error)
	AppendLayers      func(base v1.Image, layers ...v1.Layer) (v1.Image, error)
	ConfigFile        func(img v1.Image, cfg *v1.ConfigFile) (v1.Image, error)
	MediaType         func(img v1.Image, mt types.MediaType) v1.Image
	ConfigMediaType   func(img v1.Image, mt types.MediaType) v1.Image
	Annotations       func(img v1.Image, anns map[string]string) v1.Image
	EmptyImage        func() v1.Image
	RemoteGet         func(ref name.Reference, options ...remote.Option) (*remote.Descriptor, error)
	RemoteWriteLayer  func(repo name.Repository, layer v1.Layer, options ...remote.Option) error
	RemoteWrite       func(ref name.Reference, img v1.Image, options ...remote.Option) error
}

Shims provides mockable wrappers around system and file operations

func NewShims

func NewShims() *Shims

NewShims creates a new Shims instance with default implementations

type TarWriter

type TarWriter interface {
	WriteHeader(hdr *tar.Header) error
	Write(b []byte) (int, error)
	Close() error
}

TarWriter provides an interface for tar writing operations

type TemplateBundler

type TemplateBundler struct {
	BaseBundler
}

TemplateBundler handles bundling of template files

func NewTemplateBundler

func NewTemplateBundler() *TemplateBundler

NewTemplateBundler creates a new TemplateBundler instance

func (*TemplateBundler) Bundle

func (t *TemplateBundler) Bundle(artifact Artifact) error

Bundle adds template files from contexts/_template directory to the artifact by recursively walking the directory tree. It validates that the templates directory exists, then walks through all files preserving the directory structure. Each file is read and added to the artifact with the path prefix "_template/" to maintain organization. Directories are skipped and only regular files are processed for bundling.

type TerraformBundler

type TerraformBundler struct {
	BaseBundler
}

TerraformBundler handles bundling of terraform files

func NewTerraformBundler

func NewTerraformBundler() *TerraformBundler

NewTerraformBundler creates a new TerraformBundler instance

func (*TerraformBundler) Bundle

func (t *TerraformBundler) Bundle(artifact Artifact) error

Bundle adds all files from terraform directory to the artifact by recursively walking the directory tree. It checks if the terraform directory exists and returns nil if not found (graceful handling). If the directory exists, it walks through all files preserving the directory structure. Each file is read and added to the artifact maintaining the original terraform path structure. Directories are skipped and only regular files are processed for bundling. The bundler ignores .terraform directories and filters out common terraform files that should not be bundled: - *_override.tf and *.tf.json override files - *.tfstate and *.tfstate.* state files - *.tfvars and *.tfvars.json variable files (often contain sensitive data) - crash.log and crash.*.log files - .terraformrc and terraform.rc CLI config files - *.tfplan plan output files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL