Help us shape the future of Go! Take the 2026 Go Developer Survey

pack

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidName

func IsValidName(name string) bool

Types

type Dependency

type Dependency struct {

	// Name on the pack dependency which must match the MetadataPack.Name
	// value if the source is empty. Otherwise, the source dictates where the
	// pack is loaded from, allowing the same pack to be used multiple times as
	// a dependency with different variables.
	Name string `hcl:"name,label"`

	// Alias overrides the dependency pack's Name in references when set,
	// allowing the same pack source to be used multiple times as with different
	// variable values.
	Alias string `hcl:"alias,optional"`

	// Ref is the git reference of the pack at which to add. Ignored if not
	// specifying a git source. Defaults to latest.
	Ref string `hcl:"ref,optional"`

	// Source is the remote source where the pack can be fetched. This string
	// can follow any format as supported by go-getter or be a local path
	// indicating the pack has already been downloaded.
	Source string `hcl:"source,optional"`

	// Enabled is a boolean flag to determine whether the dependency is
	// available for loading. This allows easy administrative control.
	Enabled *bool `hcl:"enabled,optional"`
}

Dependency is a single dependency of a pack. A pack can have multiple and each dependency represents an individual pack. A pack can be used as a dependency multiple times. This allows helper pack to define jobspec blocks which are used multiple times, with different variable substitutions.

func (*Dependency) AliasOrName

func (d *Dependency) AliasOrName() string

AliasOrName returns the pack's Alias or the pack's Name, preferring the Alias when set.

func (*Dependency) ID

func (d *Dependency) ID() ID

ID returns the identifier for the pack. The function returns a ID which implements the Stringer interface

func (*Dependency) IsLatest

func (d *Dependency) IsLatest() bool

IsLatest works out if the user requested the HEAD of the dependency

type File

type File struct {

	// Name represents the name of the file as a reference from the pack
	// directory.
	Name string

	// Path is the absolute path of the file in question.
	Path string

	// Content is the file contents as a byte array.
	Content []byte
}

File is an individual file component of a Pack.

type ID

type ID string

func (ID) AsPath

func (p ID) AsPath() string

AsPath returns a string with the dot delimiters converted to `/` for use with file system paths.

func (ID) Join

func (p ID) Join(child ID) ID

Join returns a new ID with the child path appended to it.

func (ID) String

func (p ID) String() string

type Metadata

type Metadata struct {
	App          *MetadataApp         `hcl:"app,block"`
	Pack         *MetadataPack        `hcl:"pack,block"`
	Integration  *MetadataIntegration `hcl:"integration,block"`
	Dependencies []*Dependency        `hcl:"dependency,block"`
}

Metadata is the contents of the Pack metadata.hcl file. It contains high-level information about the pack which is useful for operators and is also exposed as template variables during rendering.

func (*Metadata) AddToInterfaceMap

func (md *Metadata) AddToInterfaceMap(m map[string]any) map[string]any

AddToInterfaceMap adds the metadata information to the provided map as a new entry under the "nomad_pack" key. This is useful for adding this information to the template rendering data. Used in the deprecated V1 Renderer

func (*Metadata) ConvertToMapInterface

func (md *Metadata) ConvertToMapInterface() map[string]any

ConvertToMapInterface returns a map[string]any representation of the metadata object. The conversion doesn't take into account empty values and will add them.

func (*Metadata) Validate

func (md *Metadata) Validate() error

Validate the entire Metadata object to ensure it meets requirements and doesn't contain invalid or incorrect data.

type MetadataApp

type MetadataApp struct {

	// URL is the HTTP(S) url to the homepage of the application to provide a
	// quick reference to the documentation and help pages.
	URL string `hcl:"url"`

	// Author is an identifier to the author and maintainer of the pack such as
	// HashiCorp or James Rasell
	//
	// Deprecated: Nomad Pack tech preview 4 removes this field, we keep it here for
	// backwards compatibility only.
	Author string `hcl:"author,optional"`
}

MetadataApp contains information regarding the application that the pack is focussed around.

type MetadataIntegration

