GeezerVison is showing github.com — move idl into project dir on generation · commitdev/zero@eba25fe
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +17Lines changed: 17 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +FROM golang:1.12.6@sha256:83e8267be041b3ddf6a5792c7e464528408f75c446745642db08cfe4e8d58d18 AS build | | 2 | +WORKDIR /cache | | 3 | +COPY go.mod . | | 4 | +COPY go.sum . | | 5 | +RUN go mod tidy && go mod download | | 6 | +COPY . . | | 7 | +RUN apt-get update && apt-get -y install sudo && apt-get -y install unzip | | 8 | +RUN make deps-linux && mv /go/bin/protoc-* /usr/local/bin/ | | 9 | +RUN make install-go && \ | | 10 | + mv /go/bin/sprout /usr/local/bin/ | | 11 | + | | 12 | + | | 13 | +FROM alpine | | 14 | +WORKDIR project | | 15 | +RUN apk add --update make | | 16 | +COPY --from=build /usr/local/bin /usr/local/bin | | 17 | +COPY --from=build /usr/local/include /usr/include |
Collapse file Copy file name to clipboardExpand all lines: Makefile +9-8Lines changed: 9 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -14,8 +14,8 @@ deps-linux: deps-go deps-protoc-linux deps-grpc-web-linux | 14 | 14 | deps-protoc-linux: | 15 | 15 | curl -OL https://github.com/google/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-linux-x86_64.zip | 16 | 16 | unzip protoc-$(PROTOC_VERSION)-linux-x86_64.zip -d protoc3 | 17 | | - sudo mv protoc3/bin/* /usr/local/bin/ | 18 | | - sudo mv protoc3/include/* /usr/local/include/ | | 17 | + sudo mv protoc3/bin/* /usr/local/bin | | 18 | + sudo mv protoc3/include/* /usr/local/include | 19 | 19 | rm -rf protoc3 protoc-$(PROTOC_VERSION)-linux-x86_64.zip | 20 | 20 |
| 21 | 21 | deps-grpc-web-linux: | | 36 | 36 | go run main.go | 37 | 37 |
| 38 | 38 | build: | 39 | | - packr2 build -o sprout | | 39 | + CGO_ENABLED=0 packr2 build -o sprout | 40 | 40 | packr2 clean | 41 | 41 |
| 42 | 42 | build-example: build clean-example | 43 | 43 | mkdir -p example | 44 | 44 | cd example && ../sprout create "hello-world" | 45 | 45 | cd example/hello-world && ../../sprout generate -l go | 46 | 46 |
| | 47 | +build-docker-local: | | 48 | + docker build . -t sprout:v0 | | 49 | + | 47 | 50 | clean-example: | 48 | 51 | rm -rf example | 49 | 52 |
| 50 | | -install-linux: build | 51 | | - mkdir -p ${HOME}/bin | 52 | | - cp sprout ${HOME}/bin/sprout | 53 | | - chmod +x ${HOME}/bin/sprout | 54 | | - @printf "\n Please run 'source ~/.profile' to add this installation to the path." | | 53 | +install-go: | | 54 | + CGO_ENABLED=0 packr2 build -o ${GOPATH}/bin/sprout | | 55 | + packr2 clean |
Collapse file Copy file name to clipboardExpand all lines: README.md +18-12Lines changed: 18 additions & 12 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -18,24 +18,30 @@ It will also live with your project, when you add a new service to the config it | 18 | 18 |
| 19 | 19 | ## What does it generate? | 20 | 20 |
| 21 | | -The generation will create 2 folders. | | 21 | +The generation will create project folder, within this there will be your implementation and an IDL folder | 22 | 22 |
| 23 | | -* A repo for the IDL's, this folder will also contain generated artifacts from the IDL under 'gen' | 24 | | -* A repo that implements the interfaces of the generated artifacts | | 23 | +* A parrent directory that implements a skeleton and sets up your service implementation of the generated artifacts | | 24 | +* A child directory for the IDL's, this folder will also contain generated artifacts from the IDL under 'gen' | 25 | 25 |
| 26 | | -`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.)` | | 26 | + | | 27 | +`NOTE: You` | 27 | 28 |
| 28 | 29 | ## The development cycle | 29 | 30 |
| 30 | | -1) Make folder with the name of your project and within that folder execute `sprout create [PROJECT_NAME]` | | 31 | +1) To create a project run `sprout create [PROJECT_NAME]` | 31 | 32 | 2) A folder will be created and within that update the `sprout.yml` and then run `sprout generate -l=[LANGUAGE OF CHOICE] eg. go` | 32 | | -3) Move back to the root folder and you will see that there is now an idl folder created. | 33 | | -4) Modify the the protobuf services generated with your desired methods | 34 | | -5) Either run `make generate` or return to the application folder and re run `sprout generate` | 35 | | -6) Push up the IDL repo | 36 | | -6) Implement these methods on the main application repo | 37 | | -7) Push up the IDL repo & remove the replace function in the go.mod in the implementation project (this will swap it over to using the live IDL pushed up to git instead of your local one) | 38 | | -8) 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. | | 33 | +3) You will see that there is now an idl folder created. | | 34 | +4) Within the idl folder modify the the protobuf services generated with your desired methods | | 35 | +5) Go up to the parrent directory and re run `sprout generate -l=[LANGUAGE OF CHOICE]` | | 36 | +6) Return back to the parent directory and implement the methods | | 37 | +7) Once you have tested your implementation and are happy with it return to the idl repo push that directory up to git | | 38 | +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 | | 39 | +10) Test and push up your implementation! | | 40 | +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. | | 41 | + | | 42 | +## Usage & installation | | 43 | + | | 44 | +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" sprout:local` as sprout from then you can use the CLI as if it was installed as usual on your machine. | 39 | 45 |
| 40 | 46 | ## Dependencies | 41 | 47 |
| |
Collapse file Copy file name to clipboardExpand all lines: cmd/create.go +16-2Lines changed: 16 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -24,6 +24,7 @@ var createCmd = &cobra.Command{ | 24 | 24 | projectName := args[0] | 25 | 25 |
| 26 | 26 | rootDir := fmt.Sprintf("./%v", projectName) | | 27 | + idlDir := fmt.Sprintf("./%v-idl", rootDir) | 27 | 28 |
| 28 | 29 | log.Printf("Creating project %s.", projectName) | 29 | 30 |
| @@ -34,13 +35,26 @@ var createCmd = &cobra.Command{ | 34 | 35 | log.Fatalf("Error creating root: %v ", err) | 35 | 36 | } | 36 | 37 |
| 37 | | - sproutConfigPath := fmt.Sprintf("%v/sprout.yml", projectName) | | 38 | + err = os.Mkdir(idlDir, os.ModePerm) | | 39 | + if os.IsExist(err) { | | 40 | + log.Fatalf("Directory %v already exists! Error: %v", projectName, err) | | 41 | + } else if err != nil { | | 42 | + log.Fatalf("Error creating root: %v ", err) | | 43 | + } | | 44 | + | | 45 | + sproutConfigPath := fmt.Sprintf("%v/sprout.yml", rootDir) | 38 | 46 |
| 39 | 47 | f, err := os.Create(sproutConfigPath) | 40 | 48 | if err != nil { | 41 | 49 | log.Printf("Error creating sprout config: %v", err) | 42 | 50 | } | 43 | | - | 44 | 51 | Templator.Sprout.Execute(f, projectName) | | 52 | + | | 53 | + gitIgnorePath := fmt.Sprintf("%v/.gitignore", rootDir) | | 54 | + f, err = os.Create(gitIgnorePath) | | 55 | + if err != nil { | | 56 | + log.Printf("Error creating sprout config: %v", err) | | 57 | + } | | 58 | + Templator.GitIgnore.Execute(f, projectName) | 45 | 59 | }, | 46 | 60 | } |
Collapse file Copy file name to clipboardExpand all lines: cmd/generate.go -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -39,7 +39,6 @@ var generateCmd = &cobra.Command{ | 39 | 39 | cfg.Print() | 40 | 40 |
| 41 | 41 | proto.Generate(Templator, cfg) | 42 | | - | 43 | 42 | switch language { | 44 | 43 | case Go: | 45 | 44 | golang.Generate(Templator, cfg) | |
Collapse file Copy file name to clipboard +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +/ |
Collapse file Copy file name to clipboardExpand all lines: example/hello-world/go.mod +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -2,7 +2,7 @@ module github.com/yourrepo/hello-world | 2 | 2 |
| 3 | 3 | go 1.12 | 4 | 4 |
| 5 | | -replace github.com/yourrepo/hello-world-idl => ../hello-world-idl | | 5 | +replace github.com/yourrepo/hello-world-idl => hello-world-idl | 6 | 6 |
| 7 | 7 | require ( | 8 | 8 | github.com/yourrepo/hello-world-idl v0.0.0 | |
Collapse file Copy file name to clipboard +3-17Lines changed: 3 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | PROTOC_VERSION := 3.9.2 | 2 | 2 | PROTOC_WEB_VERSION := 1.0.6 | 3 | | - | 4 | 3 | PROTO_SOURCES := -I /usr/local/include | 5 | 4 | PROTO_SOURCES += -I . | 6 | 5 | PROTO_SOURCES += -I ${GOPATH}/src | 7 | 6 | PROTO_SOURCES += -I ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis | 8 | | -PROTO_SOURCES += -I ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway | 9 | 7 |
| 10 | | -deps-linux: deps-protoc-linux deps-grpc-web-linux deps-go | | 8 | +deps-linux: deps-protoc-linux deps-grpc-web-linux | 11 | 9 |
| 12 | 10 | deps-protoc-linux: | 13 | 11 | curl -OL https://github.com/google/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-linux-x86_64.zip | @@ -21,14 +19,9 @@ deps-grpc-web-linux: | 21 | 19 | sudo mv protoc-gen-grpc-web-$(PROTOC_WEB_VERSION)-linux-x86_64 /usr/local/bin/protoc-gen-grpc-web | 22 | 20 | chmod +x /usr/local/bin/protoc-gen-grpc-web | 23 | 21 |
| 24 | | -deps-go: | 25 | | - go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway | 26 | | - go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger | 27 | | - go get -u github.com/golang/protobuf/protoc-gen-go | 28 | | - | 29 | | -generate: generate-grpc generate-web generate-http | | 22 | +generate: generate-grpc generate-web | 30 | 23 |
| 31 | | -generate-grpc: | | 24 | +generate-grpc: | 32 | 25 | mkdir -p gen/go | 33 | 26 | protoc ${PROTO_SOURCES} --go_out=plugins=grpc:./gen/go ./proto/health/*.proto | 34 | 27 | protoc ${PROTO_SOURCES} --go_out=plugins=grpc:./gen/go ./proto/helloworld/*.proto | @@ -40,11 +33,4 @@ generate-web: | 40 | 33 | protoc ${PROTO_SOURCES} --grpc-web_out=import_style=typescript,mode=grpcwebtext:gen/web ./proto/helloworld/*.proto | 41 | 34 | cp -f -rv gen/web/proto/* gen/web | 42 | 35 | rm -rf gen/web/Proto gen/web/proto | 43 | | -generate-http: | 44 | | - mkdir -p gen/http gen/swagger | 45 | | - protoc ${PROTO_SOURCES} --grpc-gateway_out=logtostderr=true:gen/http --swagger_out=logtostderr=true:gen/swagger ./proto/health/*.proto | 46 | | - protoc ${PROTO_SOURCES} --grpc-gateway_out=logtostderr=true:gen/http --swagger_out=logtostderr=true:gen/swagger ./proto/helloworld/*.proto | 47 | | - cp -f -rv gen/http/proto/* gen/http | 48 | | - cp -f -rv gen/swagger/proto/* gen/swagger | 49 | | - rm -rf gen/swagger/proto | 50 | 36 |
|
Collapse file Copy file name to clipboardExpand all lines: example/hello-world/hello-world-idl/gen/go/health/health.pb.go +16-24Lines changed: 16 additions & 24 deletions Collapse file Copy file name to clipboard File renamed without changes.
|