shared

package
v0.0.0-...-95fffc9 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ComposefileName  = "brave-compose.yaml"
	ComposefileAlias = "brave-compose.yml"
)
View Source
const BraveCertStore = BraveHome + "/certs"
View Source
const BraveClientCert = BraveCertStore + "/client.crt"

BraveClientCert ..

View Source
const BraveClientKey = BraveCertStore + "/client.key"

BraveClientKey ..

View Source
const BraveDB = BraveHome + "/bravetools.db"

BraveDB path to Bravetools database

View Source
const BraveHome = "/.bravetools"
View Source
const BraveRemoteStore = BraveHome + "/remotes"

BraveRemoteStore is path to remotes dir

View Source
const BraveServerCertStore = BraveHome + "/servercerts"
View Source
const BravefileTemplate = `` /* 319-byte string literal not displayed */

Bravefile template

View Source
const BravetoolsRemote = "local"

Bravetools local remote name

View Source
const BravetoolsVmName = "bravetools"

Name of Bravetools VM if not on Linux

View Source
const DefaultUnitCpuLimit = "2"

DefaultUnitCpuLimit - used if not specified

View Source
const DefaultUnitRamLimit = "2GB"

DefaultUnitRamLimit - used if not specified

View Source
const ImageStore = BraveHome + "/images/"

ImageStore ..

View Source
const PlatformConfig = BraveHome + "/config.yml"

PlatformConfig ..

View Source
const REINIT = `` /* 179-byte string literal not displayed */

REINIT ..

View Source
const REMOVELIN = `` /* 271-byte string literal not displayed */

REMOVELIN ..

View Source
const REMOVEMP = `` /* 135-byte string literal not displayed */

REMOVEMP ..

View Source
const SnapLXC = "/snap/bin/lxc"

SnapLXC lxc command path in Snap

Variables

View Source
var (
	// Info ..
	Info = teal
	// Warn ..
	Warn = yellow
	// Fatal ..
	Fatal = red
)
View Source
var Version string

Functions

func CheckPath

func CheckPath(path string) (bool, error)

CheckPath checks if path exists

func CollectErrors

func CollectErrors(errs ...error) error

CollectErrors returns the first error encountered or nil if there are none

func Color

func Color(colorString string) func(...interface{}) string

Color applies colors in terminal

func CopyFile

func CopyFile(src, dst string) error

CopyFile util function

func CreateDirectory

func CreateDirectory(dirPath string) error

CreateDirectory creates a directory path if not exists

func ExecCommand

func ExecCommand(name string, arg ...string) error

ExecCommand runs a command

func ExecCommandWReturn

func ExecCommandWReturn(name string, arg ...string) (string, error)

ExecCommandWReturn ..

func FileExists

func FileExists(filename string) bool

FileExists checks if path exists and ensures that it's a file

func FileHash

func FileHash(filePath string) (string, error)

FileHash creates MD5 for a given file

func FileSha256Hash

func FileSha256Hash(path string) (fingerprint string, err error)

func FormatByteCountSI

func FormatByteCountSI(b int64) string

FormatByteCountSI Returns formatted byte

func GenerateRandomRFC1919

func GenerateRandomRFC1919() (string, error)

GenerateRandomRFC1919 generates a random address in 10.x.x.1/24 range

func RandomSequence

func RandomSequence(n int) string

RandomSequence generates a random sequence with length n

func ReadFile

func ReadFile(path string) (*bytes.Buffer, error)

ReadFile ..

func SizeCountToInt

func SizeCountToInt(s string) (int64, error)

SizeCountToInt convert size strings to integer bytes

func StrSliceIndexOf

func StrSliceIndexOf(slice []string, element string) (index int, err error)

StrSliceIndexOf returns index of first occurence of element in a str slice or err if not found

func StringInSlice

func StringInSlice(a string, list []string) bool

StringInSlice checks if string is present in a slice

func StringSliceSearch

func StringSliceSearch(array []string, expression string) ([]int, error)

StringSliceSearch searches a string slice for an expression and returns its indeces

func TCPPortStatus

func TCPPortStatus(host string, ports []string) error

TCPPortStatus checks if multiple ports are available on the host

func TruncateStringLeft

func TruncateStringLeft(str string, num int) string

TruncateStringLeft to specific number of characters fro the left

func TruncateStringRight

func TruncateStringRight(str string, num int) string

TruncateStringRight to specific number of characters fro the right

func VersionString

func VersionString() string

VersionString prints Bravetools version

func WalkMatch

func WalkMatch(root, pattern string) ([]string, error)

WalkMatch ..

Types

type BraveProfile

type BraveProfile struct {
	Name       string
	Storage    string
	Bridge     string
	LxdVersion string
}

BraveProfile ..

type BraveUnit

type BraveUnit struct {
	Name    string
	Status  string
	Address string
	Disk    []DiskDevice
	Proxy   []ProxyDevice
	NIC     NicDevice
}

BraveUnit ..

type Bravefile

