update: Added Longhorn installation process and updated memory allocation for VMs

update: Added 'git' and 'vagrant' to required tools in pre-flight checks

fix: configured k3s install to use internal nic for flanel network

update: Added Longhorn installation process and updated memory allocation for VMs

update: Added 'git' and 'vagrant' to required tools in pre-flight checks

fix: configured k3s install to use internal nic for flanel network

fix: corrected JSON formatting for config json

update: reduce VM memory allocation to 2GB, add Longhorn installation scripts and prerequisites, and implement checks for existing pods

fix: merge issues

fix: merge issues

update: Added Longhorn installation process and updated memory allocation for VMs

update: Added 'git' and 'vagrant' to required tools in pre-flight checks

fix: configured k3s install to use internal nic for flanel network

update: Added Longhorn installation process and updated memory allocation for VMs

update: Added 'git' and 'vagrant' to required tools in pre-flight checks

fix: configured k3s install to use internal nic for flanel network

fix: corrected JSON formatting for config json

update: reduce VM memory allocation to 2GB, add Longhorn installation scripts and prerequisites, and implement checks for existing pods

update: improve error logging in RunJsonDeployment and RunCommand functions

update: add jq installation to provision script

update: add version flag

bump version

fix: improve error messages for config file reading

feat: add Windows gitbash installation support and improve binary download process

clean up tmp code

fix: increase timeout for some slower windows clients

feat: add Ingress and Service configurations for nginx deployment, and implement MetalLB  and Traeik installation scripts

refactor: remove obsolete Traefik installation script

feat: add environment checks and configurations for Vagrant setup, including dnsmasq  MetalLB  and ingress

feat: add deployment and installation scripts for infmon-cli, including Kubernetes configurations

feat: refactor customer project creation and add success/failure job scripts

refactor: rename customer references to project in configuration and application logic

feat: enhance JSON deployment handling with retry logic and command execution improvements

feat: enhance RunJsonDeployment with error handling and retry logic; add tests for configuration reading

feat: add automatic creation of base and config JSON files from examples if they do not exist

refactor: remove database package and related functionality; update app state initialization and error handling

refactor: update deployment handling to use ProjectConfig; improve error messages and logging

feat: enhance RunJsonDeployment retry logic with configurable delay; improve logging for retries

feat: implement LoadConfigs function for improved configuration loading; add logger setup

refactor: remove unused fields from BaseConfig and ProjectConfig structs for cleaner configuration management

refactor: clean up tests by removing obsolete functions and simplifying test cases

chore: update version to v0.0.5 in install script

feat: implement default configuration creation for BaseConfig and ProjectConfig; enhance validation logic

fix: enhance configuration parsing and loading; streamline flag handling and error reporting

refactor: remove obsolete configuration download logic from installation script
This commit is contained in:
jon brookes 2025-08-16 18:00:28 +01:00
parent d839fd5687
commit 11b1f1b637
61 changed files with 1573 additions and 761 deletions

View file

