Skip to content

Commit

Permalink
split into seperate repos
Browse files Browse the repository at this point in the history
  • Loading branch information
Pritesh-Patel committed Aug 22, 2019
1 parent 64c99a3 commit 00020e0
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 18 deletions.
18 changes: 18 additions & 0 deletions README.md
Expand Up @@ -16,6 +16,24 @@ Based on specified config it will generate:

It will also live with your project, when you add a new service to the config it will generate everything needed for that new service.

The generation will create a folder with 3 repos within it.

* A rep for the IDL's
* A repo that has the generated artifacts from the IDL
* A repo that implements the interfaces of the generated artifacts

NOTE: It only creates the folders for these repos, you will still need to create the git repos on your respected platform. Aswell as initialise each folder as a git repo and push when there have been changes. (if there is a strong desire we can look at how to make this process easier.)

The dev process:

1) Setup sprout config & run generation
2) Start adding your desired methods to the protobuf files generated
3) Rerun generation
4) Push the idl and the language generated repo
5) Implement these methods on the main application repo
6) When you feel the need to add more services add them to the sprout config
7) Repeat steps 1 - 5

## Dependencies

In order to use this you need ensure you have these installed.
Expand Down
7 changes: 7 additions & 0 deletions example/README.MD
@@ -0,0 +1,7 @@
# Example

You can find the generated repos from this example here:

* sprout-example
* sprout-example-idl
* sprout-example-go
File renamed without changes.
Expand Up @@ -11,12 +11,12 @@ create:

generate:
go_options:
import_path: github.com/commitdev/example/example
import_path: github.com/commitdev
extra_modifiers:
google/api/annotations.proto: google.golang.org/genproto/googleapis/api/annotations
google/api/http.proto: google.golang.org/genproto/googleapis/api/annotations
plugins:
- name: go
type: go
flags: plugins=grpc
output: ../../gen/go
output: ../../sprout-example-go
Expand Up @@ -2,7 +2,7 @@ package health

import (
"context"
api "github.com/commitdev/example/example/gen/go/health"
api "github.com/commitdev/sprout-example-go/health"
)