type Bravefile struct {
	Image           string           `yaml:"image,omitempty"`
	Base            ImageDescription `yaml:"base,omitempty"`
	SystemPackages  Packages         `yaml:"packages,omitempty"`
	Run             []RunCommand     `yaml:"run,omitempty"`
	Copy            []CopyCommand    `yaml:"copy,omitempty"`
	PlatformService Service          `yaml:"service,omitempty"`
}

Bravefile describes unit configuration

func GetBravefileFromGitHub

func GetBravefileFromGitHub(name string) (*Bravefile, error)

GetBravefileFromGitHub reads bravefile from a github URL

func NewBravefile

func NewBravefile() *Bravefile

NewBravefile ..

func (*Bravefile) IsLegacy

func (bravefile *Bravefile) IsLegacy() bool

func (*Bravefile) Load

func (bravefile *Bravefile) Load(file string) error

Load loads Bravefile

func (*Bravefile) ValidateBuild

func (bravefile *Bravefile) ValidateBuild() error

Validate validates Bravefile for build

type ComposeFile

type ComposeFile struct {
	Path     string
	Services map[string]*ComposeService `yaml:"services"`
}

A ComposeFile maps service names to services

func NewComposeFile

func NewComposeFile() *ComposeFile

NewComposeFile returns a pointer to a newly created empty ComposeFile struct

func (*ComposeFile) Load

func (composeFile *ComposeFile) Load(file string) error

Load reads a compose file from disk and loads its settings into the composeFile struct

func (*ComposeFile) TopologicalOrdering

func (composeFile *ComposeFile) TopologicalOrdering() (topologicalOrdering []string, err error)

TopologicalOrdering returns a string array of service names that are ordered so that each service comes after the services it depends on. If a valid ordering cannot be found due to cycles in the graph an error will be returned.

type ComposeService

type ComposeService struct {
	Service        `yaml:",inline"`
	BravefileBuild *Bravefile
	Bravefile      string   `yaml:"bravefile,omitempty"`
	Build          bool     `yaml:"build,omitempty"`
	Base           bool     `yaml:"base,omitempty"`
	Context        string   `yaml:"context,omitempty"`
	Depends        []string `yaml:"depends_on,omitempty"`
}

ComposeService defines a service

type CopyCommand

type CopyCommand struct {
	Source string `yaml:"source,omitempty"`
	Target string `yaml:"target,omitempty"`
	Action string `yaml:"action,omitempty"`
}

CopyCommand defines source and target for files to be copied into container

type DiskDevice

type DiskDevice struct {
	Name   string
	Path   string
	Source string
}

DiskDevice ..

type ImageDescription

type ImageDescription struct {
	Image        string `yaml:"image"`
	Location     string `yaml:"location"`
	Architecture string `yaml:"architecture"`
}

ImageDescription defines base image type and source

type NicDevice

type NicDevice struct {
	Name    string
	Type    string
	NicType string
	Parent  string
	IP      string
}

NicDevice ..

type Packages

type Packages struct {
	Manager string   `yaml:"manager,omitempty"`
	System  []string `yaml:"system,omitempty"`
}

Packages defines system packages to install in container

type Postdeploy

type Postdeploy struct {
	Run  []RunCommand  `yaml:"run,omitempty"`
	Copy []CopyCommand `yaml:"copy,omitempty"`
}

Postdeploy defines operations to perform after service deployment finish

type ProxyDevice

type ProxyDevice struct {
	Name      string
	ConnectIP string
	ListenIP  string
}

ProxyDevice ..

type Resources

type Resources struct {
	RAM  string `yaml:"ram"`
	CPU  string `yaml:"cpu"`
	GPU  string `yaml:"gpu"`
	Disk string `yaml:"disk"`
}

Resources defines resources allocated to service

type RunCommand

type RunCommand struct {
	Command string            `yaml:"command,omitempty"`
	Content string            `yaml:"content,omitempty"`
	Args    []string          `yaml:"args,omitempty"`
	Env     map[string]string `yaml:"env,omitempty"`
	Detach  bool              `yaml:"detach,omitempty"`
}

RunCommand defines custom commands to run inside continer

type Service

type Service struct {
	Name       string     `yaml:"name,omitempty"`
	Image      string     `yaml:"image,omitempty"`
	Version    string     `yaml:"version,omitempty"`
	Profile    string     `yaml:"profile,omitempty"`
	Storage    string     `yaml:"storage,omitempty"`
	Network    string     `yaml:"network,omitempty"`
	Docker     string     `yaml:"docker,omitempty"`
	IP         string     `yaml:"ip"`
	Ports      []string   `yaml:"ports"`
	Resources  Resources  `yaml:"resources"`
	Postdeploy Postdeploy `yaml:"postdeploy,omitempty"`
}

Service defines command to install app

func (*Service) IsLegacy

func (service *Service) IsLegacy() bool

func (*Service) Merge

func (s *Service) Merge(service *Service)

Merges two Service structs, prioritizing the values present in first struct

func (*Service) ValidateDeploy

func (service *Service) ValidateDeploy() error

Jump to

Keyboard shortcuts

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