diff --git a/cmd/create.go b/cmd/create.go index 6b25fa4d3..7ca6eb848 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -9,6 +9,8 @@ import ( "github.com/commitdev/commit0/internal/templator" "github.com/commitdev/commit0/internal/util" "github.com/gobuffalo/packr/v2" + "github.com/kyokomi/emoji" + "github.com/logrusorgru/aurora" "github.com/spf13/cobra" ) @@ -18,13 +20,13 @@ func init() { func Create(projectName string, outDir string, t *templator.Templator) string { rootDir := path.Join(outDir, projectName) - log.Printf("Creating project %s.", projectName) + log.Println(aurora.Cyan(emoji.Sprintf(":tada: Creating project %s.", projectName))) err := os.MkdirAll(rootDir, os.ModePerm) if os.IsExist(err) { - log.Fatalf("Directory %v already exists! Error: %v", projectName, err) + log.Fatalln(aurora.Red(emoji.Sprintf(":exclamation: Directory %v already exists! Error: %v", projectName, err))) } else if err != nil { - log.Fatalf("Error creating root: %v ", err) + log.Fatalln(aurora.Red(emoji.Sprintf(":exclamation: Error creating root: %v ", err))) } var wg sync.WaitGroup @@ -40,7 +42,7 @@ var createCmd = &cobra.Command{ Short: "Create new project with provided name.", Run: func(cmd *cobra.Command, args []string) { if len(args) < 1 { - log.Fatalf("Project name cannot be empty!") + log.Fatalln(aurora.Red(emoji.Sprintf(":exclamation: Project name cannot be empty!"))) } templates := packr.New("templates", "../templates") diff --git a/cmd/generate.go b/cmd/generate.go index 88eeee73f..b42d7d1c2 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -5,21 +5,19 @@ import ( "sync" "github.com/commitdev/commit0/internal/config" - "github.com/commitdev/commit0/internal/generate/ci" - "github.com/commitdev/commit0/internal/generate/docker" "github.com/commitdev/commit0/internal/generate/golang" - "github.com/commitdev/commit0/internal/generate/http" "github.com/commitdev/commit0/internal/generate/kubernetes" "github.com/commitdev/commit0/internal/generate/proto" "github.com/commitdev/commit0/internal/generate/react" "github.com/commitdev/commit0/internal/templator" "github.com/commitdev/commit0/internal/util" "github.com/gobuffalo/packr/v2" + "github.com/kyokomi/emoji" + "github.com/logrusorgru/aurora" "github.com/spf13/cobra" ) var configPath string -var language string const ( Go = "go" @@ -32,7 +30,6 @@ var supportedLanguages = [...]string{Go, React, Kubernetes} func init() { generateCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "commit0.yml", "config path") - generateCmd.PersistentFlags().StringVarP(&language, "language", "l", "", "language to generate project in") rootCmd.AddCommand(generateCmd) } @@ -41,54 +38,60 @@ var generateCmd = &cobra.Command{ Use: "generate", Short: "Generate idl & application folders", Run: func(cmd *cobra.Command, args []string) { - if !ValidLanguage() { - log.Fatalf("'%s' is not a supported language.", language) - } templates := packr.New("templates", "../templates") t := templator.NewTemplator(templates) cfg := config.LoadConfig(configPath) - cfg.Language = language cfg.Print() var wg sync.WaitGroup - switch language { - case Go: - proto.Generate(t, cfg, &wg) - golang.Generate(t, cfg, &wg) + if !ValidLanguage(cfg.Frontend.Framework) { + log.Fatalln(aurora.Red(emoji.Sprintf(":exclamation: '%s' is not a supported framework.", cfg.Frontend.Framework))) + } - docker.GenerateGoAppDockerFile(t, cfg, &wg) - docker.GenerateGoDockerCompose(t, cfg, &wg) - case React: - react.Generate(t, cfg, &wg) - case Kubernetes: - kubernetes.Generate(t, cfg, &wg) + for _, s := range cfg.Services { + if !ValidLanguage(cfg.Frontend.Framework) { + log.Fatalln(aurora.Red(emoji.Sprintf(":exclamation: '%s' in service '%s' is not a supported language.", s.Name, s.Language))) + } } - util.TemplateFileIfDoesNotExist("", "README.md", t.Readme, &wg, cfg) + for _, s := range cfg.Services { + switch s.Language { + case Go: + log.Println(aurora.Cyan(emoji.Sprintf("Creating Go service"))) + proto.Generate(t, cfg, s, &wg) + golang.Generate(t, cfg, s, &wg) + } + } - if cfg.CI.System != "" { - ci.Generate(t.CI, cfg, ".", &wg) + if cfg.Infrastructure.AWS.EKS.ClusterName != "" { + log.Println(aurora.Cyan(emoji.Sprintf("Generating Terraform"))) + kubernetes.Generate(t, cfg, &wg) } - if cfg.Network.Http.Enabled { - http.GenerateHTTPGW(t, cfg, &wg) - docker.GenerateGoHTTPGWDockerFile(t, cfg, &wg) + // @TODO : This strucuture probably needs to be adjusted. Probably too generic. + switch cfg.Frontend.Framework { + case React: + log.Println(aurora.Cyan(emoji.Sprintf("Creating React frontend"))) + react.Generate(t, cfg, &wg) } + util.TemplateFileIfDoesNotExist("", "README.md", t.Readme, &wg, cfg) + // Wait for all the templates to be generated wg.Wait() - switch language { - case Kubernetes: + log.Println("Executing commands") + // @TODO : Move this stuff to another command? Or genericize it a bit. + if cfg.Infrastructure.AWS.EKS.Deploy { kubernetes.Execute(cfg) } }, } -func ValidLanguage() bool { +func ValidLanguage(language string) bool { for _, l := range supportedLanguages { if l == language { return true diff --git a/go.mod b/go.mod index 970b45521..944e097a7 100644 --- a/go.mod +++ b/go.mod @@ -7,23 +7,15 @@ require ( github.com/gobuffalo/packr/v2 v2.5.2 github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect github.com/k0kubun/pp v3.0.1+incompatible + github.com/kyokomi/emoji v2.1.0+incompatible + github.com/logrusorgru/aurora v0.0.0-20191017060258-dc85c304c434 github.com/mattn/go-colorable v0.1.2 // indirect - github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect - github.com/pelletier/go-toml v1.4.0 // indirect - github.com/pkg/errors v0.8.1 // indirect - github.com/prometheus/client_golang v1.1.0 // indirect - github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 // indirect - github.com/rogpeppe/fastuuid v1.2.0 // indirect github.com/rogpeppe/go-internal v1.5.0 // indirect - github.com/russross/blackfriday v2.0.0+incompatible // indirect - github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 // indirect - github.com/spf13/afero v1.2.2 // indirect github.com/spf13/cobra v0.0.5 github.com/stretchr/testify v1.4.0 // indirect golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect golang.org/x/sys v0.0.0-20191010194322-b09406accb47 // indirect - google.golang.org/grpc v1.24.0 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect - gopkg.in/yaml.v2 v2.2.4 + gopkg.in/yaml.v2 v2.2.5 ) diff --git a/go.sum b/go.sum index b8b14d805..086992613 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,5 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= -github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= -github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= @@ -15,10 +8,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= -github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gobuffalo/envy v1.7.0 h1:GlXgaiBkmrYMHco6t4j7SacKO4XUjvh5pwXh0f4uxXU= github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= github.com/gobuffalo/logger v1.0.0/go.mod h1:2zbswyIUa45I+c+FLXuWl9zSWEiVuthsk8ze5s8JvPs= @@ -28,29 +17,11 @@ github.com/gobuffalo/packd v0.3.0 h1:eMwymTkA1uXsqxS0Tpoop3Lc0u3kTfiMBE6nKtQU4g4 github.com/gobuffalo/packd v0.3.0/go.mod h1:zC7QkmNkYVGKPw4tHpBQ+ml7W/3tIebgeo1b36chA3Q= github.com/gobuffalo/packr/v2 v2.5.2 h1:4EvjeIpQLZuRIljwnidYgbRXbr1yIzVRrESiLjqKj6s= github.com/gobuffalo/packr/v2 v2.5.2/go.mod h1:sgEE1xNZ6G0FNN5xn9pevVu4nywaxHvgup67xisti08= -github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= -github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= -github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 h1:uC1QfSlInpQF+M0ao65imhwqKnz3Q2z/d8PWZRMQvDM= github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k= github.com/k0kubun/pp v3.0.1+incompatible h1:3tqvf7QgUnZ5tXO6pNAZlrvHgl6DvifjDrd9g2S9Z40= @@ -60,60 +31,33 @@ github.com/karrick/godirwalk v1.10.12/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0L github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kyokomi/emoji v2.1.0+incompatible h1:+DYU2RgpI6OHG4oQkM5KlqD3Wd3UPEsX8jamTo1Mp6o= +github.com/kyokomi/emoji v2.1.0+incompatible/go.mod h1:mZ6aGCD7yk8j6QY6KICwnZ2pxoszVseX1DNoGtU2tBA= +github.com/logrusorgru/aurora v0.0.0-20191017060258-dc85c304c434 h1:im9kkmH0WWwxzegiv18gSUJbuXR9y028rXrWuPp6Jug= +github.com/logrusorgru/aurora v0.0.0-20191017060258-dc85c304c434/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= -github.com/pelletier/go-toml v1.4.0/go.mod h1:PN7xzY2wHTK0K9p34ErDQMlFxa51Fk0OUruD3k1mMwo= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= -github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g= -github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc= -github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= -github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/rogpeppe/go-internal v1.3.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.5.0 h1:Usqs0/lDK/NqTkvrmKSwA/3XkZAs7ZAW/eLeQ2MVBTw= github.com/rogpeppe/go-internal v1.5.0/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= -github.com/russross/blackfriday v2.0.0+incompatible/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= -github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 h1:WN9BUFbdyOsSH/XohnWpXOlq9NBD5sGAB2FciQMUEe8= -github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= -github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s= github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= @@ -129,58 +73,35 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392 h1:ACG4HJsFiNMf47Y4PeRoebLNy/2lXT9EtprMuTFWt1M= -golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190515120540-06a5c4944438/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191010194322-b09406accb47 h1:/XfQ9z7ib8eEJX2hdgFTZJ/ntt0swNk5oYBziWeTCvY= golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0 h1:Dh6fw+p6FyRl5x/FvNswO1ji0lIGzm3KP8Y9VkS9PTE= golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/grpc v1.24.0 h1:vb/1TCsVn3DcJlQ0Gs1yB1pKI6Do2/QNwxdKqmc/b0s= -google.golang.org/grpc v1.24.0/go.mod h1:XDChyiUovWa60DnaeDeZmSW86xtLtjtZbwvSiRnRtcA= -gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c= +gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/internal/config/config.go b/internal/config/config.go index e67940652..6ae68273a 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -8,71 +8,80 @@ import ( "gopkg.in/yaml.v2" ) -type Maintainers struct { +type maintainers struct { Name string Email string } -type Grpc struct { +type grpc struct { Host string Port int } -type Graphql struct { +type graphql struct { Enabled bool Port int } -type Http struct { +type http struct { Enabled bool Port int } -type Web struct { +type web struct { Enabled bool Port int } -type Network struct { - Grpc Grpc - Http Http - Web Web - Graphql Graphql +type network struct { + Grpc grpc + Http http + Web web + Graphql graphql } type Service struct { Name string Description string + Language string + GitRepo string `yaml:"gitRepo"` + DockerRepo string `yaml:"dockerRepo"` + Network network + CI CI } type CI struct { - System string `yaml:"system"` - BuildImage string `yaml:"build-image"` - BuildCommand string `yaml:"build-command"` - TestCommand string `yaml:"test-command"` - LanguageVersion string `yaml:"language-version"` + System string + Language string + BuildImage string `yaml:"buildImage"` + BuildTag string `yaml:"buildTag"` + BuildCommand string `yaml:"buildCommand"` + TestCommand string `yaml:"testCommand"` } type Commit0Config struct { - Language string `yaml:"string"` - Organization string `yaml:"organization"` - Name string `yaml:"name"` - Description string `yaml:"description"` - GitRepo string `yaml:"git-repo"` - DockerRepo string `yaml:"docker-repo"` - Maintainers []Maintainers `yaml:"maintainers"` - Network Network `yaml:"network"` - Services []Service `yaml:"services"` - React React `yaml:"react"` - Kubernetes Kubernetes `yaml:"kubernetes"` - CI CI `yaml:"ci"` + Organization string + Name string + Description string + Maintainers []maintainers + Services []Service + Frontend frontend + Infrastructure infrastructure } -type Kubernetes struct { - ClusterName string `yaml:"clusterName"` - Deploy bool `yaml:"deploy"` - AWSAccountId string `yaml:"awsAccountId"` - AWSRegion string `yaml:"awsRegion"` +type infrastructure struct { + AWS aws +} + +type aws struct { + AccountId string `yaml:"accountId"` + Region string + EKS eks +} + +type eks struct { + ClusterName string `yaml:"clusterName"` + Deploy bool } func LoadConfig(filePath string) *Commit0Config { diff --git a/internal/config/react.go b/internal/config/react.go index 678c20ddd..7916afe8f 100644 --- a/internal/config/react.go +++ b/internal/config/react.go @@ -28,10 +28,12 @@ type reactView struct { Component string } -type React struct { - App reactApp - Account reactAccount - Header reactHeader - Sidenav reactSidenav - Views []reactView +type frontend struct { + Framework string + App reactApp + Account reactAccount + Header reactHeader + Sidenav reactSidenav + Views []reactView + CI CI } diff --git a/internal/generate/ci/generate.go b/internal/generate/ci/generate.go index 2860b8ab1..9a4fbd76c 100644 --- a/internal/generate/ci/generate.go +++ b/internal/generate/ci/generate.go @@ -19,7 +19,7 @@ const ( type CIGenerationError struct { err string - config *config.Commit0Config + config config.CI } func (e *CIGenerationError) Error() string { @@ -27,46 +27,34 @@ func (e *CIGenerationError) Error() string { } // Generate a CI configuration file based on your language and CI system -func Generate(templator *templator.CITemplator, config *config.Commit0Config, basePath string, wg *sync.WaitGroup) error { - switch config.Language { - case "go": - if config.CI.LanguageVersion == "" { - config.CI.LanguageVersion = defaultGoVersion - } - if config.CI.BuildImage == "" { - config.CI.BuildImage = fmt.Sprintf("%s:%s", defaultGoDockerImage, config.CI.LanguageVersion) - } - if config.CI.BuildCommand == "" { - config.CI.BuildCommand = defaultBuildCommand - } - if config.CI.TestCommand == "" { - config.CI.TestCommand = defaultTestCommand - } - default: - return &CIGenerationError{"Unsupported Language", config} - } +func Generate(t *templator.CITemplator, cfg *config.Commit0Config, ciConfig config.CI, basePath string, wg *sync.WaitGroup) error { var ciConfigPath string var ciFilename string var ciTemp *template.Template - switch config.CI.System { + switch ciConfig.System { case "jenkins": ciConfigPath = basePath ciFilename = "Jenkinsfile" - ciTemp = templator.Jenkins + ciTemp = t.Jenkins case "circleci": ciConfigPath = fmt.Sprintf("%s/%s", basePath, ".circleci/") ciFilename = "config.yml" - ciTemp = templator.CircleCI + ciTemp = t.CircleCI case "travisci": ciConfigPath = basePath ciFilename = ".travis.yml" - ciTemp = templator.TravisCI + ciTemp = t.TravisCI default: - return &CIGenerationError{"Unsupported CI System", config} + return &CIGenerationError{"Unsupported CI System", ciConfig} + } + + data := templator.CITemplateData{ + *cfg, + ciConfig, } - util.TemplateFileIfDoesNotExist(ciConfigPath, ciFilename, ciTemp, wg, config) + util.TemplateFileIfDoesNotExist(ciConfigPath, ciFilename, ciTemp, wg, data) return nil } diff --git a/internal/generate/ci/generate_test.go b/internal/generate/ci/generate_test.go index b5a62ae60..aacdeb9c4 100644 --- a/internal/generate/ci/generate_test.go +++ b/internal/generate/ci/generate_test.go @@ -10,73 +10,20 @@ import ( "github.com/commitdev/commit0/internal/templator" ) -func TestGenerateJenkins(t *testing.T) { - testConf := &config.Commit0Config{ - Language: "go", - CI: config.CI{ - System: "jenkins", - }, - } - testTemp := &templator.CITemplator{ - Jenkins: &template.Template{}, - CircleCI: &template.Template{}, - TravisCI: &template.Template{}, - } - var wg sync.WaitGroup - err := ci.Generate(testTemp, testConf, "/dev/null", &wg) - if err != nil { - t.Errorf("Error when executing test. %s", err) - } - - expectedBuildImage := "golang/golang:1.12" - actualBuildImage := testConf.CI.BuildImage - if actualBuildImage != expectedBuildImage { - t.Errorf("want: %s, got: %s", expectedBuildImage, actualBuildImage) - } - - expectedBuildCommand := "make build" - actualBuildCommand := testConf.CI.BuildCommand - if actualBuildCommand != expectedBuildCommand { - t.Errorf("want: %s, got: %s", expectedBuildCommand, actualBuildCommand) +func TestGenerateInvalidCISystem(t *testing.T) { + testConf := &config.Commit0Config{} + testCI := config.CI{ + System: "invalidCISystem", } - expectedTestCommand := "make test" - actualTestCommand := testConf.CI.TestCommand - if actualTestCommand != expectedTestCommand { - t.Errorf("want: %s, got: %s", expectedTestCommand, actualTestCommand) - } -} - -func TestGenerateInvalidLanguage(t *testing.T) { - testConf := &config.Commit0Config{ - Language: "invalidLanguage", - } testTemp := &templator.CITemplator{ Jenkins: &template.Template{}, CircleCI: &template.Template{}, TravisCI: &template.Template{}, } - var wg sync.WaitGroup - err := ci.Generate(testTemp, testConf, "/dev/null", &wg) - if err == nil { - t.Errorf("Error should be thrown with invalid language specified. %s", err.Error()) - } -} -func TestGenerateInvalidCISystem(t *testing.T) { - testConf := &config.Commit0Config{ - Language: "go", - CI: config.CI{ - System: "invalidCISystem", - }, - } - testTemp := &templator.CITemplator{ - Jenkins: &template.Template{}, - CircleCI: &template.Template{}, - TravisCI: &template.Template{}, - } var wg sync.WaitGroup - err := ci.Generate(testTemp, testConf, "/dev/null", &wg) + err := ci.Generate(testTemp, testConf, testCI, "/dev/null", &wg) if err == nil { t.Errorf("Error should be thrown with invalid ci system specified. %s", err.Error()) } diff --git a/internal/generate/docker/generate.go b/internal/generate/docker/generate.go index 932acc204..fc10df277 100644 --- a/internal/generate/docker/generate.go +++ b/internal/generate/docker/generate.go @@ -1,21 +1,23 @@ package docker import ( + "path/filepath" "sync" - "github.com/commitdev/commit0/internal/config" "github.com/commitdev/commit0/internal/templator" "github.com/commitdev/commit0/internal/util" ) -func GenerateGoAppDockerFile(templator *templator.Templator, config *config.Commit0Config, wg *sync.WaitGroup) { - util.TemplateFileIfDoesNotExist("docker/app", "Dockerfile", templator.Docker.ApplicationDocker, wg, config) +func GenerateGoAppDockerFile(templator *templator.Templator, data templator.GolangTemplateData, basePath string, wg *sync.WaitGroup) { + path := filepath.Join(basePath, "docker/app") + util.TemplateFileIfDoesNotExist(path, "Dockerfile", templator.Docker.ApplicationDocker, wg, data) } -func GenerateGoHTTPGWDockerFile(templator *templator.Templator, config *config.Commit0Config, wg *sync.WaitGroup) { - util.TemplateFileIfDoesNotExist("docker/http", "Dockerfile", templator.Docker.HttpGatewayDocker, wg, config) +func GenerateGoHTTPGWDockerFile(templator *templator.Templator, data templator.GolangTemplateData, basePath string, wg *sync.WaitGroup) { + path := filepath.Join(basePath, "docker/http") + util.TemplateFileIfDoesNotExist(path, "Dockerfile", templator.Docker.HttpGatewayDocker, wg, data) } -func GenerateGoDockerCompose(templator *templator.Templator, config *config.Commit0Config, wg *sync.WaitGroup) { - util.TemplateFileIfDoesNotExist("", "docker-compose.yml", templator.Docker.DockerCompose, wg, config) +func GenerateGoDockerCompose(templator *templator.Templator, data templator.GolangTemplateData, basePath string, wg *sync.WaitGroup) { + util.TemplateFileIfDoesNotExist(basePath, "docker-compose.yml", templator.Docker.DockerCompose, wg, data) } diff --git a/internal/generate/golang/generate.go b/internal/generate/golang/generate.go index 87ce8b8df..705744e17 100644 --- a/internal/generate/golang/generate.go +++ b/internal/generate/golang/generate.go @@ -2,40 +2,44 @@ package golang import ( "fmt" - "log" "path/filepath" "sync" "github.com/commitdev/commit0/internal/config" + "github.com/commitdev/commit0/internal/generate/ci" + "github.com/commitdev/commit0/internal/generate/docker" + "github.com/commitdev/commit0/internal/generate/http" "github.com/commitdev/commit0/internal/templator" "github.com/commitdev/commit0/internal/util" ) -func Generate(templator *templator.Templator, config *config.Commit0Config, wg *sync.WaitGroup) { - util.TemplateFileIfDoesNotExist("", "main.go", templator.Go.GoMain, wg, config) - util.TemplateFileIfDoesNotExist("", "go.mod", templator.Go.GoMod, wg, config) - util.TemplateFileIfDoesNotExist("server/health", "health.go", templator.Go.GoHealthServer, wg, config) - GenerateServers(templator, config, wg) -} +func Generate(t *templator.Templator, cfg *config.Commit0Config, service config.Service, wg *sync.WaitGroup) { + basePath := filepath.Join("service", service.Name) + healthPath := filepath.Join(basePath, "health") -func GenerateServers(templator *templator.Templator, config *config.Commit0Config, wg *sync.WaitGroup) { - serverDirPath := "server" - err := util.CreateDirIfDoesNotExist(serverDirPath) - if err != nil { - log.Printf("Error creating server path: %v", err) + data := templator.GolangTemplateData{ + *cfg, + service, } - for _, s := range config.Services { - path := filepath.Join("server", s.Name) - file := fmt.Sprintf("%s.go", s.Name) + util.TemplateFileIfDoesNotExist(basePath, "main.go", t.Go.GoMain, wg, data) + util.TemplateFileIfDoesNotExist(basePath, "go.mod", t.Go.GoMod, wg, data) + util.TemplateFileIfDoesNotExist(healthPath, "health.go", t.Go.GoHealthServer, wg, data) + + file := fmt.Sprintf("%s.go", service.Name) + + util.TemplateFileIfDoesNotExist(basePath, file, t.Go.GoServer, wg, data) + + if service.CI.System != "" { + ci.Generate(t.CI, cfg, service.CI, basePath, wg) + } - data := map[string]string{ - "ProjectName": config.Name, - "ServiceName": s.Name, - "GitRepo": config.GitRepo, - } + docker.GenerateGoAppDockerFile(t, data, basePath, wg) + docker.GenerateGoDockerCompose(t, data, basePath, wg) - util.TemplateFileIfDoesNotExist(path, file, templator.Go.GoServer, wg, data) + if service.Network.Http.Enabled { + http.GenerateGoHTTPGW(t, data, basePath, wg) + docker.GenerateGoHTTPGWDockerFile(t, data, basePath, wg) } } diff --git a/internal/generate/http/generate.go b/internal/generate/http/generate.go index 06afe36c4..593356d00 100644 --- a/internal/generate/http/generate.go +++ b/internal/generate/http/generate.go @@ -1,13 +1,14 @@ package http import ( + "path/filepath" "sync" - "github.com/commitdev/commit0/internal/config" "github.com/commitdev/commit0/internal/templator" "github.com/commitdev/commit0/internal/util" ) -func GenerateHTTPGW(templator *templator.Templator, config *config.Commit0Config, wg *sync.WaitGroup) { - util.TemplateFileAndOverwrite("http", "main.go", templator.Go.GoHTTPGW, wg, config) +func GenerateGoHTTPGW(templator *templator.Templator, data templator.GolangTemplateData, basePath string, wg *sync.WaitGroup) { + path := filepath.Join(basePath, "http") + util.TemplateFileAndOverwrite(path, "main.go", templator.Go.GoHTTPGW, wg, data) } diff --git a/internal/generate/kubernetes/generate.go b/internal/generate/kubernetes/generate.go index cbe2da50e..95918b5e9 100644 --- a/internal/generate/kubernetes/generate.go +++ b/internal/generate/kubernetes/generate.go @@ -18,7 +18,7 @@ func Generate(templator *templator.Templator, config *config.Commit0Config, wg * } func Execute(config *config.Commit0Config) { - if config.Kubernetes.Deploy { + if config.Infrastructure.AWS.EKS.Deploy { log.Println("Planning infrastructure...") execute(exec.Command("terraform", "init")) execute(exec.Command("terraform", "plan")) diff --git a/internal/generate/proto/generate.go b/internal/generate/proto/generate.go index 3eaaad8c5..76b0f49c9 100644 --- a/internal/generate/proto/generate.go +++ b/internal/generate/proto/generate.go @@ -5,45 +5,39 @@ import ( "fmt" "log" "os/exec" + "path/filepath" "sync" "github.com/commitdev/commit0/internal/config" "github.com/commitdev/commit0/internal/templator" "github.com/commitdev/commit0/internal/util" + + "github.com/kyokomi/emoji" + "github.com/logrusorgru/aurora" ) -func Generate(templator *templator.Templator, config *config.Commit0Config, wg *sync.WaitGroup) { - idlPath := fmt.Sprintf("%s-idl", config.Name) - idlHealthPath := fmt.Sprintf("%s/proto/health", idlPath) +func Generate(t *templator.Templator, cfg *config.Commit0Config, service config.Service, wg *sync.WaitGroup) { + idlPath := fmt.Sprintf("%s-idl", cfg.Name) + idlHealthPath := filepath.Join(idlPath, "proto", "health") - util.TemplateFileIfDoesNotExist(idlPath, "go.mod", templator.Go.GoModIDL, wg, config) - util.TemplateFileIfDoesNotExist(idlPath, "Makefile", templator.MakefileTemplate, wg, config) - GenerateServiceProtobufFiles(templator, config, wg) - util.TemplateFileIfDoesNotExist(idlHealthPath, "health.proto", templator.ProtoHealthTemplate, wg, config) + data := templator.GolangTemplateData{ + *cfg, + service, + } - GenerateProtoServiceLibs(config) -} + util.TemplateFileIfDoesNotExist(idlPath, "go.mod", t.Go.GoModIDL, wg, data) + util.TemplateFileIfDoesNotExist(idlPath, "Makefile", t.MakefileTemplate, wg, data) + util.TemplateFileIfDoesNotExist(idlHealthPath, "health.proto", t.ProtoHealthTemplate, wg, data) -func GenerateServiceProtobufFiles(templator *templator.Templator, cfg *config.Commit0Config, wg *sync.WaitGroup) { - protoPath := fmt.Sprintf("%s-idl/proto", cfg.Name) - for _, s := range cfg.Services { - serviceProtoDir := fmt.Sprintf("%s/%s", protoPath, s.Name) - file := fmt.Sprintf("%s.proto", s.Name) - - data := struct { - *config.Commit0Config - ServiceName string - }{ - cfg, - s.Name, - } - - util.TemplateFileIfDoesNotExist(serviceProtoDir, file, templator.ProtoServiceTemplate, wg, data) - } + serviceProtoDir := filepath.Join(idlPath, "proto", service.Name) + file := fmt.Sprintf("%s.proto", service.Name) + util.TemplateFileIfDoesNotExist(serviceProtoDir, file, t.ProtoServiceTemplate, wg, data) + + GenerateProtoServiceLibs(cfg) } -func GenerateProtoServiceLibs(config *config.Commit0Config) { - idlRoot := fmt.Sprintf("%s-idl", config.Name) +func GenerateProtoServiceLibs(cfg *config.Commit0Config) { + idlRoot := fmt.Sprintf("%s-idl", cfg.Name) cmd := exec.Command("make", "generate") cmd.Dir = idlRoot var out bytes.Buffer @@ -55,7 +49,7 @@ func GenerateProtoServiceLibs(config *config.Commit0Config) { log.Print("Generating proto service libs...") if err != nil { - log.Printf("Failed running command in: %v", cmd.Dir) - log.Printf("Error executing protoc generation: %v %v", err, stderr.String()) + log.Println(aurora.Red(emoji.Sprintf(":exclamation: Failed running command in: %v", cmd.Dir))) + log.Println(aurora.Red(emoji.Sprintf(":exclamation: Error executing protoc generation: %v %v", err, stderr.String()))) } } diff --git a/internal/generate/react/generate.go b/internal/generate/react/generate.go index 15dff478b..f891310d8 100644 --- a/internal/generate/react/generate.go +++ b/internal/generate/react/generate.go @@ -4,9 +4,13 @@ import ( "sync" "github.com/commitdev/commit0/internal/config" + "github.com/commitdev/commit0/internal/generate/ci" "github.com/commitdev/commit0/internal/templator" ) func Generate(templator *templator.Templator, config *config.Commit0Config, wg *sync.WaitGroup) { templator.React.TemplateFiles(config, false, wg) + if config.Frontend.CI.System != "" { + ci.Generate(templator.CI, config, config.Frontend.CI, "react/", wg) + } } diff --git a/internal/templator/template_data.go b/internal/templator/template_data.go new file mode 100644 index 000000000..321d567e8 --- /dev/null +++ b/internal/templator/template_data.go @@ -0,0 +1,15 @@ +package templator + +import "github.com/commitdev/commit0/internal/config" + +// GolangTemplateData holds data for use in golang related templates +type GolangTemplateData struct { + Config config.Commit0Config + Service config.Service +} + +// CITemplateData holds data for use in CI related templates +type CITemplateData struct { + Config config.Commit0Config + CI config.CI +} diff --git a/internal/util/util.go b/internal/util/util.go index dc4c887ec..f464bd818 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -8,6 +8,9 @@ import ( "strings" "sync" "text/template" + + "github.com/kyokomi/emoji" + "github.com/logrusorgru/aurora" ) func CreateDirIfDoesNotExist(path string) error { @@ -19,21 +22,22 @@ func CreateDirIfDoesNotExist(path string) error { } var FuncMap = template.FuncMap{ - "Title": strings.Title, + "Title": strings.Title, + "ToLower": strings.ToLower, } func createTemplatedFile(fullFilePath string, template *template.Template, wg *sync.WaitGroup, data interface{}) { f, err := os.Create(fullFilePath) if err != nil { - log.Printf("Error creating file: %v", err) + log.Println(aurora.Red(emoji.Sprintf(":exclamation: Error creating file '%s' : %v", fullFilePath, err))) } wg.Add(1) go func() { err = template.Execute(f, data) if err != nil { - log.Printf("Error templating: %v", err) + log.Println(aurora.Red(emoji.Sprintf(":exclamation: Error templating '%s': %v", fullFilePath, err))) } - log.Printf("Finished templating : %v", fullFilePath) + log.Println(aurora.Green(emoji.Sprintf(":white_check_mark: Finished templating : %v", fullFilePath))) wg.Done() }() } @@ -42,7 +46,7 @@ func TemplateFileAndOverwrite(fileDir string, fileName string, template *templat fullFilePath := fmt.Sprintf("%v/%v", fileDir, fileName) err := os.MkdirAll(fileDir, os.ModePerm) if err != nil { - log.Printf("Error creating directory %v: %v", fullFilePath, err) + log.Println(aurora.Red(emoji.Sprintf(":exclamation: Error creating directory %v: %v", fullFilePath, err))) } createTemplatedFile(fullFilePath, template, wg, data) @@ -55,11 +59,11 @@ func TemplateFileIfDoesNotExist(fileDir string, fileName string, template *templ if fileDir != "" { err := CreateDirIfDoesNotExist(fileDir) if err != nil { - log.Printf("Error creating directory %v: %v", fullFilePath, err) + log.Println(aurora.Red(emoji.Sprintf(":exclamation: Error creating directory %v: %v", fullFilePath, err))) } } createTemplatedFile(fullFilePath, template, wg, data) } else { - log.Printf("%v already exists. skipping.", fullFilePath) + log.Println(aurora.Yellow(emoji.Sprintf("%v already exists. skipping.", fullFilePath))) } } diff --git a/templates/ci/Jenkinsfile.tmpl b/templates/ci/Jenkinsfile.tmpl index 60bbeafc4..5ff66442f 100644 --- a/templates/ci/Jenkinsfile.tmpl +++ b/templates/ci/Jenkinsfile.tmpl @@ -6,7 +6,7 @@ pipeline { stage('Build') { agent { docker { - image '{{ .CI.BuildImage }}' + image '{{ .CI.BuildImage }}:{{ .CI.BuildTag }}' } } steps { @@ -16,7 +16,7 @@ pipeline { stage('Test') { agent { docker { - image '{{ .CI.BuildImage }}' + image '{{ .CI.BuildImage }}:{{ .CI.BuildTag }}' } } steps { @@ -26,4 +26,4 @@ pipeline { } } } -} \ No newline at end of file +} diff --git a/templates/ci/circleci.tmpl b/templates/ci/circleci.tmpl index 67b45f2f0..7ae9a0f5f 100644 --- a/templates/ci/circleci.tmpl +++ b/templates/ci/circleci.tmpl @@ -2,20 +2,20 @@ version: 2.1 jobs: build: docker: - - image: {{ .CI.BuildImage }} + - image: {{ .CI.BuildImage }}:{{ .CI.BuildTag }} steps: - checkout - - run: + - run: name: Build command: | {{ .CI.BuildCommand }} test: docker: - - image: {{ .CI.BuildImage }} + - image: {{ .CI.BuildImage }}:{{ .CI.BuildTag }} steps: - checkout - - run: + - run: name: Test command: | {{ .CI.TestCommand }} @@ -26,4 +26,4 @@ workflow: build_and_test: jobs: - build - - test \ No newline at end of file + - test diff --git a/templates/ci/travis.tmpl b/templates/ci/travis.tmpl index a00e80f16..a1f6e0242 100644 --- a/templates/ci/travis.tmpl +++ b/templates/ci/travis.tmpl @@ -1,7 +1,7 @@ -language: {{ .Language }} -{{ .Language }}: -- {{ .CI.LanguageVersion}} +language: {{ .CI.Language }} +{{ .CI.Language }}: +- {{ .CI.BuildTag}} scripts: - {{ .CI.BuildCommand }} -- {{ .CI.TestCommand }} \ No newline at end of file +- {{ .CI.TestCommand }} diff --git a/templates/commit0/commit0.tmpl b/templates/commit0/commit0.tmpl index 75eb297e8..e37db9432 100644 --- a/templates/commit0/commit0.tmpl +++ b/templates/commit0/commit0.tmpl @@ -1,30 +1,26 @@ organization: mycompany name: {{.}} description: -git-repo: github.com/yourrepo -docker-repo: maintainers: # - name: bob # email: bob@test.com -kubernetes: - clusterName: staging - deploy: true - awsAccountId: 1234 - awsRegion: us-east-1 +infrastructure: + aws: + accountId: 1234 + region: us-east-1 + eks: + clusterName: staging + deploy: true -network: - grpc: - host: 0.0.0.0 - port: 3000 - http: - enabled: true - port: 8080 - web: - enabled: true - port: 8090 - -react: +frontend: + framework: react + ci: + system: circleci + buildImage: react/react + buildTag: 1234 + buildCommand: make build + testCommand: make test app: name: {{.}} header: @@ -47,7 +43,26 @@ react: - path: / component: home -ci: - system: circleci services: + - name: User + description: User service + language: go + gitRepo: github.com/test/repo + dockerRepo: + ci: + system: circleci + buildImage: golang/golang + buildTag: 1.12 + buildCommand: make build + testCommand: make test + network: + grpc: + host: 0.0.0.0 + port: 3000 + http: + enabled: true + port: 8080 + web: + enabled: true + port: 8090 diff --git a/templates/docker/dockercompose.tmpl b/templates/docker/dockercompose.tmpl index 8f51f5d5c..febd7da5c 100644 --- a/templates/docker/dockercompose.tmpl +++ b/templates/docker/dockercompose.tmpl @@ -2,19 +2,19 @@ version: "3.7" services: app: - build: + build: context: . dockerfile: docker/app/Dockerfile ports: - - "{{ .Network.Grpc.Port }}:{{ .Network.Grpc.Port }}" - {{ if .Network.Http.Enabled }} + - "{{ .Service.Network.Grpc.Port }}:{{ .Service.Network.Grpc.Port }}" + {{ if .Service.Network.Http.Enabled }} http: build: context: . dockerfile: docker/http/Dockerfile environment: - APP_HOST=app - - APP_PORT={{ .Network.Grpc.Port }} + - APP_PORT={{ .Service.Network.Grpc.Port }} ports: - - "{{ .Network.Http.Port }}:{{ .Network.Http.Port }}" - {{- end}} \ No newline at end of file + - "{{ .Service.Network.Http.Port }}:{{ .Service.Network.Http.Port }}" + {{- end}} diff --git a/templates/docker/dockerfile_app.tmpl b/templates/docker/dockerfile_app.tmpl index 952d5baf7..fa223ed08 100644 --- a/templates/docker/dockerfile_app.tmpl +++ b/templates/docker/dockerfile_app.tmpl @@ -2,10 +2,10 @@ FROM golang:1.12.6@sha256:83e8267be041b3ddf6a5792c7e464528408f75c446745642db08cf WORKDIR /cache COPY go.mod . COPY . . -RUN go build -o {{ .Name }} +RUN go build -o {{ .Service.Name|ToLower }} FROM alpine RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 RUN apk update && apk add ca-certificates -COPY --from=build /cache/{{ .Name }} /app/ -ENTRYPOINT /app/{{ .Name }} +COPY --from=build /cache/{{ .Service.Name|ToLower }} /app/ +ENTRYPOINT /app/{{ .Service.Name|ToLower }} diff --git a/templates/docker/dockerfile_http.tmpl b/templates/docker/dockerfile_http.tmpl index cab46d53b..a0a90d288 100644 --- a/templates/docker/dockerfile_http.tmpl +++ b/templates/docker/dockerfile_http.tmpl @@ -1,10 +1,10 @@ FROM golang:1.12.6@sha256:83e8267be041b3ddf6a5792c7e464528408f75c446745642db08cfe4e8d58d18 AS build WORKDIR /cache COPY . . -RUN go build -o {{ .Name }}-http http/main.go +RUN go build -o {{ .Service.Name|ToLower }}-http http/main.go FROM alpine RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 RUN apk update && apk add ca-certificates -COPY --from=build /cache/{{ .Name }}-http /app/ -ENTRYPOINT /app/{{ .Name }}-http +COPY --from=build /cache/{{ .Service.Name|ToLower }}-http /app/ +ENTRYPOINT /app/{{ .Service.Name|ToLower }}-http diff --git a/templates/golang/go_mod.tmpl b/templates/golang/go_mod.tmpl index 6a1725817..79908e1b7 100644 --- a/templates/golang/go_mod.tmpl +++ b/templates/golang/go_mod.tmpl @@ -1,9 +1,9 @@ -module {{ .GitRepo }}/{{ .Name }} +module {{ .Service.GitRepo }}/{{ .Config.Name }} go 1.12 -replace {{ .GitRepo }}/{{ .Name }}-idl => ./{{ .Name }}-idl +replace {{ .Service.GitRepo }}/{{ .Config.Name }}-idl => ./{{ .Config.Name }}-idl require ( - {{ .GitRepo }}/{{ .Name }}-idl v0.0.0 + {{ .Service.GitRepo }}/{{ .Config.Name }}-idl v0.0.0 ) diff --git a/templates/golang/go_mod_idl.tmpl b/templates/golang/go_mod_idl.tmpl index 8deb4bca1..4f7016948 100644 --- a/templates/golang/go_mod_idl.tmpl +++ b/templates/golang/go_mod_idl.tmpl @@ -1,3 +1,3 @@ -module {{ .GitRepo }}/{{ .Name }}-idl +module {{ .Service.GitRepo }}/{{ .Config.Name }}-idl go 1.12 diff --git a/templates/golang/health_server.tmpl b/templates/golang/health_server.tmpl index ae9be2fe5..efb3cf416 100644 --- a/templates/golang/health_server.tmpl +++ b/templates/golang/health_server.tmpl @@ -2,7 +2,7 @@ package health import ( "context" - api "{{ .GitRepo }}/{{ .Name }}-idl/gen/go/health" + api "{{ .Service.GitRepo }}/{{ .Service.Name }}-idl/gen/go/health" ) type HealthServer struct { diff --git a/templates/golang/http_gw.tmpl b/templates/golang/http_gw.tmpl index 8a46461dc..0f3aa48ed 100644 --- a/templates/golang/http_gw.tmpl +++ b/templates/golang/http_gw.tmpl @@ -10,10 +10,7 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/runtime" "google.golang.org/grpc" - health "{{ $.GitRepo }}/{{ $.Name }}-idl/gen/go/health" - {{- range .Services}} - {{ .Name }} "{{ $.GitRepo }}/{{ $.Name }}-idl/gen/go/{{ .Name }}" - {{- end}} + health "{{ $.Service.GitRepo }}/{{ $.Config.Name }}-idl/gen/go/health" ) func run(endpoint string, listening string) error { @@ -25,9 +22,6 @@ func run(endpoint string, listening string) error { mux := runtime.NewServeMux() opts := []grpc.DialOption{grpc.WithInsecure()} err := health.RegisterHealthHandlerFromEndpoint(ctx, mux, endpoint, opts) - {{- range .Services}} - err = {{ .Name }}.Register{{ .Name | Title }}HandlerFromEndpoint(ctx, mux, endpoint, opts) - {{- end}} if err != nil { return err @@ -38,8 +32,8 @@ func run(endpoint string, listening string) error { func main() { - endpoint := fmt.Sprintf("%s:%s", getEnv("APP_HOST", "0.0.0.0"), getEnv("APP_PORT", "{{ .Network.Grpc.Port }}")) - listening := fmt.Sprintf("%s:%s", getEnv("HTTP_HOST", "0.0.0.0"), getEnv("HTTP_PORT", "{{ .Network.Http.Port }}")) + endpoint := fmt.Sprintf("%s:%s", getEnv("APP_HOST", "0.0.0.0"), getEnv("APP_PORT", "{{ .Service.Network.Grpc.Port }}")) + listening := fmt.Sprintf("%s:%s", getEnv("HTTP_HOST", "0.0.0.0"), getEnv("HTTP_PORT", "{{ .Service.Network.Http.Port }}")) log.Printf("Starting http grpc gateway server on %v...", listening) diff --git a/templates/golang/main.tmpl b/templates/golang/main.tmpl index bf2156c31..60076eba8 100644 --- a/templates/golang/main.tmpl +++ b/templates/golang/main.tmpl @@ -3,21 +3,15 @@ import ( "log" "net" - healthpb "{{ .GitRepo }}/{{ .Name }}-idl/gen/go/health" - {{- range .Services}} - {{ .Name }}pb "{{ $.GitRepo }}/{{ $.Name }}-idl/gen/go/{{ .Name }}" - {{- end}} - - health "{{ .GitRepo }}/{{ .Name }}/server/health" - {{- range .Services}} - {{ .Name }} "{{ $.GitRepo }}/{{ $.Name }}/server/{{ .Name }}" - {{- end}} + healthpb "{{ .Service.GitRepo }}/{{ .Config.Name }}-idl/gen/go/health" + + health "{{ .Service.GitRepo }}/{{ .Config.Name }}/server/health" "google.golang.org/grpc" ) func main() { - grpcAddr := "{{ .Network.Grpc.Host }}:{{ .Network.Grpc.Port }}" + grpcAddr := "{{ .Service.Network.Grpc.Host }}:{{ .Service.Network.Grpc.Port }}" lis, err := net.Listen("tcp", grpcAddr) if err != nil { log.Fatalf("failed to listen: %v", err) @@ -28,14 +22,12 @@ func main() { //Server initialization & registration healthServer := health.NewHealthServer() healthpb.RegisterHealthServer(s, healthServer) - {{- range .Services}} - {{ .Name }}Server := {{ .Name }}.New{{ .Name | Title}}Server() - {{ .Name }}pb.Register{{ .Name | Title}}Server(s, {{ .Name }}Server) - {{- end}} + {{ .Config.Name }}Server := {{ .Config.Name }}.New{{ .Config.Name | Title}}Server() + {{ .Config.Name }}pb.Register{{ .Config.Name | Title}}Server(s, {{ .Config.Name }}Server) log.Printf("Starting grpc server on %v...", grpcAddr) - + if err := s.Serve(lis); err != nil { log.Fatalf("failed to serve: %v", err) } diff --git a/templates/golang/server.tmpl b/templates/golang/server.tmpl index b0f2acbd4..05e74fae0 100644 --- a/templates/golang/server.tmpl +++ b/templates/golang/server.tmpl @@ -1,20 +1,20 @@ -package {{ .ServiceName }} +package {{ .Service.Name }} import ( "context" - health_api "{{.GitRepo}}/{{ .ProjectName }}-idl/gen/go/health" - //api "{{.GitRepo}}/{{ .ProjectName }}-idl/gen/go/{{ .ServiceName }}" + health_api "{{.Service.GitRepo}}/{{ .Config.Name }}-idl/gen/go/health" + //api "{{.Service.GitRepo}}/{{ .Config.Name }}-idl/gen/go/{{ .Service.Name }}" ) -type {{ .ServiceName | Title }}Server struct { +type {{ .Service.Name | Title }}Server struct { } -func New{{ .ServiceName | Title }}Server() *{{ .ServiceName | Title }}Server { - return &{{ .ServiceName | Title }}Server{} +func New{{ .Service.Name | Title }}Server() *{{ .Service.Name | Title }}Server { + return &{{ .Service.Name | Title }}Server{} } -func (s *{{ .ServiceName | Title }}Server) Check(ctx context.Context, req *health_api.HealthCheckRequest) (*health_api.HealthCheckResponse, error) { +func (s *{{ .Service.Name | Title }}Server) Check(ctx context.Context, req *health_api.HealthCheckRequest) (*health_api.HealthCheckResponse, error) { resp := &health_api.HealthCheckResponse{ Status: health_api.HealthCheckResponse_SERVING, } diff --git a/templates/kubernetes/terraform/environments/development/main.tf b/templates/kubernetes/terraform/environments/development/main.tf index 884dc6db8..e1fbec649 100644 --- a/templates/kubernetes/terraform/environments/development/main.tf +++ b/templates/kubernetes/terraform/environments/development/main.tf @@ -4,12 +4,12 @@ module "development" { environment = "development" # Project configuration - project = "{{ .Kubernetes.ClusterName }}" - region = "{{ .Kubernetes.AWSRegion }}" - allowed_account_ids = ["{{ .Kubernetes.AWSAccountId }}"] + project = "{{ .Infrastructure.AWS.EKS.ClusterName }}" + region = "{{ .Infrastructure.AWS.Region }}" + allowed_account_ids = ["{{ .Infrastructure.AWS.AccountId }}"] # ECR configuration - ecr_repositories = ["{{ .Kubernetes.ClusterName }}"] + ecr_repositories = ["{{ .Infrastructure.AWS.EKS.ClusterName }}"] # EKS configuration eks_worker_instance_type = "t2.small" diff --git a/templates/kubernetes/terraform/environments/production/main.tf b/templates/kubernetes/terraform/environments/production/main.tf index 03c03c285..dd2d76d3f 100644 --- a/templates/kubernetes/terraform/environments/production/main.tf +++ b/templates/kubernetes/terraform/environments/production/main.tf @@ -4,12 +4,12 @@ module "production" { environment = "production" # Project configuration - project = "{{ .Kubernetes.ClusterName }}" - region = "{{ .Kubernetes.AWSRegion }}" - allowed_account_ids = ["{{ .Kubernetes.AWSAccountId }}"] + project = "{{ .Infrastructure.AWS.EKS.ClusterName }}" + region = "{{ .Infrastructure.AWS.Region }}" + allowed_account_ids = ["{{ .Infrastructure.AWS.AccountId }}"] # ECR configuration - ecr_repositories = ["{{ .Kubernetes.ClusterName }}"] + ecr_repositories = ["{{ .Infrastructure.AWS.EKS.ClusterName }}"] # EKS configuration eks_worker_instance_type = "m4.large" diff --git a/templates/kubernetes/terraform/environments/staging/main.tf b/templates/kubernetes/terraform/environments/staging/main.tf index b94959a46..0c5e517e0 100644 --- a/templates/kubernetes/terraform/environments/staging/main.tf +++ b/templates/kubernetes/terraform/environments/staging/main.tf @@ -4,12 +4,12 @@ module "staging" { environment = "staging" # Project configuration - project = "{{ .Kubernetes.ClusterName }}" - region = "{{ .Kubernetes.AWSRegion }}" - allowed_account_ids = ["{{ .Kubernetes.AWSAccountId }}"] + project = "{{ .Infrastructure.AWS.EKS.ClusterName }}" + region = "{{ .Infrastructure.AWS.Region }}" + allowed_account_ids = ["{{ .Infrastructure.AWS.AccountId }}"] # ECR configuration - ecr_repositories = ["{{ .Kubernetes.ClusterName }}"] + ecr_repositories = ["{{ .Infrastructure.AWS.EKS.ClusterName }}"] # EKS configuration eks_worker_instance_type = "t2.small" diff --git a/templates/proto/health_proto.tmpl b/templates/proto/health_proto.tmpl index b5658e76b..e679b5768 100644 --- a/templates/proto/health_proto.tmpl +++ b/templates/proto/health_proto.tmpl @@ -1,10 +1,10 @@ syntax = "proto3"; -option go_package = "{{ .GitRepo }}/{{ .Name }}-idl/gen/go/health"; +option go_package = "{{ .Service.GitRepo }}/{{ .Config.Name }}-idl/gen/go/health"; package health; -{{- if .Network.Http.Enabled }} +{{- if .Service.Network.Http.Enabled }} import "google/api/annotations.proto"; import "protoc-gen-swagger/options/annotations.proto"; @@ -32,7 +32,7 @@ message HealthCheckResponse { service Health { rpc Check(HealthCheckRequest) returns (HealthCheckResponse){ - {{- if .Network.Http.Enabled }} + {{- if .Service.Network.Http.Enabled }} option (google.api.http) = { get: "/v1/health" }; diff --git a/templates/proto/makefile.tmpl b/templates/proto/makefile.tmpl index b8d6a5bc5..40fb49976 100644 --- a/templates/proto/makefile.tmpl +++ b/templates/proto/makefile.tmpl @@ -3,14 +3,14 @@ PROTOC_WEB_VERSION := 1.0.6 PROTO_SOURCES := -I /usr/local/include PROTO_SOURCES += -I . -{{- if .Network.Http.Enabled }} +{{- if .Service.Network.Http.Enabled }} PROTO_SOURCES += -I ${GOPATH}/src PROTO_SOURCES += -I ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis PROTO_SOURCES += -I ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway {{- end}} -{{- $language := .Language }} -{{- $http := .Network.Http.Enabled }} +{{- $language := .Service.Language }} +{{- $http := .Service.Network.Http.Enabled }} deps-linux: deps-protoc-linux deps-grpc-web-linux deps-go @@ -31,36 +31,36 @@ deps-go: go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger go get -u github.com/golang/protobuf/protoc-gen-go -generate: generate-grpc {{ if .Network.Web.Enabled }}generate-web{{- end}} {{ if .Network.Http.Enabled }}generate-http{{- end}} +generate: generate-grpc {{ if .Service.Network.Web.Enabled }}generate-web{{- end}} {{ if .Service.Network.Http.Enabled }}generate-http{{- end}} -generate-grpc: +generate-grpc: mkdir -p gen/{{ $language }} protoc ${PROTO_SOURCES} --{{ $language }}_out=plugins=grpc,paths=source_relative:proto ./proto/health/*.proto -{{- range .Services}} + {{- range .Config.Services}} protoc ${PROTO_SOURCES} --{{ $language }}_out=plugins=grpc,paths=source_relative:proto ./proto/{{ .Name }}/*.proto -{{- end }} + {{- end }} cp -f -rv proto/proto/* gen/go rm -rf proto/proto -{{- if .Network.Web.Enabled }} +{{- if .Service.Network.Web.Enabled }} generate-web: mkdir -p gen/web protoc ${PROTO_SOURCES} --grpc-web_out=import_style=typescript,mode=grpcwebtext:proto ./proto/health/*.proto -{{- range .Services}} + {{- range .Config.Services}} protoc ${PROTO_SOURCES} --grpc-web_out=import_style=typescript,mode=grpcwebtext:proto ./proto/{{ .Name }}/*.proto -{{- end }} + {{- end }} cp -f -rv proto/proto/* gen/web cp -f -rv proto/Proto/* gen/web rm -rf proto/proto proto/Proto {{- end}} -{{- if .Network.Http.Enabled }} +{{- if .Service.Network.Http.Enabled }} generate-http: mkdir -p gen/go protoc ${PROTO_SOURCES} --grpc-gateway_out=logtostderr=true,paths=source_relative:proto --swagger_out=logtostderr=true:proto ./proto/health/*.proto -{{- range .Services}} + {{- range .Config.Services}} protoc ${PROTO_SOURCES} --grpc-gateway_out=logtostderr=true,paths=source_relative:proto --swagger_out=logtostderr=true:proto ./proto/{{ .Name }}/*.proto -{{- end }} + {{- end }} cp -f -rv proto/proto/* gen/go rm -rf proto/proto {{- end}} diff --git a/templates/proto/service_proto.tmpl b/templates/proto/service_proto.tmpl index 95300561c..ad1820354 100644 --- a/templates/proto/service_proto.tmpl +++ b/templates/proto/service_proto.tmpl @@ -1,28 +1,28 @@ syntax = "proto3"; -option go_package = "{{ .GitRepo }}/{{ .Name }}-idl/gen/go/{{ .ServiceName }}"; +option go_package = "{{ .Service.GitRepo }}/{{ .Config.Name }}-idl/gen/go/{{ .Service.Name }}"; -package {{ .ServiceName }}; +package {{ .Service.Name }}; import "proto/health/health.proto"; -{{- if .Network.Http.Enabled}} +{{- if .Service.Network.Http.Enabled}} import "google/api/annotations.proto"; import "protoc-gen-swagger/options/annotations.proto"; option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = { info: { - title: "{{ .ServiceName | Title }}"; + title: "{{ .Service.Name | Title }}"; version: "1.0"; } }; {{- end}} -service {{ .ServiceName | Title }} { +service {{ .Service.Name | Title }} { rpc Check(health.HealthCheckRequest) returns (health.HealthCheckResponse){ - {{- if .Network.Http.Enabled }} + {{- if .Service.Network.Http.Enabled }} option (google.api.http) = { - get: "/v1/{{ .ServiceName }}/health" + get: "/v1/{{ .Service.Name }}/health" }; {{- end}} } diff --git a/templates/react/package.json.tmpl b/templates/react/package.json.tmpl index 82a05ebc9..a837942e1 100644 --- a/templates/react/package.json.tmpl +++ b/templates/react/package.json.tmpl @@ -1,5 +1,5 @@ { - "name": "{{ .React.App.Name }}", + "name": "{{ .Frontend.App.Name }}", "version": "0.1.0", "private": true, "dependencies": { diff --git a/templates/react/public/index.html.tmpl b/templates/react/public/index.html.tmpl index a1ce09791..ef430c4fd 100644 --- a/templates/react/public/index.html.tmpl +++ b/templates/react/public/index.html.tmpl @@ -25,7 +25,7 @@ work correctly both with client-side routing and a non-root public URL. Learn how to configure a non-root public URL by running `npm run build`. --> - {{ .React.App.Name }} + {{ .Frontend.App.Name }} diff --git a/templates/react/src/config/index.js.tmpl b/templates/react/src/config/index.js.tmpl index f493b7277..3241ff3b7 100644 --- a/templates/react/src/config/index.js.tmpl +++ b/templates/react/src/config/index.js.tmpl @@ -1,18 +1,18 @@ export default { app: { - name: '{{ .React.App.Name }}', + name: '{{ .Frontend.App.Name }}', }, account: { - enabled: {{ .React.Account.Enabled }}, - required: {{ .React.Account.Required }}, + enabled: {{ .Frontend.Account.Enabled }}, + required: {{ .Frontend.Account.Required }}, }, header: { - enabled: {{ .React.Header.Enabled }}, + enabled: {{ .Frontend.Header.Enabled }}, }, sidenav: { - enabled: {{ .React.Sidenav.Enabled }}, + enabled: {{ .Frontend.Sidenav.Enabled }}, items: [ - {{ range .React.Sidenav.Items }} + {{ range .Frontend.Sidenav.Items }} { path: '{{ .Path }}', label: '{{ .Label }}', @@ -22,7 +22,7 @@ export default { ] }, views: [ - {{ range .React.Views }} + {{ range .Frontend.Views }} { path: '{{ .Path }}', component: '{{ .Component }}', diff --git a/tests/integration/ci/ci_test.go b/tests/integration/ci/ci_test.go index e063de1bd..545cc5f94 100644 --- a/tests/integration/ci/ci_test.go +++ b/tests/integration/ci/ci_test.go @@ -33,14 +33,16 @@ func TestGenerateJenkins(t *testing.T) { var waitgroup sync.WaitGroup - testConf := &config.Commit0Config{ - Language: "go", - CI: config.CI{ - System: "jenkins", - }, + testConf := &config.Commit0Config{} + testCI := config.CI{ + System: "jenkins", + BuildImage: "golang/golang", + BuildTag: "1.12", + BuildCommand: "make build", + TestCommand: "make test", } - err := ci.Generate(testTemplator.CI, testConf, testData+"/actual", &waitgroup) + err := ci.Generate(testTemplator.CI, testConf, testCI, testData+"/actual", &waitgroup) if err != nil { t.Errorf("Error when executing test. %s", err) } @@ -69,14 +71,16 @@ func TestGenerateCircleCI(t *testing.T) { var waitgroup sync.WaitGroup - testConf := &config.Commit0Config{ - Language: "go", - CI: config.CI{ - System: "circleci", - }, + testConf := &config.Commit0Config{} + testCI := config.CI{ + System: "circleci", + BuildImage: "golang/golang", + BuildTag: "1.12", + BuildCommand: "make build", + TestCommand: "make test", } - err := ci.Generate(testTemplator.CI, testConf, testData+"/actual", &waitgroup) + err := ci.Generate(testTemplator.CI, testConf, testCI, testData+"/actual", &waitgroup) if err != nil { t.Errorf("Error when executing test. %s", err) } @@ -105,14 +109,16 @@ func TestGenerateTravisCI(t *testing.T) { var waitgroup sync.WaitGroup - testConf := &config.Commit0Config{ - Language: "go", - CI: config.CI{ - System: "travisci", - }, + testConf := &config.Commit0Config{} + testCI := config.CI{ + System: "travisci", + Language: "go", + BuildImage: "golang/golang", + BuildTag: "1.12", + BuildCommand: "make build", + TestCommand: "make test", } - - err := ci.Generate(testTemplator.CI, testConf, testData+"/actual", &waitgroup) + err := ci.Generate(testTemplator.CI, testConf, testCI, testData+"/actual", &waitgroup) if err != nil { t.Errorf("Error when executing test. %s", err) } diff --git a/tests/test_data/ci/expected/.circleci/config.yml b/tests/test_data/ci/expected/.circleci/config.yml index 6b928dd14..0ee506c1f 100644 --- a/tests/test_data/ci/expected/.circleci/config.yml +++ b/tests/test_data/ci/expected/.circleci/config.yml @@ -5,7 +5,7 @@ jobs: - image: golang/golang:1.12 steps: - checkout - - run: + - run: name: Build command: | make build @@ -15,7 +15,7 @@ jobs: - image: golang/golang:1.12 steps: - checkout - - run: + - run: name: Test command: | make test @@ -26,4 +26,4 @@ workflow: build_and_test: jobs: - build - - test \ No newline at end of file + - test diff --git a/tests/test_data/ci/expected/.travis.yml b/tests/test_data/ci/expected/.travis.yml index 352ea8297..92654dee0 100644 --- a/tests/test_data/ci/expected/.travis.yml +++ b/tests/test_data/ci/expected/.travis.yml @@ -4,4 +4,4 @@ go: scripts: - make build -- make test \ No newline at end of file +- make test diff --git a/tests/test_data/ci/expected/Jenkinsfile b/tests/test_data/ci/expected/Jenkinsfile index 1b815b99d..307f1c186 100644 --- a/tests/test_data/ci/expected/Jenkinsfile +++ b/tests/test_data/ci/expected/Jenkinsfile @@ -26,4 +26,4 @@ pipeline { } } } -} \ No newline at end of file +}