Skip to content

Commit

Permalink
update to commit0
Browse files Browse the repository at this point in the history
  • Loading branch information
Pritesh-Patel committed Oct 9, 2019
1 parent 8564266 commit 9d493ce
Show file tree
Hide file tree
Showing 20 changed files with 79 additions and 440 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,3 +1,3 @@
main-packr.go
packrd
/sprout
commit0
9 changes: 3 additions & 6 deletions Dockerfile
Expand Up @@ -37,13 +37,10 @@ RUN mkdir -p /tmp/protoc && \

RUN GO111MODULE=off go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway

WORKDIR tmp/sprout
COPY go.mod .
COPY go.sum .
RUN go mod tidy && go mod download
WORKDIR tmp/commit0
COPY . .
RUN make build-deps && make build && \
mv sprout /usr/local/bin
mv commit0 /usr/local/bin
RUN upx --lzma /usr/local/bin/*

FROM alpine:edge
Expand All @@ -60,4 +57,4 @@ COPY --from=builder /go/src/github.com/grpc-ecosystem/grpc-gateway ${GOPATH}/src
WORKDIR /project
RUN apk add --update --no-cache make protobuf=${PROTOBUF_VERSION}-${ALPINE_PROTOBUF_VERSION_SUFFIX} && \
rm -rf /var/cache/apk/*
ENTRYPOINT ["sprout"]
ENTRYPOINT ["commit0"]
14 changes: 7 additions & 7 deletions Makefile
Expand Up @@ -37,25 +37,25 @@ run:
go run main.go

build:
CGO_ENABLED=0 packr2 build -o sprout
CGO_ENABLED=0 packr2 build -o commit0
packr2 clean

build-example: build clean-example
mkdir -p example
cd example && ../sprout create "hello-world"
cd example/hello-world && ../../sprout generate -l go
cd example && ../commit0 create "hello-world"
cd example/hello-world && ../../commit0 generate -l go

build-example-docker: clean-example
mkdir -p example
docker run -v "$(shell pwd)/example:/project" --user $(shell id -u):$(shell id -g) sprout:v0 create "hello-world"
docker run -v "$(shell pwd)/example/hello-world:/project" --user $(shell id -u):$(shell id -g) sprout:v0 generate -l go
docker run -v "$(shell pwd)/example:/project" --user $(shell id -u):$(shell id -g) commit0:v0 create "hello-world"
docker run -v "$(shell pwd)/example/hello-world:/project" --user $(shell id -u):$(shell id -g) commit0:v0 generate -l go

build-docker-local:
docker build . -t sprout:v0
docker build . -t commit0:v0

clean-example:
rm -rf example

install-go:
CGO_ENABLED=0 packr2 build -o ${GOPATH}/bin/sprout
CGO_ENABLED=0 packr2 build -o ${GOPATH}/bin/commit0
packr2 clean
14 changes: 7 additions & 7 deletions README.md
@@ -1,8 +1,8 @@
# Sprout [POC]
# Commit0 [POC]

Status: currently poc

Sprout intends to be a multi-language service generator. The intention is to create a modular monolith, which is easy to seperate at a later stage when the boundries are completely understood.
Commit0 intends to be a multi-language service generator. The intention is to create a modular monolith, which is easy to seperate at a later stage when the boundries are completely understood.

Based on specified config it will generate:
* Proto files [Done]
Expand All @@ -25,20 +25,20 @@ The generation will create project folder, within this there will be your implem

## The development cycle

1) To create a project run `sprout create [PROJECT_NAME]`
2) A folder will be created and within that update the `sprout.yml` and then run `sprout generate -l=[LANGUAGE OF CHOICE] eg. go`
1) To create a project run `commit0 create [PROJECT_NAME]`
2) A folder will be created and within that update the `commit0.yml` and then run `commit0 generate -l=[LANGUAGE OF CHOICE] eg. go`
3) You will see that there is now an idl folder created.
4) Within the idl folder modify the the protobuf services generated with your desired methods
5) Go up to the parrent directory and re run `sprout generate -l=[LANGUAGE OF CHOICE]`
5) Go up to the parrent directory and re run `commit0 generate -l=[LANGUAGE OF CHOICE]`
6) Return back to the parent directory and implement the methods
7) Once you have tested your implementation and are happy with it return to the idl repo push that directory up to git
8) Return to the parent directory and check the depency file, for go it will be the go.mod file remove the lines that point it to your local directory, this will now point it to the version on git that was pushed up previously
10) Test and push up your implementation!
9) When you feel the need to add more services add them to the sprout config and re-run `sprout generate` and repeat steps 4 - 7.
9) When you feel the need to add more services add them to the commit0 config and re-run `commit0 generate` and repeat steps 4 - 7.

## Usage & installation

As there alot of dependencies it will be easier to use this tool within the provided image, clone the repo and then run `make build-docker-local`. The best way then to use this is to alias `docker run -v "$(pwd):/project" --user $(id -u):$(id -g) sprout:v0` as sprout from then you can use the CLI as if it was installed as usual on your machine.
As there alot of dependencies it will be easier to use this tool within the provided image, clone the repo and then run `make build-docker-local`. The best way then to use this is to alias `docker run -v "$(pwd):/project" --user $(id -u):$(id -g) commit0:v0` as commit0 from then you can use the CLI as if it was installed as usual on your machine.

## Dependencies

Expand Down
6 changes: 3 additions & 3 deletions cmd/sprout.go → cmd/commit0.go
Expand Up @@ -2,16 +2,16 @@ package cmd

import (
"fmt"
"github.com/commitdev/sprout/templator"
"github.com/commitdev/commit0/templator"
"github.com/spf13/cobra"
"os"
)

var Templator *templator.Templator

var rootCmd = &cobra.Command{
Use: "sprout",
Short: "Sprout a moduler service generator.",
Use: "commit0",
Short: "Commit0 is a moduler service generator.",
Long: `TODO`,
Run: func(cmd *cobra.Command, args []string) {
},
Expand Down
10 changes: 5 additions & 5 deletions cmd/create.go
Expand Up @@ -34,18 +34,18 @@ var createCmd = &cobra.Command{
log.Fatalf("Error creating root: %v ", err)
}

sproutConfigPath := fmt.Sprintf("%v/sprout.yml", rootDir)
commit0ConfigPath := fmt.Sprintf("%v/commit0.yml", rootDir)

f, err := os.Create(sproutConfigPath)
f, err := os.Create(commit0ConfigPath)
if err != nil {
log.Printf("Error creating sprout config: %v", err)
log.Printf("Error creating commit0 config: %v", err)
}
Templator.Sprout.Execute(f, projectName)
Templator.Commit0.Execute(f, projectName)

gitIgnorePath := fmt.Sprintf("%v/.gitignore", rootDir)
f, err = os.Create(gitIgnorePath)
if err != nil {
log.Printf("Error creating sprout config: %v", err)
log.Printf("Error creating commit0 config: %v", err)
}
Templator.GitIgnore.Execute(f, projectName)
},
Expand Down
12 changes: 6 additions & 6 deletions cmd/generate.go
@@ -1,11 +1,11 @@
package cmd

import (
"github.com/commitdev/sprout/config"
"github.com/commitdev/sprout/generate/golang"
"github.com/commitdev/sprout/generate/proto"
"github.com/commitdev/sprout/generate/docker"
"github.com/commitdev/sprout/generate/http"
"github.com/commitdev/commit0/config"
"github.com/commitdev/commit0/generate/golang"
"github.com/commitdev/commit0/generate/proto"
"github.com/commitdev/commit0/generate/docker"
"github.com/commitdev/commit0/generate/http"


"log"
Expand All @@ -24,7 +24,7 @@ var supportedLanguages = [...]string{Go}

func init() {

generateCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "sprout.yml", "config path")
generateCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "commit0.yml", "config path")
generateCmd.PersistentFlags().StringVarP(&language, "language", "l", "", "language to generate project in")

rootCmd.AddCommand(generateCmd)
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Expand Up @@ -12,7 +12,7 @@ func init() {

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of sprout",
Short: "Print the version number of commit0",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("v0.0.1")
},
Expand Down
8 changes: 4 additions & 4 deletions config/config.go
Expand Up @@ -44,7 +44,7 @@ type Service struct {
Description string
}

type SproutConfig struct {
type Commit0Config struct {
Language string `yaml:"string"`
Organization string `yaml:"organization"`
Name string `yaml:"name"`
Expand All @@ -56,8 +56,8 @@ type SproutConfig struct {
Services []Service `yaml:"services"`
}

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

func (c *SproutConfig) Print() {
func (c *Commit0Config) Print() {
pp.Println(c)

}
Empty file removed example/hello-world/.dockerignore
Empty file.
1 change: 0 additions & 1 deletion example/hello-world/.gitignore
@@ -1 +0,0 @@
/hello-world-idl
File renamed without changes.
12 changes: 5 additions & 7 deletions generate/docker/generate.go
@@ -1,18 +1,16 @@
package docker

import (
"github.com/commitdev/sprout/util"
"github.com/commitdev/commit0/util"

"github.com/commitdev/sprout/config"
"github.com/commitdev/sprout/templator"
"github.com/commitdev/commit0/config"
"github.com/commitdev/commit0/templator"
)

func GenerateGoAppDockerFile(templator *templator.Templator, config *config.SproutConfig) {
func GenerateGoAppDockerFile(templator *templator.Templator, config *config.Commit0Config) {
util.TemplateFileIfDoesNotExist("docker/app", "Dockerfile", templator.Docker.ApplicationDocker, config)
util.TemplateFileIfDoesNotExist("./", ".dockerignore", templator.Docker.DockerIgnore, config)

}

func GenerateGoHttpGWDockerFile(templator *templator.Templator, config *config.SproutConfig) {
func GenerateGoHttpGWDockerFile(templator *templator.Templator, config *config.Commit0Config) {
util.TemplateFileIfDoesNotExist("docker/http", "Dockerfile", templator.Docker.HttpGatewayDocker, config)
}
16 changes: 8 additions & 8 deletions generate/golang/generate.go
Expand Up @@ -2,22 +2,22 @@ package golang

import (
"fmt"
"github.com/commitdev/sprout/util"
"github.com/commitdev/commit0/util"

"github.com/commitdev/sprout/config"
"github.com/commitdev/sprout/templator"
"github.com/commitdev/commit0/config"
"github.com/commitdev/commit0/templator"
"log"
"os"
)

func Generate(templator *templator.Templator, config *config.SproutConfig) {
func Generate(templator *templator.Templator, config *config.Commit0Config) {
GenerateGoMain(templator, config)
GenerateGoMod(templator, config)
GenerateHealthServer(templator, config)
GenerateServers(templator, config)
}

func GenerateGoMain(templator *templator.Templator, config *config.SproutConfig) {
func GenerateGoMain(templator *templator.Templator, config *config.Commit0Config) {
if _, err := os.Stat("main.go"); os.IsNotExist(err) {

f, err := os.Create("main.go")
Expand All @@ -32,7 +32,7 @@ func GenerateGoMain(templator *templator.Templator, config *config.SproutConfig)
}
}

func GenerateGoMod(templator *templator.Templator, config *config.SproutConfig) {
func GenerateGoMod(templator *templator.Templator, config *config.Commit0Config) {
f, err := os.Create("go.mod")

if err != nil {
Expand All @@ -42,7 +42,7 @@ func GenerateGoMod(templator *templator.Templator, config *config.SproutConfig)
templator.Go.GoMod.Execute(f, config)
}

func GenerateServers(templator *templator.Templator, config *config.SproutConfig) {
func GenerateServers(templator *templator.Templator, config *config.Commit0Config) {
serverDirPath := "server"
err := util.CreateDirIfDoesNotExist(serverDirPath)
if err != nil {
Expand Down Expand Up @@ -79,7 +79,7 @@ func GenerateServers(templator *templator.Templator, config *config.SproutConfig

}

func GenerateHealthServer(templator *templator.Templator, config *config.SproutConfig) {
func GenerateHealthServer(templator *templator.Templator, config *config.Commit0Config) {
serverDirPath := "server"
err := util.CreateDirIfDoesNotExist(serverDirPath)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions generate/http/generate.go
@@ -1,12 +1,12 @@
package http

import (
"github.com/commitdev/sprout/util"
"github.com/commitdev/commit0/util"

"github.com/commitdev/sprout/config"
"github.com/commitdev/sprout/templator"
"github.com/commitdev/commit0/config"
"github.com/commitdev/commit0/templator"
)

func GenerateHttpGW(templator *templator.Templator, config *config.SproutConfig) {
func GenerateHttpGW(templator *templator.Templator, config *config.Commit0Config) {
util.TemplateFileIfDoesNotExist("http", "main.go", templator.Go.GoHttpGW, config)
}
20 changes: 10 additions & 10 deletions generate/proto/generate.go
Expand Up @@ -4,23 +4,23 @@ import (
"bytes"
"fmt"

"github.com/commitdev/sprout/config"
"github.com/commitdev/sprout/templator"
"github.com/commitdev/sprout/util"
"github.com/commitdev/commit0/config"
"github.com/commitdev/commit0/templator"
"github.com/commitdev/commit0/util"
"log"
"os"
"os/exec"
)

func Generate(templator *templator.Templator, config *config.SproutConfig) {
func Generate(templator *templator.Templator, config *config.Commit0Config) {
GenerateIDLMakefile(templator, config)
GenerateProtoHealth(templator, config)
GenerateServiceProtobufFiles(templator, config)
GenerateProtoServiceLibs(config)
GenerateGoModIDL(templator, config)
}

func GenerateGoModIDL(templator *templator.Templator, config *config.SproutConfig) {
func GenerateGoModIDL(templator *templator.Templator, config *config.Commit0Config) {
idlPath := fmt.Sprintf("%s-idl", config.Name)
idlOutput := fmt.Sprintf("%s/go.mod", idlPath)
err := util.CreateDirIfDoesNotExist(idlPath)
Expand All @@ -33,7 +33,7 @@ func GenerateGoModIDL(templator *templator.Templator, config *config.SproutConfi
templator.Go.GoModIDL.Execute(f, config)
}

func GenerateIDLMakefile(templator *templator.Templator, config *config.SproutConfig) {
func GenerateIDLMakefile(templator *templator.Templator, config *config.Commit0Config) {
makeFilePath := fmt.Sprintf("%s-idl", config.Name)
makeFileOutput := fmt.Sprintf("%s/Makefile", makeFilePath)

Expand All @@ -49,7 +49,7 @@ func GenerateIDLMakefile(templator *templator.Templator, config *config.SproutCo
templator.MakefileTemplate.Execute(f, config)
}

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

Expand All @@ -66,7 +66,7 @@ func GenerateProtoHealth(templator *templator.Templator, config *config.SproutCo
templator.ProtoHealthTemplate.Execute(f, config)
}

func GenerateServiceProtobufFiles(templator *templator.Templator, cfg *config.SproutConfig) {
func GenerateServiceProtobufFiles(templator *templator.Templator, cfg *config.Commit0Config) {
protoPath := fmt.Sprintf("%s-idl/proto", cfg.Name)
for _, s := range cfg.Services {
serviceProtoDir := fmt.Sprintf("%s/%s", protoPath, s.Name)
Expand All @@ -81,7 +81,7 @@ func GenerateServiceProtobufFiles(templator *templator.Templator, cfg *config.Sp
f, err := os.Create(serviceProtoFilePath)

data := struct {
*config.SproutConfig
*config.Commit0Config
ServiceName string
}{
cfg,
Expand All @@ -93,7 +93,7 @@ func GenerateServiceProtobufFiles(templator *templator.Templator, cfg *config.Sp

}

func GenerateProtoServiceLibs(config *config.SproutConfig) {
func GenerateProtoServiceLibs(config *config.Commit0Config) {
idlRoot := fmt.Sprintf("%s-idl", config.Name)
cmd := exec.Command("make", "generate")
cmd.Dir = idlRoot
Expand Down

0 comments on commit 9d493ce

Please sign in to comment.