imagebuilder

package
v0.0.0-...-9854be3 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2023 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpandTemplate

func ExpandTemplate(key string, templateString string, context interface{}) (string, error)

ExpandTemplate executes a golang template

func IsGCENotFound

func IsGCENotFound(err error) bool

func ReadFile

func ReadFile(p string) ([]byte, error)

ReadFile reads the whole file using ioutil.ReadFile, but does path expansion first

Types

type AWSCloud

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

AWSCloud is a helper type for talking to an AWS acccount

func NewAWSCloud

func NewAWSCloud(ec2 *ec2.EC2, config *AWSConfig, useLocalhost bool) *AWSCloud

func (*AWSCloud) CreateInstance

func (a *AWSCloud) CreateInstance() (Instance, error)

CreateInstance creates an instance for building an image instance

func (*AWSCloud) FindImage

func (a *AWSCloud) FindImage(imageName string) (Image, error)

FindImage finds a registered image, matching by the name tag

func (*AWSCloud) GetExtraEnv

func (a *AWSCloud) GetExtraEnv() (map[string]string, error)

func (*AWSCloud) GetInstance

func (a *AWSCloud) GetInstance() (Instance, error)

GetInstance returns the AWS instance matching our tags, or nil if not found

func (*AWSCloud) TagResource

func (a *AWSCloud) TagResource(resourceID string, tags ...*ec2.Tag) error

TagResource adds AWS tags to the specified resource

func (*AWSCloud) TerminateInstance

func (a *AWSCloud) TerminateInstance(instanceID string) error

TerminateInstance terminates the specified instance

type AWSConfig

type AWSConfig struct {
	Config

	Region          string
	ImageID         string
	InstanceType    string
	SSHKeyName      string
	SubnetID        string
	SecurityGroupID string
	Tags            map[string]string
}

func (*AWSConfig) InitDefaults

func (c *AWSConfig) InitDefaults(region string)

type AWSImage

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

AWSImage represents an AMI on AWS

func (*AWSImage) AddTags

func (i *AWSImage) AddTags(tags map[string]string) error

AddTags adds the specified tags on the image

func (*AWSImage) EnsurePublic

func (i *AWSImage) EnsurePublic() error

EnsurePublic makes the image accessible outside the current account

func (*AWSImage) ID

func (i *AWSImage) ID() string

ID returns the AWS identifier for the image

func (*AWSImage) ReplicateImage

func (i *AWSImage) ReplicateImage(makePublic bool) (map[string]Image, error)

ReplicateImage copies the image to all accessable AWS regions

func (*AWSImage) String

func (i *AWSImage) String() string

String returns a string representation of the image

type AWSInstance

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

AWSInstance manages an AWS instance, used for building an image

func (*AWSInstance) DialSSH

func (i *AWSInstance) DialSSH(config *ssh.ClientConfig) (executor.Executor, error)

DialSSH establishes an SSH client connection to the instance

func (*AWSInstance) Shutdown

func (i *AWSInstance) Shutdown() error

Shutdown terminates the running instance

func (*AWSInstance) WaitPublicIP

func (i *AWSInstance) WaitPublicIP() (string, error)

WaitPublicIP waits for the instance to get a public IP, returning it

type BootstrapVzTemplate

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

BootstrapVzTemplate represents a bootstrap-vz template file

func NewBootstrapVzTemplate

func NewBootstrapVzTemplate(data string) (*BootstrapVzTemplate, error)

NewBootstrapVzTemplate builds a BootstrapVzTemplate from a file

func (*BootstrapVzTemplate) BuildImageName

func (t *BootstrapVzTemplate) BuildImageName() (string, error)

BuildImageName computes the name of the image that will be built

func (*BootstrapVzTemplate) Bytes

func (t *BootstrapVzTemplate) Bytes() []byte

Bytes returns the template contents

type Builder

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

func NewBuilder

