deploy

package
v0.0.0-...-70da08f Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const CopyPrivateKeyFunc string = `` /* 180-byte string literal not displayed */
View Source
const CreateInstanceUserFunc string = `` /* 593-byte string literal not displayed */
View Source
const DeployProviderAws string = "aws"
View Source
const DeployProviderOpenstack string = "openstack"
View Source
const InitVolumeAttachmentFunc string = `` /* 1331-byte string literal not displayed */
View Source
const LogColorGreen string = "\033[32m"
View Source
const LogColorRed string = "\033[31m"
View Source
const LogColorReset string = "\033[0m"

Variables

This section is empty.

Functions

func AddLogMsg

func AddLogMsg(sb *strings.Builder, logMsg LogMsg)

func CmdChainExecToString

func CmdChainExecToString(title string, logContent string, err error, isVerbose bool) string

func ExecSshForClient

func ExecSshForClient(sshClient *ssh.Client, cmd string) (string, string, error)

func FileGroupUpDefsToSpecs

func FileGroupUpDefsToSpecs(prj *Project, fileGroupsToUpload map[string]*FileGroupUpDef) ([]*FileUploadSpec, []*AfterFileUploadSpec, error)

func NewCopyPrivateKeysCommands

func NewCopyPrivateKeysCommands(iDef *InstanceDef) ([]string, error)

func NewCreateInstanceUsersCommands

func NewCreateInstanceUsersCommands(iDef *InstanceDef) ([]string, error)

Types

type AfterFileUploadSpec

type AfterFileUploadSpec struct {
	IpAddress string
	Env       map[string]string
	Cmd       []string
}

type AwsDeployProvider

type AwsDeployProvider struct{}

func (*AwsDeployProvider) AttachVolume

func (*AwsDeployProvider) AttachVolume(prjPair *ProjectPair, iNickname string, volNickname string, isVerbose bool) (LogMsg, error)

func (*AwsDeployProvider) CreateFloatingIp