type HealthServer struct {
Expand Down
Expand Up @@ -2,7 +2,7 @@ package helloworld

import (
"context"
api "github.com/commitdev/example/example/gen/go/helloworld"
api "github.com/commitdev/sprout-example-go/helloworld"
)

type HelloworldServer struct {
Expand Down
4 changes: 2 additions & 2 deletions example/sprout.yml
@@ -1,7 +1,7 @@
organization: mycompany
name: example
name: sprout-example
description: This is a test project
git-repo: github.com/commitdev/example/example
git-repo: github.com/commitdev
docker-repo: test.com
maintainers:
- name: bob
Expand Down
9 changes: 4 additions & 5 deletions generate/golang/generate.go
Expand Up @@ -17,7 +17,7 @@ func Generate(templator *templator.Templator, config *config.SproutConfig, outPa
}

func GenerateServers(templator *templator.Templator, config *config.SproutConfig, outPath string) {
serverDirPath := fmt.Sprintf("%s/%s/server", outPath, config.Name)
serverDirPath := fmt.Sprintf("%s/%s/%s/server", outPath, config.Name, config.Name)
err := util.CreateDirIfDoesNotExist(serverDirPath)
if err != nil {
log.Printf("Error creating server path: %v", err)
Expand All @@ -43,6 +43,7 @@ func GenerateServers(templator *templator.Templator, config *config.SproutConfig
}

data := map[string]string {
"ProjectName": config.Name,
"ServiceName": s.Name,
"GitRepo": config.GitRepo,
}
Expand All @@ -53,7 +54,7 @@ func GenerateServers(templator *templator.Templator, config *config.SproutConfig
}

func GenerateHealthServer(templator *templator.Templator, config *config.SproutConfig, outPath string) {
serverDirPath := fmt.Sprintf("%s/%s/server", outPath, config.Name)
serverDirPath := fmt.Sprintf("%s/%s/%s/server", outPath, config.Name, config.Name)
err := util.CreateDirIfDoesNotExist(serverDirPath)
if err != nil {
log.Printf("Error creating server path: %v", err)
Expand All @@ -72,7 +73,5 @@ func GenerateHealthServer(templator *templator.Templator, config *config.SproutC
log.Printf("Error: %v", err)
}

importPath := fmt.Sprintf("%s/gen/go/health", config.GitRepo)

templator.Go.GoHealthServer.Execute(f, importPath)
templator.Go.GoHealthServer.Execute(f, config)
}
8 changes: 4 additions & 4 deletions generate/proto/generate.go
Expand Up @@ -19,7 +19,7 @@ func Generate(templator *templator.Templator, config *config.SproutConfig, outPa
}

func GenerateProtoToolConfig(templator *templator.Templator, config *config.SproutConfig, outPath string) {
protoPath := fmt.Sprintf("%s/%s/idl/proto", outPath, config.Name)
protoPath := fmt.Sprintf("%s/%s/%s-idl/proto", outPath, config.Name, config.Name)
protoToolOutput := fmt.Sprintf("%s/prototool.yaml", protoPath)

err := util.CreateDirIfDoesNotExist(protoPath)
Expand All @@ -35,7 +35,7 @@ func GenerateProtoToolConfig(templator *templator.Templator, config *config.Spro
}

func GenerateProtoHealth(templator *templator.Templator, config *config.SproutConfig, outPath string) {
protoHealthPath := fmt.Sprintf("%s/%s/idl/proto/health", outPath, config.Name)
protoHealthPath := fmt.Sprintf("%s/%s/%s-idl/proto/health", outPath, config.Name, config.Name)
protoHealthOutput := fmt.Sprintf("%s/health.proto", protoHealthPath)

err := util.CreateDirIfDoesNotExist(protoHealthPath)
Expand All @@ -52,7 +52,7 @@ func GenerateProtoHealth(templator *templator.Templator, config *config.SproutCo
}

func GenerateProtoServices(templator *templator.Templator, config *config.SproutConfig, outPath string) {
protoToolConfigPath := fmt.Sprintf("%s/%s/idl/proto", outPath, config.Name)
protoToolConfigPath := fmt.Sprintf("%s/%s/%s-idl/proto", outPath, config.Name, config.Name)
for _, s := range config.Services {
idlPath := fmt.Sprintf("%s/%s", protoToolConfigPath, s.Name)
err := util.CreateDirIfDoesNotExist(idlPath)
Expand All @@ -70,7 +70,7 @@ func GenerateProtoServices(templator *templator.Templator, config *config.Sprout
}

func GenerateProtoServiceLibs(config *config.SproutConfig, outPath string) {
protoToolConfigPath := fmt.Sprintf("%s/%s/idl/proto", outPath, config.Name)
protoToolConfigPath := fmt.Sprintf("%s/%s/%s-idl/proto", outPath, config.Name, config.Name)
cmd := exec.Command("prototool", "generate")
cmd.Dir = protoToolConfigPath
err := cmd.Run()
Expand Down
2 changes: 1 addition & 1 deletion templates/golang/health_server.tmpl
Expand Up @@ -2,7 +2,7 @@ package health

import (
"context"
api "{{ . }}"
api "{{ .GitRepo }}/{{ .Name }}-go/health"
)

type HealthServer struct {
Expand Down
2 changes: 1 addition & 1 deletion templates/golang/server.tmpl
Expand Up @@ -2,7 +2,7 @@ package {{ .ServiceName }}

import (
"context"
api "{{.GitRepo}}/gen/go/{{ .ServiceName }}"
api "{{.GitRepo}}/{{ .ProjectName }}-go/{{ .ServiceName }}"
)

type {{ .ServiceName | Title }}Server struct {
Expand Down
2 changes: 1 addition & 1 deletion templates/proto/prototool.tmpl
Expand Up @@ -22,4 +22,4 @@ generate:
- name: go
type: go
flags: plugins=grpc
output: ../../gen/go
output: ../../{{ .Name }}-go

0 comments on commit 00020e0

Please sign in to comment.