parser

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRandomString added in v0.2.0

func GenerateRandomString(length int) string

func GetProfilePath

func GetProfilePath() (string, error)

GetProfilePath returns the path to the profile file in the user's home directory

func LoadEnvVarsFromFile

func LoadEnvVarsFromFile(envFile string) (map[string]string, error)

LoadEnvVarsFromFile reads environment variables from the specified file and returns them as a map

func SaveProfile

func SaveProfile(profile *Profile, profilePath string) error

SaveProfile saves the profile to the specified path

Types

type AWSCloudResource added in v0.2.0

type AWSCloudResource struct {
	VPC *VPC `toml:"vpc,omitempty"`
	ECS *ECS `toml:"ecs,omitempty"`
}

type AppService

type AppService struct {
	ResourceGroupName  string `toml:"resource_group_name"`
	AppServicePlanName string `toml:"app_service_plan_name"`
	AppServiceName     string `toml:"app_service_name"`
}

type AzureCloudResource added in v0.2.0

type AzureCloudResource struct {
	AppService        *AppService        `toml:"app_service,omitempty"`
	ContainerInstance *ContainerInstance `toml:"container_instance,omitempty"`
}

type Config

type Config struct {
	Registry struct {
		Port     int    `mapstructure:"port" default:"5000"`
		Tag      string `mapstructure:"tag" default:"2"`
		Name     string `mapstructure:"name" default:"locreg-registry"`
		Image    string `mapstructure:"image" default:"registry"`
		Username string `mapstructure:"username"` // Set separately as should be unique each time
		Password string `mapstructure:"password"` // Set separately as should be unique each time
	} `mapstructure:"registry"`
	Image struct {
		Name string `mapstructure:"name" default:"locreg-built-image"`
		Tag  string `mapstructure:"tag"` // Set a git SHA if not peresent default to latest
	} `mapstructure:"image"`
	Tunnel struct {
		Provider struct {
			Ngrok struct {
				Name        string `mapstructure:"name" default:"locreg-ngrok"`
				Image       string `mapstructure:"image" default:"ngrok/ngrok"`
				Tag         string `mapstructure:"tag" default:"latest"`
				Port        int    `mapstructure:"port" default:"4040"`
				NetworkName string `mapstructure:"networkName" default:"locreg-ngrok"`
			} `mapstructure:"ngrok"`
		} `mapstructure:"provider"`
	} `mapstructure:"tunnel"`
	Deploy struct {
		Provider struct {
			Azure struct {
				Location       string `mapstructure:"location" default:"eastus"`
				ResourceGroup  string `mapstructure:"resourceGroup" default:"LocregResourceGroup"`
				AppServicePlan struct {
					Name string `mapstructure:"name" default:"LocregAppServicePlan"`
					Sku  struct {
						Name     string `mapstructure:"name" default:"F1"`
						Capacity int    `mapstructure:"capacity" default:"1"`
					} `mapstructure:"sku"`
					PlanProperties struct {
						Reserved bool `mapstructure:"reserved" default:"true"`
					} `mapstructure:"planProperties"`
				} `mapstructure:"appServicePlan"`
				AppService struct {
					Name       string `mapstructure:"name"` // Generated with random suffix
					SiteConfig struct {
						AlwaysOn bool `mapstructure:"alwaysOn" default:"false"`
					} `mapstructure:"siteConfig"`
				} `mapstructure:"appService"`
				ContainerInstance struct {
					Name          string `mapstructure:"name" default:"locreg-container"`
					OsType        string `mapstructure:"osType" default:"Linux"`
					RestartPolicy string `mapstructure:"restartPolicy" default:"Always"`
					IPAddress     struct {
						Type  string `mapstructure:"type" default:"Public"`
						Ports []struct {
							Port     int    `mapstructure:"port"`
							Protocol string `mapstructure:"protocol"`
						} `mapstructure:"ports"`
					} `mapstructure:"ipAddress"`
					Resources struct {
						Requests struct {
							CPU    float64 `mapstructure:"cpu" default:"1.0"`
							Memory float64 `mapstructure:"memory" default:"1.5"`
						} `mapstructure:"requests"`
					} `mapstructure:"resources"`
				} `mapstructure:"containerInstance"`
			} `mapstructure:"azure"`
			AWS struct {
				Region string `mapstructure:"region" default:"us-east-1"`
				ECS    struct {
					ClusterName           string `mapstructure:"clusterName" default:"locreg-cluster"`
					ServiceName           string `mapstructure:"serviceName" default:"locreg-service"`
					ServiceContainerCount int    `mapstructure:"serviceContainerCount" default:"1"`
					TaskDefinition        struct {
						Family              string `mapstructure:"family" default:"locreg-task"`
						IAMRoleName         string `mapstructure:"awsRoleName" default:"locreg-role"`
						MemoryAllocation    int    `mapstructure:"memoryAllocation" default:"512"`
						CPUAllocation       int    `mapstructure:"cpuAllocation" default:"256"`
						ContainerDefinition struct {
							Name         string `mapstructure:"name" default:"locreg-container"`
							PortMappings []struct {
								ContainerPort int    `mapstructure:"containerPort"`
								HostPort      int    `mapstructure:"hostPort"`
								Protocol      string `mapstructure:"protocol"`
							} `mapstructure:"portMappings"`
						} `mapstructure:"containerDefinitions"`
					} `mapstructure:"taskDefinition"`
				} `mapstructure:"ecs"`
				VPC struct {
					CIDRBlock string `mapstructure:"cidrBlock" default:"10.10.0.0/16"`
					Subnet    struct {
						CIDRBlock string `mapstructure:"cidrBlock" default:"10.10.10.0/24"`
					} `mapstructure:"subnet"`
				} `mapstructure:"vpc"`
			} `mapstructure:"aws"`
		} `mapstructure:"provider"`
	} `mapstructure:"deploy"`
	Tags map[string]*string `mapstructure:"tags"`
}

