Skip to content

Commit eba25fe

Browse files
committed
move idl into project dir on generation
1 parent d92dcae commit eba25fe

File tree

26 files changed

+197
-94
lines changed

26 files changed

+197
-94
lines changed

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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

Makefile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ deps-linux: deps-go deps-protoc-linux deps-grpc-web-linux
1414
deps-protoc-linux:
1515
curl -OL https://github.com/google/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-linux-x86_64.zip
1616
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
1919
rm -rf protoc3 protoc-$(PROTOC_VERSION)-linux-x86_64.zip
2020

2121
deps-grpc-web-linux:
@@ -36,19 +36,20 @@ run:
3636
go run main.go
3737

3838
build:
39-
packr2 build -o sprout
39+
CGO_ENABLED=0 packr2 build -o sprout
4040
packr2 clean
4141

4242
build-example: build clean-example
4343
mkdir -p example
4444
cd example && ../sprout create "hello-world"
4545
cd example/hello-world && ../../sprout generate -l go
4646

47+
build-docker-local:
48+
docker build . -t sprout:v0
49+
4750
clean-example:
4851
rm -rf example
4952

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

README.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,30 @@ It will also live with your project, when you add a new service to the config it
1818

1919
## What does it generate?
2020

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
2222

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'
2525

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`
2728

2829
## The development cycle
2930

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]`
3132
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.
3945

4046
## Dependencies
4147

cmd/create.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var createCmd = &cobra.Command{
2424
projectName := args[0]
2525

2626
rootDir := fmt.Sprintf("./%v", projectName)
27+
idlDir := fmt.Sprintf("./%v-idl", rootDir)
2728

2829
log.Printf("Creating project %s.", projectName)
2930

@@ -34,13 +35,26 @@ var createCmd = &cobra.Command{
3435
log.Fatalf("Error creating root: %v ", err)
3536
}
3637

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)
3846

3947
f, err := os.Create(sproutConfigPath)
4048
if err != nil {
4149
log.Printf("Error creating sprout config: %v", err)
4250
}
43-
4451
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)
4559
},
4660
}

cmd/generate.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ var generateCmd = &cobra.Command{
3939
cfg.Print()
4040

4141
proto.Generate(Templator, cfg)
42-
4342
switch language {
4443
case Go:
4544
golang.Generate(Templator, cfg)

example/hello-world/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/

example/hello-world/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/yourrepo/hello-world
22

33
go 1.12
44

5-
replace github.com/yourrepo/hello-world-idl => ../hello-world-idl
5+
replace github.com/yourrepo/hello-world-idl => hello-world-idl
66

77
require (
88
github.com/yourrepo/hello-world-idl v0.0.0
Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
PROTOC_VERSION := 3.9.2
22
PROTOC_WEB_VERSION := 1.0.6
3-
43
PROTO_SOURCES := -I /usr/local/include
54
PROTO_SOURCES += -I .
65
PROTO_SOURCES += -I ${GOPATH}/src
76
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
97

10-
deps-linux: deps-protoc-linux deps-grpc-web-linux deps-go
8+
deps-linux: deps-protoc-linux deps-grpc-web-linux
119

1210
deps-protoc-linux:
1311
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:
2119
sudo mv protoc-gen-grpc-web-$(PROTOC_WEB_VERSION)-linux-x86_64 /usr/local/bin/protoc-gen-grpc-web
2220
chmod +x /usr/local/bin/protoc-gen-grpc-web
2321

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
3023

31-
generate-grpc:
24+
generate-grpc:
3225
mkdir -p gen/go
3326
protoc ${PROTO_SOURCES} --go_out=plugins=grpc:./gen/go ./proto/health/*.proto
3427
protoc ${PROTO_SOURCES} --go_out=plugins=grpc:./gen/go ./proto/helloworld/*.proto
@@ -40,11 +33,4 @@ generate-web:
4033
protoc ${PROTO_SOURCES} --grpc-web_out=import_style=typescript,mode=grpcwebtext:gen/web ./proto/helloworld/*.proto
4134
cp -f -rv gen/web/proto/* gen/web
4235
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
5036

example/hello-world-idl/gen/go/health/health.pb.go renamed to example/hello-world/hello-world-idl/gen/go/health/health.pb.go

Lines changed: 16 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/hello-world-idl/gen/go/helloworld/helloworld.pb.go renamed to example/hello-world/hello-world-idl/gen/go/helloworld/helloworld.pb.go

File renamed without changes.

0 commit comments

Comments
 (0)