infctl-cli/config/base.go
jon brookes 636a0494ac 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
2025-08-21 11:08:52 +01:00

77 lines
2.3 KiB
Go

package config
import (
"encoding/json"
"flag"
"fmt"
"os"
)
const Version = "v0.0.4"
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"`
}
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")
helpFlag := flag.Bool("help", false, "show help")
versionFlag := flag.Bool("version", false, "show version")
vFlag := flag.Bool("v", false, "show version (shorthand)")
flag.Parse()
if *helpFlag {
fmt.Println("Usage: infctl-cli --deployment-file=<path_to_config_file>")
fmt.Println("DEPLOYMENT_TYPE environment variable must be set to 'json' or 'api (api is not implemented yet)'")
os.Exit(0)
}
// Handle version flags
if *versionFlag || *vFlag {
fmt.Println("infctl-cli version:", Version)
os.Exit(0)
}
var config BaseConfig
if *deploymentFileShorthand != "" {
config.DeploymentFile = *deploymentFileShorthand
} else if *deploymentFile != "" {
config.DeploymentFile = *deploymentFile
}
data, err := os.ReadFile(path)
if err != nil {
return BaseConfig{}, fmt.Errorf("failed to read file: %w", err)
}
if err := json.Unmarshal(data, &config); err != nil {
return BaseConfig{}, fmt.Errorf("failed to unmarshal JSON: %w", err)
}
config.DeploymentType = deploymentType
return config, nil
}