diff --git a/command/command.go b/command/command.go index f2e6347..88401f7 100644 --- a/command/command.go +++ b/command/command.go @@ -34,16 +34,17 @@ type GlobalArgs struct { // GlobalState contains common to all commands. type GlobalState struct { - GlobalArgs *GlobalArgs - Component string - Commit string - CodeDir string - Manifest *manifest.Manifest - InputStream io.Reader - OutputStream io.Writer - ErrorStream io.Writer - DockerClient docker.Iface - MonitoringClient *monitoring.DatadogClient + GlobalArgs *GlobalArgs + ConfigFilesFolder string + Component string + Commit string + CodeDir string + Manifest *manifest.Manifest + InputStream io.Reader + OutputStream io.Writer + ErrorStream io.Writer + DockerClient docker.Iface + MonitoringClient *monitoring.DatadogClient } // GetGlobalState collects info common to every command. @@ -78,6 +79,12 @@ func GetGlobalState(globalArgs *GlobalArgs, repoShouldExist bool) (*GlobalState, return nil, errors.New("cdflow.yaml version must be 2 for cdflow2") } + if state.Manifest.ConfigFilesFolder == "" { + state.ConfigFilesFolder = "config/" + } else { + state.ConfigFilesFolder = state.Manifest.ConfigFilesFolder + } + if globalArgs.Component == "" { state.Component, err = GetComponentFromGit() if err != nil { diff --git a/deploy/command.go b/deploy/command.go index 0c6bb12..ff1b338 100644 --- a/deploy/command.go +++ b/deploy/command.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "os" + "path" "strings" "github.com/mergermarket/cdflow2/command" @@ -152,12 +153,12 @@ func RunCommand(state *command.GlobalState, args *CommandArgs, env map[string]st "-var-file=/build/release-metadata.json", } - commonConfigFile := "config/common.json" + commonConfigFile := path.Join(state.ConfigFilesFolder, "common.json") if _, err := os.Stat(commonConfigFile); !os.IsNotExist(err) { planCommand = append(planCommand, "-var-file=../"+commonConfigFile) } - envConfigFilename := "config/" + args.EnvName + ".json" + envConfigFilename := path.Join(state.ConfigFilesFolder, args.EnvName+".json") if _, err := os.Stat(envConfigFilename); !os.IsNotExist(err) { planCommand = append(planCommand, "-var-file=../"+envConfigFilename) } diff --git a/destroy/command.go b/destroy/command.go index b4b61b2..1d21293 100644 --- a/destroy/command.go +++ b/destroy/command.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "os" + "path" "strings" "github.com/mergermarket/cdflow2/command" @@ -153,13 +154,13 @@ func RunCommand(state *command.GlobalState, args *CommandArgs, env map[string]st ) } - commonConfigFile := "config/common.json" + commonConfigFile := path.Join(state.ConfigFilesFolder, "common.json") if _, err := os.Stat(commonConfigFile); !os.IsNotExist(err) { planCommand = append(planCommand, "-var-file=../"+commonConfigFile) destroyCommand = append(destroyCommand, "-var-file=../"+commonConfigFile) } - envConfigFilename := "config/" + args.EnvName + ".json" + envConfigFilename := path.Join(state.ConfigFilesFolder, args.EnvName+".json") if _, err := os.Stat(envConfigFilename); !os.IsNotExist(err) { planCommand = append(planCommand, "-var-file=../"+envConfigFilename) destroyCommand = append(destroyCommand, "-var-file=../"+envConfigFilename) diff --git a/docs/src/cdflow-yaml-reference.md b/docs/src/cdflow-yaml-reference.md index 6330b7b..ed4dbe4 100644 --- a/docs/src/cdflow-yaml-reference.md +++ b/docs/src/cdflow-yaml-reference.md @@ -14,6 +14,9 @@ controlling how cdflow2 builds and deploys your code. # required - always "2" for cdflow2 version: 2 +# optional - default is set to "config/" +config_files_folder: "config/" + # required - descibed below config: image: mergermarket/cdflow2-config-aws-simple @@ -50,6 +53,13 @@ prevent you accidentally using the wrong version. For example: version: 2 ``` +### `config_files_folder` (optional) +Folder where the enviroment specific configuration files and common.json are stored. Default is `config/` + +```yaml +config_files_folder: "infra_config/" +``` + ### `config` (required) Config is used to select and configure the container that sets up the diff --git a/manifest/manifest.go b/manifest/manifest.go index 4705258..d3b2042 100644 --- a/manifest/manifest.go +++ b/manifest/manifest.go @@ -10,10 +10,11 @@ import ( // Manifest represents the data in the cdflow.yaml file before it is canonicalised. type Manifest struct { - Version int8 `yaml:"version"` - Config ImageWithParams `yaml:"config"` - Builds map[string]ImageWithParams `yaml:"builds"` - Terraform Terraform `yaml:"terraform"` + Version int8 `yaml:"version"` + ConfigFilesFolder string `yaml:"config_files_folder"` + Config ImageWithParams `yaml:"config"` + Builds map[string]ImageWithParams `yaml:"builds"` + Terraform Terraform `yaml:"terraform"` } // ImageWithParams represents either the config or a build key in cdflow.yaml.