Documentation
¶
Index ¶
- Constants
- func FormatOCIRef(registry, repository, tag string) string
- func IsAuthenticationError(err error) bool
- func ParseRegistryURL(registryURL string) (registryBase, repoName, tag string, err error)
- func ReadCachedBOM(cacheDir string) ([]byte, error)
- func ReadCachedDigest(cacheDir string) (string, error)
- func ResolveCompatibleTag(artifactBuilder Artifact, urlPrefix string, tags []string) (tag string, version *semver.Version, ok bool, err error)
- func ValidateCliVersion(cliVersion, constraint string) error
- type Artifact
- type ArtifactBuilder
- func (a *ArtifactBuilder) Bundle() error
- func (a *ArtifactBuilder) ExtractModulePath(registry, repository, tag, modulePath string) (string, error)
- func (a *ArtifactBuilder) GetCacheDir(registry, repository, tag string) (string, error)
- func (a *ArtifactBuilder) GetCliVersionConstraint(ociRef string) (string, error)
- func (a *ArtifactBuilder) ListTags(ociRef string) ([]string, error)
- func (a *ArtifactBuilder) ParseOCIRef(ociRef string) (registry, repository, tag string, err error)
- func (a *ArtifactBuilder) Pull(ociRefs []string) (map[string]string, error)
- func (a *ArtifactBuilder) Push(registryBase string, repoName string, tag string) error
- func (a *ArtifactBuilder) SetBOMWriter(writer BOMWriter)
- func (a *ArtifactBuilder) VerifyCliVersionCompatibility(ociRef string) error
- func (a *ArtifactBuilder) Write(outputPath string, tag string) (string, error)
- type ArtifactTag
- type ArtifactTagType
- type BOMWriter
- type BlueprintMetadata
- type BlueprintMetadataInput
- type BuilderInfo
- type FileInfo
- type GitProvenance
- type KustomizationScope
- type MockArtifact
- func (m *MockArtifact) Bundle() error
- func (m *MockArtifact) ExtractModulePath(registry, repository, tag, modulePath string) (string, error)
- func (m *MockArtifact) GetCacheDir(registry, repository, tag string) (string, error)
- func (m *MockArtifact) GetCliVersionConstraint(ociRef string) (string, error)
- func (m *MockArtifact) ListTags(ociRef string) ([]string, error)
- func (m *MockArtifact) ParseOCIRef(ociRef string) (registry, repository, tag string, err error)
- func (m *MockArtifact) Pull(ociRefs []string) (map[string]string, error)
- func (m *MockArtifact) Push(registryBase string, repoName string, tag string) error
- func (m *MockArtifact) VerifyCliVersionCompatibility(ociRef string) error
- func (m *MockArtifact) Write(outputPath string, tag string) (string, error)
- type OCIArtifactInfo
- type PathProcessor
- type Shims
- type TagScope
- type TarReader
- type TarWriter
- type TerraformScope
Constants ¶
const BOMFileName = "artifact-manifest.cdx.json"
BOMFileName is the name of the CycloneDX BOM at the root of a blueprint artifact.
const CliVersionAnnotationKey = "windsorcli.dev/cli-version"
CliVersionAnnotationKey mirrors BlueprintMetadataInput.CliVersion into the OCI manifest, so GetCliVersionConstraint can check it without a full Pull.
Variables ¶
This section is empty.
Functions ¶
func FormatOCIRef ¶ added in v0.9.1
FormatOCIRef builds "registry/repository:tag", or "registry/repository@tag" when tag is a digest ("sha256:<hex>"). Every ParseOCIRef caller uses this to rebuild a reference or cache key, so a digest round-trips correctly.
func IsAuthenticationError ¶
IsAuthenticationError reports whether err comes from a registry authentication or authorization failure. It looks for a go-containerregistry *transport.Error with HTTP 401 or 403, or an UNAUTHORIZED or DENIED code. It uses errors.As, so a werror.Wrap frame or a fmt.Errorf %w wrap does not hide the error. The push command uses it to tell the user to run `docker login`.
func ParseRegistryURL ¶
ParseRegistryURL parses a registry URL into the registry base, the repository name, and the tag. It accepts "registry.com/repo:tag", "registry.com/repo", and "oci://registry.com/repo:tag". It returns an error if the URL has no repository path.
func ReadCachedBOM ¶ added in v0.10.0
ReadCachedBOM returns the BOM in the artifact.tar of the cache directory cacheDir. It returns nil and no error when the archive holds no BOM, as in an artifact from an older CLI. It returns an error when the archive is missing or cannot be read, or when the BOM is larger than maxBOMSize.
func ReadCachedDigest ¶ added in v0.10.0
ReadCachedDigest returns the manifest digest of the artifact in the cache directory cacheDir. It returns an empty digest when the cache holds no digest, as in a cache from an older CLI. It returns an error when the digest file cannot be read or does not hold a valid digest.
func ResolveCompatibleTag ¶ added in v0.9.0
func ResolveCompatibleTag(artifactBuilder Artifact, urlPrefix string, tags []string) (tag string, version *semver.Version, ok bool, err error)
ResolveCompatibleTag returns the highest stable semver tag that the running CLI is compatible with. For each tag, it reads the manifest constraint annotation first. If there is no annotation, it pulls the tag to check. Older tags do not have the annotation, so it cannot think that they are compatible. A manifest read error skips that tag. It returns the last error only if no tag is compatible.
func ValidateCliVersion ¶
ValidateCliVersion checks that cliVersion satisfies the cliVersion constraint of the blueprint metadata. It does not check when the constraint or cliVersion is empty, for the "dev", "main", or "latest" builds, or for a "nightly" build. A nightly build has a snapshot string that is not a semver version. It checks a pre-release version, such as "0.9.0-rc.1", as its release version. Masterminds/semver excludes pre-releases from a range that does not include one, so an rc build would always fail.
Types ¶
type Artifact ¶
type Artifact interface {
Bundle() error
Write(outputPath string, tag string) (string, error)
Push(registryBase string, repoName string, tag string) error
Pull(ociRefs []string) (map[string]string, error)
ExtractModulePath(registry, repository, tag, modulePath string) (string, error)
ParseOCIRef(ociRef string) (registry, repository, tag string, err error)
GetCacheDir(registry, repository, tag string) (string, error)
ListTags(ociRef string) ([]string, error)
GetCliVersionConstraint(ociRef string) (string, error)
VerifyCliVersionCompatibility(ociRef string) 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(rt *runtime.Runtime) *ArtifactBuilder
NewArtifactBuilder creates a new ArtifactBuilder instance with the provided shell dependency. If overrides are provided, any non-nil component in the override ArtifactBuilder will be used instead of creating a default. The shell is used for retrieving git provenance and builder information during metadata generation.
func (*ArtifactBuilder) Bundle ¶
func (a *ArtifactBuilder) Bundle() error
Bundle collects the project files for the artifact and adds the artifact manifest. It reads contexts/_template, kustomize, and terraform under the base directory of the project and writes them at the archive root as _template, kustomize, and terraform. It does not copy the terraform files that shouldSkipTerraformFile excludes.
func (*ArtifactBuilder) ExtractModulePath ¶ added in v0.9.0
func (a *ArtifactBuilder) ExtractModulePath(registry, repository, tag, modulePath string) (string, error)
ExtractModulePath returns the path of modulePath in the cache directory of a pulled OCI artifact. If the path does not exist, it extracts the cached artifact.tar again. It returns an error if the artifact does not contain modulePath.
func (*ArtifactBuilder) GetCacheDir ¶ added in v0.9.0
func (a *ArtifactBuilder) GetCacheDir(registry, repository, tag string) (string, error)
GetCacheDir returns the cache directory path for an OCI artifact identified by registry, repository, and tag. The cache directory is located at <projectRoot>/.windsor/cache/oci/<extractionKey> where extractionKey is the cacheKey with /, :, and @ replaced with _ for filesystem safety. Returns an error if project root is empty.
func (*ArtifactBuilder) GetCliVersionConstraint ¶ added in v0.9.0
func (a *ArtifactBuilder) GetCliVersionConstraint(ociRef string) (string, error)
GetCliVersionConstraint returns the cliVersion constraint of ociRef from the manifest annotation. It reads only the manifest and does not pull the layer. An empty string means the artifact sets no constraint. When the context has a mirror for the registry, it reads the manifest from the mirror. If the registry rejects the keychain credentials, it tries again without credentials.
func (*ArtifactBuilder) ListTags ¶ added in v0.9.0
func (a *ArtifactBuilder) ListTags(ociRef string) ([]string, error)
ListTags returns the tags of the repository of an OCI reference. It ignores the tag in ociRef. The upgrade of a source uses it to find the latest version. When the context has a mirror for the registry, it lists the tags of the mirror. A mirror holds only the tags that were copied to it. It returns an error if the reference is not valid or the registry is not available.
func (*ArtifactBuilder) ParseOCIRef ¶ added in v0.9.0
func (a *ArtifactBuilder) ParseOCIRef(ociRef string) (registry, repository, tag string, err error)
ParseOCIRef parses an OCI reference into registry, repository, and tag. It accepts "oci://registry/repository:tag" or "oci://registry/repository@sha256:digest". The registry can have a port, so the repository and tag split on the last colon. It rejects a repository with a colon, because the split would be wrong. For a digest reference, tag is the bare "sha256:<hex>" string. FormatOCIRef adds the correct separator again.
func (*ArtifactBuilder) Pull ¶
func (a *ArtifactBuilder) Pull(ociRefs []string) (map[string]string, error)
Pull puts each oci:// reference in the disk cache and returns the cache directories by registry/repository:tag. It uses a valid cache entry, and removes a cache directory that is not complete. It downloads and extracts each reference that has no valid cache entry. If NO_CACHE is "true" or "1", it downloads each reference again.
func (*ArtifactBuilder) Push ¶
func (a *ArtifactBuilder) Push(registryBase string, repoName string, tag string) error
Push bundles the project files and pushes the artifact to registryBase/repoName:tag. It uploads each layer and the config blob that the registry does not have, then writes the manifest. This order prevents MANIFEST_BLOB_UNKNOWN errors from the registry. It uses the Docker keychain for credentials, and writes the manifest with a retry backoff.
func (*ArtifactBuilder) SetBOMWriter ¶ added in v0.10.0
func (a *ArtifactBuilder) SetBOMWriter(writer BOMWriter)
SetBOMWriter sets the writer of the artifact manifest. With no writer, Bundle checks the artifact tags and writes no manifest.
func (*ArtifactBuilder) VerifyCliVersionCompatibility ¶ added in v0.9.0
func (a *ArtifactBuilder) VerifyCliVersionCompatibility(ociRef string) error
VerifyCliVersionCompatibility pulls ociRef and checks the cliVersion constraint in its metadata.yaml. ResolveCompatibleTag uses it when the manifest of a tag has no constraint annotation. The pull reads the mirror of the registry, as Pull does. It returns nil if the running CLI satisfies the constraint or the artifact has no metadata.yaml. Any other error means that the tag is not safe to use.
func (*ArtifactBuilder) Write ¶
func (a *ArtifactBuilder) Write(outputPath string, tag string) (string, error)
Write bundles the project files and writes them to a tar.gz artifact. It returns the path of the artifact. The tag is optional. A "name:version" tag overrides the name and version in metadata.yaml. A tag without a colon overrides only the version. If metadata.yaml does not set a name, the tag must set it. If outputPath is a directory, Write adds the file name <name>-<version>.tar.gz.
type ArtifactTag ¶ added in v0.10.0
type ArtifactTag struct {
Type ArtifactTagType
Name string
Repo string
Version string
Digest string
NoReferrers bool
File string
Line int
}
ArtifactTag is one chart or image that an `artifact` tag names.
func ScanTags ¶ added in v0.10.0
func ScanTags(filePath string, content []byte) ([]ArtifactTag, error)
ScanTags returns the artifact tags in the content of one file. A tag on a comment line of its own binds to the next line that is not blank and not a comment. A tag at the end of a line binds to that line. The value is the last scalar on the bound line, and an @sha256 suffix gives the digest. It returns an error for a tag with no value, an unknown type, no name and no full image reference, a chart with no repo, a referrers value that is not true or false, or a chart with referrers.
func ScanTagsDir ¶ added in v0.10.0
func ScanTagsDir(root string) ([]ArtifactTag, error)
ScanTagsDir returns the artifact tags in the .yaml, .yml, .tf and .tfvars files under the kustomize, terraform, contexts and _template directories of root. This covers facets and values files. A root with none of these directories gives no tags. File paths are relative to root.
func ScanTagsScoped ¶ added in v0.10.0
func ScanTagsScoped(root string, scope TagScope) ([]ArtifactTag, []string, error)
ScanTagsScoped returns the artifact tags in the files of root that scope uses, and notes for the operator. File paths are relative to root. It always reads the contexts, _template and kustomize/crds directories. For each kustomization and Terraform component, it reads the directory and follows its local entries and modules. It does not enter a subdirectory that is its own root, unless an entry reaches it. A name that holds an expression widens the scan and gives a note. A path that the source does not hold gives a note.
type ArtifactTagType ¶ added in v0.10.0
type ArtifactTagType string
ArtifactTagType is the type of artifact that a tag names.
const ( // ArtifactTagImage is a container image. Its name is the image repository. ArtifactTagImage ArtifactTagType = "image" // ArtifactTagChart is a Helm chart. Its name is the chart name and its repo is the repository URL. ArtifactTagChart ArtifactTagType = "chart" )
type BOMWriter ¶ added in v0.10.0
type BOMWriter func(name, version string, tags []ArtifactTag, blueprint []byte) ([]byte, error)
BOMWriter returns the BOM of a blueprint with the given name, version and artifact tags. blueprint is the content of the bundled _template/blueprint.yaml, or nil when the bundle has none.
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"`
ChangelogUrl string `json:"changelogUrl,omitempty"`
License string `json:"license,omitempty"`
CliVersion string `json:"cliVersion,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"`
ChangelogUrl string `yaml:"changelogUrl,omitempty"`
License string `yaml:"license,omitempty"`
CliVersion string `yaml:"cliVersion,omitempty"`
}
BlueprintMetadataInput represents the input metadata from contexts/_template/metadata.yaml
type BuilderInfo ¶
BuilderInfo contains information about who/what built the artifact
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 KustomizationScope ¶ added in v0.10.0
KustomizationScope is one kustomization of a blueprint. Dir is relative to the source root, such as kustomize/telemetry/install. Each component is relative to Dir.
type MockArtifact ¶
type MockArtifact struct {
BundleFunc func() error
WriteFunc func(outputPath string, tag string) (string, error)
PushFunc func(registryBase string, repoName string, tag string) error
PullFunc func(ociRefs []string) (map[string]string, error)
ExtractModulePathFunc func(registry, repository, tag, modulePath string) (string, error)
ParseOCIRefFunc func(ociRef string) (registry, repository, tag string, err error)
GetCacheDirFunc func(registry, repository, tag string) (string, error)
ListTagsFunc func(ociRef string) ([]string, error)
GetCliVersionConstraintFunc func(ociRef string) (string, error)
VerifyCliVersionCompatibilityFunc func(ociRef string) error
}
MockArtifact is a mock implementation of the Artifact interface
func NewMockArtifact ¶
func NewMockArtifact() *MockArtifact
NewMockArtifact creates a new MockArtifact instance
func (*MockArtifact) Bundle ¶
func (m *MockArtifact) Bundle() error
Bundle calls the mock BundleFunc if set, otherwise returns nil
func (*MockArtifact) ExtractModulePath ¶ added in v0.9.0
func (m *MockArtifact) ExtractModulePath(registry, repository, tag, modulePath string) (string, error)
ExtractModulePath calls the mock ExtractModulePathFunc if set, otherwise returns empty string and nil error
func (*MockArtifact) GetCacheDir ¶ added in v0.9.0
func (m *MockArtifact) GetCacheDir(registry, repository, tag string) (string, error)
GetCacheDir calls the mock GetCacheDirFunc if set, otherwise returns empty string and nil error
func (*MockArtifact) GetCliVersionConstraint ¶ added in v0.9.0
func (m *MockArtifact) GetCliVersionConstraint(ociRef string) (string, error)
GetCliVersionConstraint calls the mock GetCliVersionConstraintFunc if set, otherwise returns empty string and nil error
func (*MockArtifact) ListTags ¶ added in v0.9.0
func (m *MockArtifact) ListTags(ociRef string) ([]string, error)
ListTags calls the mock ListTagsFunc if set, otherwise returns an empty slice and nil error
func (*MockArtifact) ParseOCIRef ¶ added in v0.9.0
func (m *MockArtifact) ParseOCIRef(ociRef string) (registry, repository, tag string, err error)
ParseOCIRef calls the mock ParseOCIRefFunc if set, otherwise returns empty strings and nil error
func (*MockArtifact) Pull ¶
func (m *MockArtifact) Pull(ociRefs []string) (map[string]string, 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 Bundle() first, then calls the mock PushFunc if set, otherwise returns nil
func (*MockArtifact) VerifyCliVersionCompatibility ¶ added in v0.9.0
func (m *MockArtifact) VerifyCliVersionCompatibility(ociRef string) error
VerifyCliVersionCompatibility calls the mock VerifyCliVersionCompatibilityFunc if set, otherwise returns nil
type OCIArtifactInfo ¶
OCIArtifactInfo contains information about the OCI artifact source for blueprint data
func ParseOCIReference ¶
func ParseOCIReference(ociRef string) (*OCIArtifactInfo, error)
ParseOCIReference parses a blueprint reference into an OCIArtifactInfo. It accepts "oci://registry/org/repo:v1.0.0" and "org/repo:v1.0.0". It adds ghcr.io to an org/repo reference. Both formats accept "@sha256:<hex>" in place of the tag. Tag is then the digest without "@". It returns nil and no error for an empty reference. It returns an error if the reference has no version.
type PathProcessor ¶
type PathProcessor struct {
Pattern string
Handler func(relPath string, data []byte, mode os.FileMode) error
}
PathProcessor defines a processor for files matching a specific path pattern
type Shims ¶
type Shims struct {
shims.Shims
Create func(name string) (io.WriteCloser, error)
Walk func(root string, walkFn filepath.WalkFunc) error
NewGzipWriter func(w io.Writer) *gzip.Writer
NewTarWriter func(w io.Writer) TarWriter
FilepathRel func(basepath, targpath string) (string, 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)
ImageDigest func(img v1.Image) (v1.Hash, 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
RemoteList func(repo name.Repository, options ...remote.Option) ([]string, error)
NewRepository func(repo string, opts ...name.Option) (name.Repository, error)
NewBytesReader func(b []byte) *bytes.Reader
NewTarReader func(r io.Reader) TarReader
Copy func(dst io.Writer, src io.Reader) (int64, error)
Chmod func(name string, mode os.FileMode) error
}
Shims holds the shared system call primitives and the artifact-specific shims.
type TagScope ¶ added in v0.10.0
type TagScope struct {
Kustomizations []KustomizationScope
Terraform []TerraformScope
}
TagScope lists the paths of one source that a composed blueprint uses.
type TarReader ¶ added in v0.9.0
TarReader is the subset of tar.Reader that the artifact package uses.
type TarWriter ¶
type TarWriter interface {
WriteHeader(hdr *tar.Header) error
Write(b []byte) (int, error)
Close() error
}
TarWriter is the subset of tar.Writer that the artifact package uses.
type TerraformScope ¶ added in v0.10.0
TerraformScope is one Terraform component of a blueprint. Root is the directory of the source that holds the Terraform components, and Path is relative to Root.