func NewBuilder(config *Config, target *executor.Target) *Builder

func (*Builder) BuildImage

func (b *Builder) BuildImage(template []byte, extraEnv map[string]string, logdir string) error

func (*Builder) RunSetupCommands

func (b *Builder) RunSetupCommands() error

type Cloud

type Cloud interface {
	GetInstance() (Instance, error)
	CreateInstance() (Instance, error)

	FindImage(imageName string) (Image, error)

	GetExtraEnv() (map[string]string, error)
}

type Config

type Config struct {
	Cloud         string
	TemplatePath  string
	SetupCommands [][]string

	BootstrapVZRepo   string
	BootstrapVZBranch string

	SSHUsername   string
	SSHPublicKey  string
	SSHPrivateKey string

	InstanceProfile string

	// Tags to add to the image
	Tags map[string]string
}

func (*Config) InitDefaults

func (c *Config) InitDefaults()

type GCECloud

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

GCECloud is a helper type for talking to an GCE acccount

func NewGCECloud

func NewGCECloud(computeClient *compute.Service, config *GCEConfig) *GCECloud

func (*GCECloud) CreateInstance

func (c *GCECloud) CreateInstance() (Instance, error)

CreateInstance creates an instance for building an image instance

func (*GCECloud) FindImage

func (c *GCECloud) FindImage(imageName string) (Image, error)

FindImage finds a registered image, matching by the name tag

func (*GCECloud) GetExtraEnv

func (a *GCECloud) GetExtraEnv() (map[string]string, error)

func (*GCECloud) GetInstance

func (c *GCECloud) GetInstance() (Instance, error)

GetInstance returns the GCE instance matching our tags, or nil if not found

type GCEConfig

type GCEConfig struct {
	Config

	// To create an image on GCE, we have to upload it to a bucket first
	GCSDestination string

	Project     string
	Zone        string
	MachineName string

	MachineType string
	Image       string
	Tags        map[string]string
}

func (*GCEConfig) InitDefaults

func (c *GCEConfig) InitDefaults()

type GCEImage

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

GCEImage represents an image on GCE

func (*GCEImage) AddTags

func (i *GCEImage) AddTags(tags map[string]string) error

AddTags adds the specified tags on the image

func (*GCEImage) EnsurePublic

func (i *GCEImage) EnsurePublic() error

EnsurePublic makes the image accessible outside the current account

func (*GCEImage) ReplicateImage

func (i *GCEImage) ReplicateImage(makePublic bool) (map[string]Image, error)

ReplicateImage copies the image to all accessible GCE regions

func (*GCEImage) String

func (i *GCEImage) String() string

String returns a string representation of the image

type GCEInstance

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

GCEInstance manages an GCE instance, used for building an image

func (*GCEInstance) DialSSH

func (i *GCEInstance) DialSSH(config *ssh.ClientConfig) (executor.Executor, error)

DialSSH establishes an SSH client connection to the instance

func (*GCEInstance) Shutdown

func (i *GCEInstance) Shutdown() error

Shutdown terminates the running instance

func (*GCEInstance) WaitPublicIP

func (i *GCEInstance) WaitPublicIP() (string, error)

WaitPublicIP waits for the instance to get a public IP, returning it

type Image

type Image interface {
	EnsurePublic() error

	// Adds the specified tags to the image
	AddTags(tags map[string]string) error

	ReplicateImage(makePublic bool) (map[string]Image, error)
}

type Instance

type Instance interface {
	DialSSH(config *ssh.ClientConfig) (executor.Executor, error)
	Shutdown() error
}

type LocalhostInstance

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

func (*LocalhostInstance) DialSSH

func (i *LocalhostInstance) DialSSH(config *ssh.ClientConfig) (executor.Executor, error)

DialSSH establishes an SSH client connection to the instance

func (*LocalhostInstance) Shutdown

func (i *LocalhostInstance) Shutdown() error

Shutdown terminates the running instance

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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