diff --git a/cmd/cmd_utils.go b/cmd/cmd_utils.go index ad4debf4f..a8db5f541 100644 --- a/cmd/cmd_utils.go +++ b/cmd/cmd_utils.go @@ -225,7 +225,7 @@ func executeCustomCommand( } if component == "" || component == "" { u.LogErrorAndExit(cliConfig, fmt.Errorf("the command defines an invalid 'component_config.component: %s' in '%s'", - commandConfig.ComponentConfig.Component, cfg.CliConfigFileName)) + commandConfig.ComponentConfig.Component, cfg.CliConfigFileName+cfg.DefaultStackConfigFileExtension)) } // Process Go templates in the command's 'component_config.stack' @@ -235,7 +235,7 @@ func executeCustomCommand( } if stack == "" || stack == "" { u.LogErrorAndExit(cliConfig, fmt.Errorf("the command defines an invalid 'component_config.stack: %s' in '%s'", - commandConfig.ComponentConfig.Stack, cfg.CliConfigFileName)) + commandConfig.ComponentConfig.Stack, cfg.CliConfigFileName+cfg.DefaultStackConfigFileExtension)) } // Get the config for the component in the stack diff --git a/internal/exec/vendor_utils.go b/internal/exec/vendor_utils.go index 0185e8b58..03f55bc6a 100644 --- a/internal/exec/vendor_utils.go +++ b/internal/exec/vendor_utils.go @@ -125,15 +125,10 @@ func ReadAndProcessVendorConfigFile(cliConfig schema.CliConfiguration, vendorCon var vendorConfig schema.AtmosVendorConfig vendorConfigFileExists := true - // If the vendoring manifest is specified without an extension, use the default extension - if filepath.Ext(vendorConfigFile) == "" { - vendorConfigFile = vendorConfigFile + cfg.DefaultVendoringManifestFileExtension - } - - foundVendorConfigFile := vendorConfigFile + // Check if the vendoring manifest file exists + foundVendorConfigFile, fileExists := u.SearchConfigFile(vendorConfigFile) - // Look for the vendoring manifest in the current directory - if !u.FileExists(vendorConfigFile) { + if !fileExists { // Look for the vendoring manifest in the directory pointed to by the `base_path` setting in the `atmos.yaml` pathToVendorConfig := path.Join(cliConfig.BasePath, vendorConfigFile) diff --git a/pkg/config/config.go b/pkg/config/config.go index 0a719d79b..63014bf4d 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -338,11 +338,12 @@ func processConfigFile( path string, v *viper.Viper, ) (bool, error) { - if !u.FileExists(path) { + // Check if the config file exists + configPath, fileExists := u.SearchConfigFile(path) + if !fileExists { return false, nil } - - reader, err := os.Open(path) + reader, err := os.Open(configPath) if err != nil { return false, err } @@ -350,7 +351,7 @@ func processConfigFile( defer func(reader *os.File) { err := reader.Close() if err != nil { - u.LogWarning(cliConfig, fmt.Sprintf("error closing file '"+path+"'. "+err.Error())) + u.LogWarning(cliConfig, fmt.Sprintf("error closing file '"+configPath+"'. "+err.Error())) } }(reader) diff --git a/pkg/config/const.go b/pkg/config/const.go index 530ce3192..720f53507 100644 --- a/pkg/config/const.go +++ b/pkg/config/const.go @@ -3,7 +3,7 @@ package config const ( DefaultStackConfigFileExtension = ".yaml" DefaultVendoringManifestFileExtension = ".yaml" - CliConfigFileName = "atmos.yaml" + CliConfigFileName = "atmos" SystemDirConfigFilePath = "/usr/local/etc/atmos" WindowsAppDataEnvVar = "LOCALAPPDATA" @@ -39,7 +39,7 @@ const ( HelpFlag2 = "--help" ComponentVendorConfigFileName = "component.yaml" - AtmosVendorConfigFileName = "vendor.yaml" + AtmosVendorConfigFileName = "vendor" ImportSectionName = "import" OverridesSectionName = "overrides" diff --git a/pkg/utils/file_utils.go b/pkg/utils/file_utils.go index 693ae10b7..5cf32bb66 100644 --- a/pkg/utils/file_utils.go +++ b/pkg/utils/file_utils.go @@ -173,3 +173,22 @@ func IsSocket(path string) (bool, error) { isSocket := fileInfo.Mode().Type() == fs.ModeSocket return isSocket, nil } + +// SearchConfigFile searches for a config file in the provided path. +// If the path has a file extension, it checks if the file exists. +// If the path does not have a file extension, it checks for the existence of the file with the provided path and the possible config file extensions +func SearchConfigFile(path string) (string, bool) { + // check if the provided has a file extension + if filepath.Ext(path) != "" { + return path, FileExists(path) + } + // Define the possible config file extensions + configExtensions := []string{".yaml", ".yml"} + for _, ext := range configExtensions { + filePath := path + ext + if FileExists(filePath) { + return filePath, true + } + } + return "", false +}