type MetadataIntegration struct {

	// Identifier is a unique identifier that points to a specific integration
	// registered in the HashiCorp Developer Integrations Library.
	Identifier string `hcl:"identifier"`

	// Flags is an array of strings referencing various booleans you
	// can enable for your pack as it will display in the integrations
	// library. All flag options are specified within this file:
	// https://github.com/hashicorp/integrations/blob/main/flags.hcl
	Flags []string `hcl:"flags,optional"`

	// You can optionally override the pack.name value here to adjust
	// the name that will be displayed in HashiCorp Developer. For example,
	// your pack name may be "hello_world", whereas on HashiCorp Developer
	// you would like the name to render as "Hello World".
	Name string `hcl:"name,optional"`
}

MetadataIntegration contains information pertaining to the HashiCorp Developer (https://developer.hashicorp.com/) Integrations Library. This block is only needed for packs that are to be displayed in the integrations library.

Note: Currently, the integrations library is in closed beta, so you will not be able to register an integration without support from a HashiCorp team member. Furthermore, you may not be able to access some of the links specified below in this structs documentation.

type MetadataPack

type MetadataPack struct {

	// Name of the pack which acts as a convenience for use within template
	// rendering.
	Name string `hcl:"name"`

	// Alias will optionally override the provided Pack name value when set
	Alias string `hcl:"alias,optional"`

	// Description is a small overview of the application that is deployed by
	// the pack.
	Description string `hcl:"description,optional"`

	// URL is the HTTP(S) url of the pack which is acts as a convenience when
	// managing packs within a registry.
	//
	// Deprecated: Nomad Pack tech preview 4 removes this field, we keep it here for
	// backwards compatibility only.
	URL string `hcl:"url,optional"`

	// Version is the version of the pack which is acts as a convenience when
	// managing packs within a registry.
	Version string `hcl:"version"`
}

MetadataPack contains information regarding the pack itself.

type Pack

type Pack struct {

	// Metadata is the contents of the Pack metadata.hcl file. It contains
	// high-level information about the pack which is useful for operators and
	// is also exposed as template variables during rendering.
	Metadata *Metadata

	// TemplateFiles are the templated files which constitute this Pack. The
	// list includes both helper templates and Nomad resource templates and all
	// files within the list will be processed by the rendering engine.
	TemplateFiles []*File

	// AuxiliaryFiles are the files included in the "templates" directory of the
	// Pack that will also be rendered, but not run.
	AuxiliaryFiles []*File

	// RootVariableFile is the file which contains the root variables that can
	// include a description, type, and default value. This is parsed along
	// with any override variables and stored within Variables.
	RootVariableFile *File

	// OutputTemplateFile contains the optional output template file. If this
	// string is empty, it is assumed there is no output template to render and
	// print.
	OutputTemplateFile *File
	// contains filtered or unexported fields
}

Pack is a single nomad-pack package and contains all the required information to successfully interrogate and render the pack.

func (*Pack) AddDependencies

func (p *Pack) AddDependencies(packs ...*Pack)

AddDependencies to the pack, correctly setting their parent pack identifier.

func (*Pack) AddDependency

func (p *Pack) AddDependency(alias ID, pack *Pack)

AddDependency to the pack, correctly setting their parent pack identifier and alias.

func (*Pack) Alias

func (p *Pack) Alias() string

Alias returns the alias assigned to the pack. The canonical value for this comes from the alias on a running pack with a fallback to the Pack.Alias Metadata struct field.

func (*Pack) AliasOrName

func (p *Pack) AliasOrName() string

AliasOrName returns the pack's Alias or the pack's Name, preferring the Alias when set.

func (*Pack) Dependencies

func (p *Pack) Dependencies() []*Pack

Dependencies returns the list of dependencies the Pack has.

func (*Pack) HasParent

func (p *Pack) HasParent() bool

HasParent reports whether this pack has a parent or can be considered the top level pack.

func (*Pack) ID

func (p *Pack) ID() ID

ID returns the identifier for the pack. The function returns a ID which implements the Stringer interface

func (*Pack) Name

func (p *Pack) Name() string

Name returns the name of the pack. The canonical value for this comes from the Pack.Name Metadata struct field.

func (*Pack) RootVariableFiles

func (p *Pack) RootVariableFiles() map[ID]*File

RootVariableFiles generates a mapping of all root variable files for the pack and all dependencies.

func (*Pack) Validate

func (p *Pack) Validate() error

Validate the pack for terminal problems that can easily be detected at this stage. Anything that has potential to cause a panic should ideally be caught here.

func (*Pack) VariablesPath

func (p *Pack) VariablesPath() ID

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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