func (*AwsDeployProvider) CreateFloatingIp(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func (*AwsDeployProvider) CreateInstanceAndWaitForCompletion

func (*AwsDeployProvider) CreateInstanceAndWaitForCompletion(prjPair *ProjectPair, iNickname string, flavorId string, imageId string, _ string, isVerbose bool) (LogMsg, error)

func (*AwsDeployProvider) CreateNetworking

func (*AwsDeployProvider) CreateNetworking(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func (*AwsDeployProvider) CreateSecurityGroups

func (*AwsDeployProvider) CreateSecurityGroups(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func (*AwsDeployProvider) CreateVolume

func (*AwsDeployProvider) CreateVolume(prjPair *ProjectPair, iNickname string, volNickname string, isVerbose bool) (LogMsg, error)

func (*AwsDeployProvider) DeleteFloatingIp

func (*AwsDeployProvider) DeleteFloatingIp(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func (*AwsDeployProvider) DeleteInstance

func (*AwsDeployProvider) DeleteInstance(prjPair *ProjectPair, iNickname string, isVerbose bool) (LogMsg, error)

func (*AwsDeployProvider) DeleteNetworking

func (*AwsDeployProvider) DeleteNetworking(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func (*AwsDeployProvider) DeleteSecurityGroups

func (*AwsDeployProvider) DeleteSecurityGroups(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func (*AwsDeployProvider) DeleteVolume

func (*AwsDeployProvider) DeleteVolume(prjPair *ProjectPair, iNickname string, volNickname string, isVerbose bool) (LogMsg, error)

func (*AwsDeployProvider) GetFlavorIds

func (*AwsDeployProvider) GetFlavorIds(prjPair *ProjectPair, flavorMap map[string]string, isVerbose bool) (LogMsg, error)

func (*AwsDeployProvider) GetImageIds

func (*AwsDeployProvider) GetImageIds(prjPair *ProjectPair, imageMap map[string]string, isVerbose bool) (LogMsg, error)

func (*AwsDeployProvider) GetKeypairs

func (*AwsDeployProvider) GetKeypairs(prjPair *ProjectPair, keypairMap map[string]struct{}, isVerbose bool) (LogMsg, error)

type BuildArtifactsDef

type BuildArtifactsDef struct {
	Env map[string]string `json:"env"`
	Cmd []string          `json:"cmd"`
}

type DeployProvider

type DeployProvider interface {
	CreateFloatingIp(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)
	DeleteFloatingIp(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)
	CreateSecurityGroups(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)
	DeleteSecurityGroups(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)
	CreateNetworking(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)
	DeleteNetworking(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)
	GetFlavorIds(prjPair *ProjectPair, flavorMap map[string]string, isVerbose bool) (LogMsg, error)
	GetImageIds(prjPair *ProjectPair, imageMap map[string]string, isVerbose bool) (LogMsg, error)
	GetKeypairs(prjPair *ProjectPair, keypairMap map[string]struct{}, isVerbose bool) (LogMsg, error)
	CreateInstanceAndWaitForCompletion(prjPair *ProjectPair, iNickname string, flavorId string, imageId string, availabilityZone string, isVerbose bool) (LogMsg, error)
	DeleteInstance(prjPair *ProjectPair, iNickname string, isVerbose bool) (LogMsg, error)
	CreateVolume(prjPair *ProjectPair, iNickname string, volNickname string, isVerbose bool) (LogMsg, error)
	AttachVolume(prjPair *ProjectPair, iNickname string, volNickname string, isVerbose bool) (LogMsg, error)
	DeleteVolume(prjPair *ProjectPair, iNickname string, volNickname string, isVerbose bool) (LogMsg, error)
}

func DeployProviderFactory

func DeployProviderFactory(deployProviderName string) (DeployProvider, error)

type ExecResult

type ExecResult struct {
	Cmd     string
	Stdout  string
	Stderr  string
	Elapsed float64
	Error   error
}

func ExecLocal

func ExecLocal(prj *Project, cmdPath string, params []string, envVars map[string]string, dir string) ExecResult

func ExecLocalAndGetJsonBool

func ExecLocalAndGetJsonBool(prj *Project, cmdPath string, params []string, query string) (bool, ExecResult)

func ExecLocalAndGetJsonString

func ExecLocalAndGetJsonString(prj *Project, cmdPath string, params []string, query string, allowEmpty bool) (string, ExecResult)

func ExecLocalAndGetJsonValue

func ExecLocalAndGetJsonValue(prj *Project, cmdPath string, params []string, query string) (any, ExecResult)

func ExecSsh

func ExecSsh(sshConfig *SshConfigDef, ipAddress string, cmd string) ExecResult

func ExecSshAndReturnLastLine

func ExecSshAndReturnLastLine(sshConfig *SshConfigDef, ipAddress string, cmd string) (string, ExecResult)

func (*ExecResult) ToString

func (er *ExecResult) ToString() string

type ExecTimeouts

type ExecTimeouts struct {
	OpenstackCmd              int `json:"openstack_cmd"`
	OpenstackInstanceCreation int `json:"openstack_instance_creation"`
	AttachVolume              int `json:"attach_volume"`
}

type FileDownloadSpec

type FileDownloadSpec struct {
	IpAddress string
	Src       string
	Dst       string
}

func FileGroupDownDefsToSpecs

func FileGroupDownDefsToSpecs(prj *Project, fileGroupsToDownload map[string]*FileGroupDownDef) ([]*FileDownloadSpec, error)

func InstanceFileGroupDownDefsToSpecs

func InstanceFileGroupDownDefsToSpecs(prj *Project, ipAddress string, fgDef *FileGroupDownDef) ([]*FileDownloadSpec, error)

type FileGroupDownDef

type FileGroupDownDef struct {
	Src string `json:"src"`
	Dst string `json:"dst"`
}

type FileGroupUpAfter

type FileGroupUpAfter struct {
	Env map[string]string `json:"env,omitempty"`
	Cmd []string          `json:"cmd,omitempty"`
}

type FileGroupUpDef

type FileGroupUpDef struct {
	Src             string           `json:"src"`
	Dst             string           `json:"dst"`
	DirPermissions  int              `json:"dir_permissions"`
	FilePermissions int              `json:"file_permissions"`
	Owner           string           `json:"owner,omitempty"`
	After           FileGroupUpAfter `json:"after,omitempty"`
}

type FileUploadSpec

type FileUploadSpec struct {
	IpAddress       string
	Src             string
	Dst             string
	DirPermissions  int
	FilePermissions int
	Owner           string
}

type InstanceDef

type InstanceDef struct {
	HostName                       string                `json:"host_name"`
	SecurityGroupNickname          string                `json:"security_group"`
	RootKeyName                    string                `json:"root_key_name"`
	IpAddress                      string                `json:"ip_address"`
	UsesSshConfigExternalIpAddress bool                  `json:"uses_ssh_config_external_ip_address,omitempty"`
	ExternalIpAddress              string                `json:"external_ip_address,omitempty"`
	FlavorName                     string                `json:"flavor"`
	ImageName                      string                `json:"image"`
	AvailabilityZone               string                `json:"availability_zone"`
	SubnetType                     string                `json:"subnet_type"`
	Volumes                        map[string]*VolumeDef `json:"volumes,omitempty"`
	Id                             string                `json:"id"`
	Users                          []UserDef             `json:"users,omitempty"`
	PrivateKeys                    []PrivateKeyDef       `json:"private_keys,omitempty"`
	Service                        ServiceDef            `json:"service"`
	ApplicableFileGroups           []string              `json:"applicable_file_groups,omitempty"`
}

func (*InstanceDef) BestIpAddress

func (iDef *InstanceDef) BestIpAddress() string

func (*InstanceDef) Clean

func (iDef *InstanceDef) Clean()

type LogBuilder

type LogBuilder struct {
	Sb        *strings.Builder
	IsVerbose bool
	Header    string
	StartTs   time.Time
}

func NewLogBuilder

func NewLogBuilder(header string, isVerbose bool) *LogBuilder

func (*LogBuilder) Add

func (lb *LogBuilder) Add(content string)

func (*LogBuilder) Complete

func (lb *LogBuilder) Complete(err error) (LogMsg, error)

type LogMsg

type LogMsg string

func BuildArtifacts

func BuildArtifacts(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func DownloadFileSftp

func DownloadFileSftp(prj *Project, ipAddress string, srcPath string, dstPath string, isVerbose bool) (LogMsg, error)

func ExecCommandsOnInstance

func ExecCommandsOnInstance(sshConfig *SshConfigDef, ipAddress string, cmds []string, isVerbose bool) (LogMsg, error)

func ExecScriptsOnInstance

func ExecScriptsOnInstance(sshConfig *SshConfigDef, ipAddress string, env map[string]string, prjFileDirPath string, shellScriptFiles []string, isVerbose bool) (LogMsg, error)

func UploadFileS3

func UploadFileS3(prj *Project, srcPath string, dstPath string, isVerbose bool) (LogMsg, error)

func UploadFileSftp

func UploadFileSftp(prj *Project, ipAddress string, srcPath string, dstPath string, dirPermissions int, filePermissions int, owner string, isVerbose bool) (LogMsg, error)

type NetworkDef

type NetworkDef struct {
	Name          string           `json:"name"`
	Id            string           `json:"id"`
	Cidr          string           `json:"cidr"`
	PrivateSubnet PrivateSubnetDef `json:"private_subnet"`
	PublicSubnet  PublicSubnetDef  `json:"public_subnet"`
	Router        RouterDef        `json:"router"`
}

type OpenstackDeployProvider

type OpenstackDeployProvider struct{}

func (*OpenstackDeployProvider) AttachVolume

func (*OpenstackDeployProvider) AttachVolume(prjPair *ProjectPair, iNickname string, volNickname string, isVerbose bool) (LogMsg, error)

func (*OpenstackDeployProvider) CreateFloatingIp

func (*OpenstackDeployProvider) CreateFloatingIp(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func (*OpenstackDeployProvider) CreateInstanceAndWaitForCompletion

func (*OpenstackDeployProvider) CreateInstanceAndWaitForCompletion(prjPair *ProjectPair, iNickname string, flavorId string, imageId string, availabilityZone string, isVerbose bool) (LogMsg, error)

func (*OpenstackDeployProvider) CreateNetworking

func (*OpenstackDeployProvider) CreateNetworking(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func (*OpenstackDeployProvider) CreateSecurityGroups

func (*OpenstackDeployProvider) CreateSecurityGroups(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func (*OpenstackDeployProvider) CreateVolume

func (*OpenstackDeployProvider) CreateVolume(prjPair *ProjectPair, iNickname string, volNickname string, isVerbose bool) (LogMsg, error)

func (*OpenstackDeployProvider) DeleteFloatingIp

func (*OpenstackDeployProvider) DeleteFloatingIp(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func (*OpenstackDeployProvider) DeleteInstance

func (*OpenstackDeployProvider) DeleteInstance(prjPair *ProjectPair, iNickname string, isVerbose bool) (LogMsg, error)

func (*OpenstackDeployProvider) DeleteNetworking

func (*OpenstackDeployProvider) DeleteNetworking(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func (*OpenstackDeployProvider) DeleteSecurityGroups

func (*OpenstackDeployProvider) DeleteSecurityGroups(prjPair *ProjectPair, isVerbose bool) (LogMsg, error)

func (*OpenstackDeployProvider) DeleteVolume

func (*OpenstackDeployProvider) DeleteVolume(prjPair *ProjectPair, iNickname string, volNickname string, isVerbose bool) (LogMsg, error)

func (*OpenstackDeployProvider) GetFlavorIds

func (*OpenstackDeployProvider) GetFlavorIds(prjPair *ProjectPair, flavorMap map[string]string, isVerbose bool) (LogMsg, error)

func (*OpenstackDeployProvider) GetImageIds

func (*OpenstackDeployProvider) GetImageIds(prjPair *ProjectPair, imageMap map[string]string, isVerbose bool) (LogMsg, error)

func (*OpenstackDeployProvider) GetKeypairs

func (*OpenstackDeployProvider) GetKeypairs(prjPair *ProjectPair, keypairMap map[string]struct{}, isVerbose bool) (LogMsg, error)

type PrivateKeyDef

type PrivateKeyDef struct {
	Name           string `json:"name"`
	PrivateKeyPath string `json:"private_key_path"`
}

type PrivateSubnetDef

type PrivateSubnetDef struct {
	Name             string `json:"name"`
	Id               string `json:"id"`
	Cidr             string `json:"cidr"`
	AllocationPool   string `json:"allocation_pool"`    // start=192.168.199.2,end=192.168.199.254
	AvailabilityZone string `json:"availability_zone"`  // AWS only
	RouteTableToNat  string `json:"route_table_to_nat"` // AWS only
}

type Project

type Project struct {
	Artifacts          BuildArtifactsDef            `json:"artifacts"`
	SshConfig          *SshConfigDef                `json:"ssh_config"`
	Timeouts           ExecTimeouts                 `json:"timeouts"`
	EnvVariablesUsed   []string                     `json:"env_variables_used"`
	SecurityGroups     map[string]*SecurityGroupDef `json:"security_groups"`
	Network            NetworkDef                   `json:"network"`
	FileGroupsUp       map[string]*FileGroupUpDef   `json:"file_groups_up"`
	FileGroupsDown     map[string]*FileGroupDownDef `json:"file_groups_down"`
	Instances          map[string]*InstanceDef      `json:"instances"`
	DeployProviderName string                       `json:"deploy_provider_name"`
	S3FileGroupsUp     map[string]*S3FileGroupUpDef `json:"s3_file_groups_up"`
	CliEnvVars         map[string]string
}

func (*Project) SaveProject

func (prj *Project) SaveProject(fullPrjPath string) error

type ProjectPair

type ProjectPair struct {
	Template           Project
	Live               Project
	ProjectFileDirPath string
}

func LoadProject

func LoadProject(prjFile string) (*ProjectPair, string, error)

func (*ProjectPair) CleanInstance

func (prjPair *ProjectPair) CleanInstance(iNickname string)

func (*ProjectPair) CleanSecurityGroup

func (prjPair *ProjectPair) CleanSecurityGroup(sgNickname string)

func (*ProjectPair) SetAttachedVolumeDevice

func (prjPair *ProjectPair) SetAttachedVolumeDevice(iNickname string, volNickname string, device string)

func (*ProjectPair) SetInstanceId

func (prjPair *ProjectPair) SetInstanceId(iNickname string, newId string)

func (*ProjectPair) SetNatGatewayExternalIp

func (prjPair *ProjectPair) SetNatGatewayExternalIp(newIp string)

func (*ProjectPair) SetNatGatewayId

func (prjPair *ProjectPair) SetNatGatewayId(newId string)

func (*ProjectPair) SetNetworkId

func (prjPair *ProjectPair) SetNetworkId(newId string)

func (*ProjectPair) SetPrivateSubnetId

func (prjPair *ProjectPair) SetPrivateSubnetId(newId string)

func (*ProjectPair) SetPublicSubnetId

func (prjPair *ProjectPair) SetPublicSubnetId(newId string)

func (*ProjectPair) SetRouteTableToNat

func (prjPair *ProjectPair) SetRouteTableToNat(newId string)

func (*ProjectPair) SetRouterId

func (prjPair *ProjectPair) SetRouterId(newId string)

func (*ProjectPair) SetSecurityGroupId

func (prjPair *ProjectPair) SetSecurityGroupId(sgNickname string, newId string)

func (*ProjectPair) SetSecurityGroupRuleId

func (prjPair *ProjectPair) SetSecurityGroupRuleId(sgNickname string, ruleIdx int, newId string)

func (*ProjectPair) SetSshExternalIp

func (prjPair *ProjectPair) SetSshExternalIp(newIp string)

func (*ProjectPair) SetVolumeAttachmentId

func (prjPair *ProjectPair) SetVolumeAttachmentId(iNickname string, volNickname string, newId string)

func (*ProjectPair) SetVolumeBlockDeviceId

func (prjPair *ProjectPair) SetVolumeBlockDeviceId(iNickname string, volNickname string, newId string)

func (*ProjectPair) SetVolumeId

func (prjPair *ProjectPair) SetVolumeId(iNickname string, volNickname string, newId string)

type PublicSubnetDef

type PublicSubnetDef struct {
	Name               string `json:"name"`
	Id                 string `json:"id"`
	Cidr               string `json:"cidr"`
	AvailabilityZone   string `json:"availability_zone"`
	NatGatewayName     string `json:"nat_gateway_name"`
	NatGatewayId       string `json:"nat_gateway_id"`
	NatGatewayPublicIp string `json:"nat_gateway_public_ip"`
}

type RouterDef

type RouterDef struct {
	Name                       string `json:"name"`
	Id                         string `json:"id"`
	ExternalGatewayNetworkName string `json:"external_gateway_network_name"`
}

type RouterInterfaceInfo

type RouterInterfaceInfo struct {
	PortId    string `json:"port_id"`
	IpAddress string `json:"ip_address"`
	SubnetId  string `json:"subnet_id"`
}

type S3FileGroupUpDef

type S3FileGroupUpDef struct {
	Bucket string `json:"bucket"` // s3://capi-in
	Src    string `json:"src"`
	Dst    string `json:"dst"`
}

type S3FileUploadSpec

type S3FileUploadSpec struct {
	Src string
	Dst string
}

func S3FileGroupUpDefsToSpecs

func S3FileGroupUpDefsToSpecs(prj *Project, s3FileGroupsToUpload map[string]*S3FileGroupUpDef) ([]*S3FileUploadSpec, error)

type SecurityGroupDef

type SecurityGroupDef struct {
	Name  string                  `json:"name"`
	Id    string                  `json:"id"`
	Rules []*SecurityGroupRuleDef `json:"rules"`
}

func (*SecurityGroupDef) Clean

func (sg *SecurityGroupDef) Clean()

type SecurityGroupRuleDef

type SecurityGroupRuleDef struct {
	Desc      string `json:"desc"`      // human-readable
	Id        string `json:"id"`        // guid
	Protocol  string `json:"protocol"`  // tcp
	Ethertype string `json:"ethertype"` // IPv4
	RemoteIp  string `json:"remote_ip"` // 0.0.0.0/0
	Port      int    `json:"port"`      // 22
	Direction string `json:"direction"` // ingress
}

type ServiceCommandsDef

type ServiceCommandsDef struct {
	Install []string `json:"install"`
	Config  []string `json:"config"`
	Start   []string `json:"start"`
	Stop    []string `json:"stop"`
}

type ServiceDef

type ServiceDef struct {
	Env map[string]string  `json:"env"`
	Cmd ServiceCommandsDef `json:"cmd"`
}

type SshConfigDef

type SshConfigDef struct {
	ExternalIpAddress  string `json:"external_ip_address"`
	Port               int    `json:"port"`
	User               string `json:"user"`
	PrivateKeyPath     string `json:"private_key_path"`
	PrivateKeyPassword string `json:"private_key_password"`
}

type TunneledSshClient

type TunneledSshClient struct {
	ProxySshClient  *ssh.Client
	TunneledTcpConn net.Conn
	TunneledSshConn ssh.Conn
	SshClient       *ssh.Client
}

func NewTunneledSshClient

func NewTunneledSshClient(sshConfig *SshConfigDef, ipAddress string) (*TunneledSshClient, error)

func (*TunneledSshClient) Close

func (tsc *TunneledSshClient) Close()

type UserDef

type UserDef struct {
	Name          string `json:"name"`
	PublicKeyPath string `json:"public_key_path"`
}

type VolumeDef

type VolumeDef struct {
	Name             string `json:"name"`
	MountPoint       string `json:"mount_point"`
	Size             int    `json:"size"`
	Type             string `json:"type"`
	Permissions      int    `json:"permissions"`
	Owner            string `json:"owner"`
	AvailabilityZone string `json:"availability_zone"`
	VolumeId         string `json:"id"`
	AttachmentId     string `json:"attachment_id"`
	Device           string `json:"device"`
	BlockDeviceId    string `json:"block_device_id"`
}

Jump to

Keyboard shortcuts

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