func LoadConfig

func LoadConfig(filePath string) (*Config, error)

func (*Config) GenerateContainerPorts added in v0.2.0

func (config *Config) GenerateContainerPorts() []types.PortMapping

GenerateContainerPorts generates the container ports mappings for the task definition

func (*Config) GenerateECSTags added in v0.2.0

func (config *Config) GenerateECSTags() []types.Tag

GenerateECSTags generates tags for the ECS cluster and task definition that is created

func (*Config) GenerateRulesForSG added in v0.2.0

func (config *Config) GenerateRulesForSG() []ec2Types.IpPermission

GenerateRulesForSG generates ingress and egress rules for a default security group. Generate rules to allow traffic only to ports that are exposed on container

func (*Config) GenerateSecretTags added in v0.2.0

func (config *Config) GenerateSecretTags() []secretsTypes.Tag

GenerateSecretTags generates tags for the ECS cluster and task definition that is created

func (*Config) GenerateVPCTags added in v0.2.0

func (config *Config) GenerateVPCTags(tagResourceType ec2Types.ResourceType) []ec2Types.TagSpecification

GenerateVPCTags generates tags for the VPC and subnet and all other parts of networking that must be created

func (*Config) GetRegistryImage added in v0.2.0

func (config *Config) GetRegistryImage() string

GetRegistryImage returns the registry image with the tag

func (*Config) IsAppServiceSet

func (config *Config) IsAppServiceSet() bool

IsAppServiceSet checks if the App Service configuration is set in the config. If it is set returns true if not returns false

func (*Config) IsContainerInstanceSet

func (config *Config) IsContainerInstanceSet() bool

IsContainerInstanceSet checks if the Container Instance configuration is set in the config. If it is set returns true if not returns false

func (*Config) IsNgrokConfigured

func (config *Config) IsNgrokConfigured() bool

type ContainerInstance

type ContainerInstance struct {
	ResourceGroupName     string `toml:"resource_group_name"`
	ContainerInstanceName string `toml:"container_instance_name"`
}

type ECS added in v0.2.0

type ECS struct {
	ECSClusterARN string `toml:"ecs_cluster_arn,omitempty"`
	TaskDefARN    string `toml:"task_def_arn,omitempty"`
	ServiceARN    string `toml:"service_arn,omitempty"`
	RoleARN       string `toml:"role_arn,omitempty"`
	SecretARN     string `tom:"secret_arn,omitempty"`
}

type LocalRegistry

type LocalRegistry struct {
	RegistryID string `toml:"registry_id"`
	Username   string `toml:"username"`
	Password   string `toml:"password"`
}

type Profile

type Profile struct {
	LocalRegistry      *LocalRegistry      `toml:"local_registry,omitempty"`
	Tunnel             *Tunnel             `toml:"tunnel,omitempty"`
	AzureCloudResource *AzureCloudResource `toml:"cloud_resource,omitempty"`
	AWSCloudResource   *AWSCloudResource   `toml:"aws_cloud_resource,omitempty"`
}

func LoadOrCreateProfile

func LoadOrCreateProfile(profilePath string) (*Profile, error)

LoadOrCreateProfile loads an existing profile or creates a new one if it doesn't exist

func LoadProfileData

func LoadProfileData() (*Profile, string)

LoadProfileData loads the profile data from the user's home directory or creates what it is not found.

Newer version of LoadOrCreateProfile function

func (*Profile) GetTunnelURL added in v0.2.0

func (profile *Profile) GetTunnelURL() string

func (*Profile) Save added in v0.2.0

func (profile *Profile) Save()

Save saves the profile to the user's home directory Newer version of SaveProfile function that avoids need of passing profilePath and profile as arguments

type Tunnel

type Tunnel struct {
	URL         string `toml:"tunnel_url"`
	ContainerID string `toml:"tunnel_container_id"`
}

type VPC added in v0.2.0

type VPC struct {
	InternetGatewayId string `toml:"internet_gateway_arn,omitempty"`
	VPCId             string `toml:"vpc_id,omitempty"`
	SubnetId          string `toml:"subnet_id,omitempty"`
	RouteTableId      string `toml:"route_table_id,omitempty"`
}

Jump to

Keyboard shortcuts

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