Skip to content

Commit

Permalink
make config/ configurable from cdflow.yaml (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
marciogoda authored Mar 8, 2024
1 parent a03f396 commit ad10020
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
27 changes: 17 additions & 10 deletions command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions deploy/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"os"
"path"
"strings"

"github.com/mergermarket/cdflow2/command"
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 3 additions & 2 deletions destroy/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"path"
"strings"

"github.com/mergermarket/cdflow2/command"
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions docs/src/cdflow-yaml-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ad10020

Please sign in to comment.