@ -7,37 +7,30 @@ import (
"os"
)
const Version = "v0.0.5"
// Package-level variables for flags
var (
baseConfigFile string
projectConfigFile string
pipelineFile string
)
type BaseConfig struct {
ProjectsDirectory string `json:"projects_directory"`
Env string `json:"env"`
StaticImages string `json:"static_images"`
PublicImages string `json:"public_images"`
PhpConf string `json:"php_conf"`
Exports string `json:"exports"`
Logs string `json:"logs"`
PreviewPath string `json:"preview_path"`
DataWww string `json:"data_www"`
NginxConf string `json:"nginx_conf"`
AdminURL string `json:"admin_url"`
PreviewURL string `json:"preview_url"`
AppImage string `json:"app_image"`
WebserverImage string `json:"webserver_image"`
EmptyDB string `json:"empty_db"`
DB string `json:"db"`
EmptyImages string `json:"empty_imaages"`
DeploymentType string `json:"deployment_type"`
DeploymentFile string `json:"deployment_file"`
Port int `json:"port"`
RetryDelaySenconds int `json:"retry_delay_seconds"`
}
func ReadBaseConfig(path string) (BaseConfig, error) {
deploymentType := os.Getenv("DEPLOYMENT_TYPE")
deploymentFile := flag.String("deployment-file", "", "path to config file")
deploymentFileShorthand := flag.String("f", "", "shorthand for -deployment-file")
// ParseFlags parses all command-line flags and handles help/version flags
func ParseFlags() {
helpFlag := flag.Bool("help", false, "show help")
versionFlag := flag.Bool("version", false, "show version")
vFlag := flag.Bool("v", false, "show version (shorthand)")
flag.StringVar(&baseConfigFile, "base-config", "", "Path to base config file (optional)")
flag.StringVar(&projectConfigFile, "project-config", "", "Path to project config file (optional)")
flag.StringVar(&pipelineFile, "f", "", "Path to pipeline file")
flag.StringVar(&pipelineFile, "deployment-file", "", "Path to pipeline file (long format)")
flag.Parse()
if *helpFlag {
@ -46,22 +39,79 @@ func ReadBaseConfig(path string) (BaseConfig, error) {
os.Exit(0)
}
var config BaseConfig
if *deploymentFileShorthand != "" {
config.DeploymentFile = *deploymentFileShorthand
} else if *deploymentFile != "" {
config.DeploymentFile = *deploymentFile
if *versionFlag || *vFlag {
fmt.Println("infctl-cli version:", Version)
os.Exit(0)
}
}
func ReadBaseConfig(path string) (BaseConfig, error) {
config := BaseConfig{}
// If base.json does not exist, create it with default value
if _, err := os.Stat(path); os.IsNotExist(err) {
if err := CreateDefaultBaseConfig(path); err != nil {
return BaseConfig{}, fmt.Errorf("failed to create default base config: %w", err)
}
}
data, err := os.ReadFile(path)
if err != nil {
return BaseConfig{}, fmt.Errorf("failed to read file: %w", err)
return BaseConfig{}, fmt.Errorf("failed to read the config file: %w", err)
}
if err := json.Unmarshal(data, &config); err != nil {
return BaseConfig{}, fmt.Errorf("failed to unmarshal JSON: %w", err)
return config, fmt.Errorf("failed to unmarshal JSON: %w", err)
}
config.DeploymentType = deploymentType
return config, nil
}
// CreateDefaultBaseConfig creates a default base.json with retry_delay_seconds: 3
func CreateDefaultBaseConfig(path string) error {
defaultConfig := BaseConfig{
RetryDelaySenconds: 3,
}
data, err := json.MarshalIndent(defaultConfig, "", " ")
if err != nil {
return fmt.Errorf("failed to marshal default base config: %w", err)
}
if err := os.WriteFile(path, data, 0644); err != nil {
return fmt.Errorf("failed to write default base config to file: %w", err)
}
return nil
}
// LoadConfigs resolves config paths and loads both configs
func LoadConfigs() (BaseConfig, ProjectConfig, error) {
wd, err := os.Getwd()
if err != nil {
return BaseConfig{}, ProjectConfig{}, fmt.Errorf("failed to get current directory: %w", err)
}
var baseConfigPath string
if baseConfigFile == "" {
baseConfigPath = wd + string(os.PathSeparator) + "base.json"
} else {
baseConfigPath = baseConfigFile
}
var projectConfigPath string
if projectConfigFile == "" {
projectConfigPath = wd + string(os.PathSeparator) + "config.json"
} else {
projectConfigPath = projectConfigFile
}
baseConfig, err := ReadBaseConfig(baseConfigPath)
if err != nil {
return BaseConfig{}, ProjectConfig{}, fmt.Errorf("error reading base config file: %w", err)
}
projectConfig, err := ReadProjectConfig(projectConfigPath, &pipelineFile)
if err != nil {
return BaseConfig{}, ProjectConfig{}, fmt.Errorf("error reading project config file: %w", err)
}
return baseConfig, projectConfig, nil
}