Skip to content

Commit

Permalink
fixup! fixup! zero create -> init
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcheung committed May 27, 2020
1 parent b7e8726 commit 945db22
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 34 deletions.
2 changes: 1 addition & 1 deletion configs/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package configs

const (
TemplatesDir = "tmp/templates"
CommitYml = "zero.yml"
CommitYml = "zero-project.yml"
IgnoredPaths = "(?i)zero.module.yml|.git/"
TemplateExtn = ".tmpl"
)
2 changes: 1 addition & 1 deletion internal/api/generate_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func generateProject(w http.ResponseWriter, req *http.Request) {
switch req.Method {
case "POST":
decoder := json.NewDecoder(req.Body)
var projectConfig config.Commit0Config
var projectConfig config.ZeroProjectConfig
err := decoder.Decode(&projectConfig)
if err != nil {
panic(err)
Expand Down
8 changes: 4 additions & 4 deletions internal/config/context_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
yaml "gopkg.in/yaml.v2"
)

type Commit0Config struct {
type ZeroProjectConfig struct {
Name string
Infrastructure Infrastructure // TODO simplify and flatten / rename?
Context map[string]string
Expand All @@ -29,8 +29,8 @@ type terraform struct {
RemoteState bool
}

func LoadConfig(filePath string) *Commit0Config {
config := &Commit0Config{}
func LoadConfig(filePath string) *ZeroProjectConfig {
config := &ZeroProjectConfig{}
data, err := ioutil.ReadFile(filePath)
if err != nil {
log.Panicf("failed to read config: %v", err)
Expand All @@ -43,6 +43,6 @@ func LoadConfig(filePath string) *Commit0Config {
return config
}

func (c *Commit0Config) Print() {
func (c *ZeroProjectConfig) Print() {
pp.Println(c)
}
12 changes: 4 additions & 8 deletions internal/config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"path"

"github.com/commitdev/zero/configs"
"github.com/commitdev/zero/pkg/util/exit"
)

Expand All @@ -27,21 +28,16 @@ modules:

var RootDir = "./"

const ConfigFileName = "zero.yml"

func SetRootDir(dir string) {
RootDir = dir
}

func Init(dir string, projectName string, projectContext *Commit0Config) {
if projectContext != nil {
fmt.Println("Context to put into zero.yml: \n-------------\n", projectContext.Context)
}
func Init(dir string, projectName string, projectContext *ZeroProjectConfig) {
// TODO: template the zero-project.yml with projectContext
content := []byte(fmt.Sprintf(exampleConfig, projectName))

err := ioutil.WriteFile(path.Join(dir, projectName, ConfigFileName), content, 0644)
err := ioutil.WriteFile(path.Join(dir, projectName, configs.CommitYml), content, 0644)
if err != nil {
exit.Fatal(fmt.Sprintf("Failed to create example %s", ConfigFileName))
exit.Fatal(fmt.Sprintf("Failed to create example %s", configs.CommitYml))
}
}
3 changes: 2 additions & 1 deletion internal/config/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"path"
"testing"

"github.com/commitdev/zero/configs"
"github.com/commitdev/zero/internal/config"
)

Expand All @@ -24,7 +25,7 @@ func TestInit(t *testing.T) {

config.Init(config.RootDir, projectName, nil)

if _, err := os.Stat(path.Join(testDirPath, config.ConfigFileName)); err != nil {
if _, err := os.Stat(path.Join(testDirPath, configs.CommitYml)); err != nil {
t.Fatal(err)
}
}
2 changes: 1 addition & 1 deletion internal/config/module_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Prompt struct {
Field string `yaml:"field,omitempty"`
Label string
Options []string `yaml:"options,omitempty"`
Execute string `yaml:"execute"`
Execute string `yaml:"execute,omitempty"`
}

type TemplateConfig struct {
Expand Down
18 changes: 8 additions & 10 deletions internal/context/init.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package context

import (
"fmt"
"log"
"os"
"path"
Expand All @@ -20,7 +19,7 @@ import (
)

// Create cloud provider context
func Init(projectName string, outDir string) *config.Commit0Config {
func Init(projectName string, outDir string) *config.ZeroProjectConfig {
rootDir := path.Join(outDir, projectName)
flog.Infof(":tada: Creating project %s.", projectName)

Expand Down Expand Up @@ -49,7 +48,7 @@ func Init(projectName string, outDir string) *config.Commit0Config {
return &projectConfig
}

func promptAllModules(projectConfig *config.Commit0Config) {
func promptAllModules(projectConfig *config.ZeroProjectConfig) {
// TODO: do we need to run through the modules and extract first
// or we need to run through twice
for _, moduleSource := range projectConfig.Modules {
Expand All @@ -62,7 +61,7 @@ func promptAllModules(projectConfig *config.Commit0Config) {
}
}

func promptProjectName(projectName string, projectConfig *config.Commit0Config) {
func promptProjectName(projectName string, projectConfig *config.ZeroProjectConfig) {
providerPrompt := promptui.Prompt{
Label: "Project Name",
Default: projectName,
Expand All @@ -71,7 +70,7 @@ func promptProjectName(projectName string, projectConfig *config.Commit0Config)
providerPrompt.Run()
}

func chooseCloudProvider(projectConfig *config.Commit0Config) {
func chooseCloudProvider(projectConfig *config.ZeroProjectConfig) {
// @TODO move options into configs
providerPrompt := promptui.Select{
Label: "Select Cloud Provider",
Expand All @@ -84,13 +83,12 @@ func chooseCloudProvider(projectConfig *config.Commit0Config) {
panic(err)
}

fmt.Println("providerResult", providerResult)
if providerResult != "Amazon AWS" {
exit.Fatal("Only the AWS provider is available at this time")
}
}

func chooseStack(projectConfig *config.Commit0Config) {
func chooseStack(projectConfig *config.ZeroProjectConfig) {
items := map[string][]string{
// TODO: better place to store these options as configuration file or any source
"EKS + Go + React": []string{
Expand Down Expand Up @@ -120,7 +118,7 @@ func chooseStack(projectConfig *config.Commit0Config) {
projectConfig.Modules = items[providerResult]
}

func fillProviderDetails(projectConfig *config.Commit0Config, s project.Secrets) {
func fillProviderDetails(projectConfig *config.ZeroProjectConfig, s project.Secrets) {
if projectConfig.Infrastructure.AWS != nil {
sess, err := session.NewSession(&aws.Config{
Region: aws.String(projectConfig.Infrastructure.AWS.Region),
Expand Down Expand Up @@ -148,8 +146,8 @@ func fillProviderDetails(projectConfig *config.Commit0Config, s project.Secrets)
}
}

func defaultProjConfig(projectName string) config.Commit0Config {
return config.Commit0Config{
func defaultProjConfig(projectName string) config.ZeroProjectConfig {
return config.ZeroProjectConfig{
Name: projectName,
Infrastructure: config.Infrastructure{
AWS: nil,
Expand Down
6 changes: 3 additions & 3 deletions internal/generate/generate_infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var amiLookup = map[string]string{
}

// GetOutputs captures the terraform output for the specific variables
func GetOutputs(cfg *config.Commit0Config, pathPrefix string, outputs []string) map[string]string {
func GetOutputs(cfg *config.ZeroProjectConfig, pathPrefix string, outputs []string) map[string]string {
outputsMap := make(map[string]string)
envars := credentials.MakeAwsEnvars(cfg, project.GetSecrets(util.GetCwd()))
pathPrefix = filepath.Join(pathPrefix, "environments/staging")
Expand All @@ -36,7 +36,7 @@ func GetOutputs(cfg *config.Commit0Config, pathPrefix string, outputs []string)
}

// Init sets up anything required by Execute
func Init(cfg *config.Commit0Config, pathPrefix string) {
func Init(cfg *config.ZeroProjectConfig, pathPrefix string) {
if cfg.Infrastructure.AWS.AccountID != "" {
flog.Infof("Preparing aws environment...")

Expand All @@ -56,7 +56,7 @@ func Init(cfg *config.Commit0Config, pathPrefix string) {
}

// Execute terrafrom init & plan. May modify the config passed in
func Execute(cfg *config.Commit0Config, pathPrefix string) {
func Execute(cfg *config.ZeroProjectConfig, pathPrefix string) {
if cfg.Infrastructure.AWS.AccountID != "" {
log.Println("Preparing aws environment...")

Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import "github.com/commitdev/zero/cmd"
import (
"github.com/commitdev/zero/cmd"
)

func main() {
cmd.Execute()
Expand Down
2 changes: 1 addition & 1 deletion pkg/credentials/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type AWS struct {
SecretAccessKey string
}

func MakeAwsEnvars(cfg *config.Commit0Config, awsSecrets Secrets) []string {
func MakeAwsEnvars(cfg *config.ZeroProjectConfig, awsSecrets Secrets) []string {
env := os.Environ()
env = append(env, fmt.Sprintf("AWS_ACCESS_KEY_ID=%s", awsSecrets.AWS.AccessKeyID))
env = append(env, fmt.Sprintf("AWS_SECRET_ACCESS_KEY=%s", awsSecrets.AWS.SecretAccessKey))
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/ci/ci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ package ci_test

// var waitgroup sync.WaitGroup

// testConf := &config.Commit0Config{}
// testConf := &config.ZeroProjectConfig{}
// testCI := config.CI{
// System: "jenkins",
// BuildImage: "golang/golang",
Expand Down Expand Up @@ -72,7 +72,7 @@ package ci_test

// var waitgroup sync.WaitGroup

// testConf := &config.Commit0Config{}
// testConf := &config.ZeroProjectConfig{}
// testCI := config.CI{
// System: "circleci",
// BuildImage: "golang/golang",
Expand Down Expand Up @@ -110,7 +110,7 @@ package ci_test

// var waitgroup sync.WaitGroup

// testConf := &config.Commit0Config{}
// testConf := &config.ZeroProjectConfig{}
// testCI := config.CI{
// System: "travisci",
// Language: "go",
Expand Down

0 comments on commit 945db22

Please sign in to comment.