Skip to content

Commit eaed28e

Browse files
authored
Deprecate static templators (#92)
* proposal config syntax for package support * renamed config files * updated command * moved create command implementation into new context package * consolidated configs and cleaned up util logs * refactored to remove templators * generating example commit0.yml on create * updated reference docs
1 parent c104404 commit eaed28e

File tree

193 files changed

+1455
-23513
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

193 files changed

+1455
-23513
lines changed

.gitignore

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,4 @@ main-packr.go
22
packrd
33
/commit0
44
.history/
5-
tmp/
6-
7-
# Generated files from Config UI.
8-
intenral/ui/node_modules
9-
intenral/ui/build
5+
tmp

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
language: go
22

33
script:
4-
- GO111MODULE=on make build-deps
54
- GO111MODULE=on make build
65
- GO111MODULE=on make check
76

87
go:
9-
- 1.12.x
108
- 1.13.x

Dockerfile

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,13 @@
11
FROM golang:1.12.12-alpine3.10 as builder
22

33
ENV GO111MODULE=on
4-
ENV GOLANG_PROTOBUF_VERSION=1.3.1
5-
ENV GRPC_GATEWAY_VERSION=1.11.3
6-
ENV GRPC_WEB_VERSION=1.0.6
7-
ENV PROTOBUF_VERSION=3.6.1
84
ENV TERRAFORM_VERSION=0.12.13
9-
ENV K8S_VERSION=1.14.8
105

116
RUN apk add --update --no-cache build-base curl git upx && \
127
rm -rf /var/cache/apk/*
138

149
RUN apk add --update nodejs npm
1510

16-
RUN go get \
17-
github.com/golang/protobuf/protoc-gen-go@v${GOLANG_PROTOBUF_VERSION} &&\
18-
mv /go/bin/protoc-gen-go* /usr/local/bin/
19-
20-
RUN curl -sSL \
21-
https://github.com/grpc-ecosystem/grpc-gateway/releases/download/v${GRPC_GATEWAY_VERSION}/protoc-gen-grpc-gateway-v${GRPC_GATEWAY_VERSION}-linux-x86_64 \
22-
-o /usr/local/bin/protoc-gen-grpc-gateway && \
23-
curl -sSL \
24-
https://github.com/grpc-ecosystem/grpc-gateway/releases/download/v${GRPC_GATEWAY_VERSION}/protoc-gen-swagger-v${GRPC_GATEWAY_VERSION}-linux-x86_64 \
25-
-o /usr/local/bin/protoc-gen-swagger
26-
27-
RUN curl -sSL \
28-
https://github.com/grpc/grpc-web/releases/download/${GRPC_WEB_VERSION}/protoc-gen-grpc-web-${GRPC_WEB_VERSION}-linux-x86_64 \
29-
-o /usr/local/bin/protoc-gen-grpc-web
30-
31-
RUN mkdir -p /tmp/protoc && \
32-
curl -sSL \
33-
https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VERSION}/protoc-${PROTOBUF_VERSION}-linux-x86_64.zip \
34-
-o /tmp/protoc/protoc.zip && \
35-
cd /tmp/protoc && \
36-
unzip protoc.zip && \
37-
mv /tmp/protoc/include /usr/local/include
38-
3911
RUN curl -sSL \
4012
https://storage.googleapis.com/kubernetes-release/release/v${K8S_VERSION}/bin/linux/amd64/kubectl \
4113
-o /usr/local/bin/kubectl
@@ -72,6 +44,5 @@ COPY --from=builder /usr/local/bin /usr/local/bin
7244
COPY --from=builder /usr/local/include /usr/local/include
7345
COPY --from=builder /go/src/github.com/grpc-ecosystem/grpc-gateway ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway
7446
WORKDIR /project
75-
RUN apk add --update --no-cache make protobuf=${PROTOBUF_VERSION} && \
76-
rm -rf /var/cache/apk/*
47+
7748
ENTRYPOINT ["/usr/local/bin/commit0"]

Makefile

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,11 @@
1-
PROTOC_VERSION := 3.9.2
2-
PROTOC_WEB_VERSION := 1.0.6
3-
4-
PROTO_SOURCES := -I /usr/local/include
5-
PROTO_SOURCES += -I .
6-
PROTO_SOURCES += -I ${GOPATH}/src
7-
PROTO_SOURCES += -I ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway
8-
91
VERSION:= 0.0.1
102

11-
deps-linux: deps-go deps-protoc-linux deps-grpc-web-linux
12-
13-
deps-protoc-linux:
14-
curl -OL https://github.com/google/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-linux-x86_64.zip
15-
unzip protoc-$(PROTOC_VERSION)-linux-x86_64.zip -d protoc3
16-
mv protoc3/bin/protoc /usr/local/bin
17-
mv protoc3/include/* /usr/local/include
18-
rm -rf protoc3 protoc-$(PROTOC_VERSION)-linux-x86_64.zip
19-
20-
deps-grpc-web-linux:
21-
curl -OL https://github.com/grpc/grpc-web/releases/download/$(PROTOC_WEB_VERSION)/protoc-gen-grpc-web-$(PROTOC_WEB_VERSION)-linux-x86_64
22-
mv protoc-gen-grpc-web-$(PROTOC_WEB_VERSION)-linux-x86_64 /usr/local/bin/protoc-gen-grpc-web
23-
chmod +x /usr/local/bin/protoc-gen-grpc-web
24-
25-
deps-go:
26-
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
27-
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
28-
go get -u github.com/golang/protobuf/protoc-gen-go
29-
30-
build-deps:
31-
go install github.com/gobuffalo/packr/v2/packr2
32-
333
check:
344
go test ./...
355

366
fmt:
377
go fmt ./...
388

39-
build-example: build clean-example
40-
mkdir -p example
41-
cd example && ../commit0 create "hello-world"
42-
cd example/hello-world && ../../commit0 generate -l go
43-
449
build-docker-local:
4510
docker build . -t commit0:v0
4611

@@ -49,19 +14,9 @@ build-example-docker: clean-example
4914
docker run -v "$(shell pwd)/example:/project" --user $(shell id -u):$(shell id -g) commit0:v0 create "hello-world"
5015
docker run -v "$(shell pwd)/example/hello-world:/project" --user $(shell id -u):$(shell id -g) commit0:v0 generate -l go
5116

52-
clean-example:
53-
rm -rf example
54-
55-
watch-ui:
56-
cd internal/ui && yarn start
57-
58-
# builds
5917
build:
60-
CGO_ENABLED=0 packr2 build -o commit0
61-
packr2 clean
62-
cd internal/ui && yarn && yarn build
18+
go build -o commit0
6319

6420
# Installs the CLI int your GOPATH
6521
install-go:
66-
CGO_ENABLED=0 packr2 build -o ${GOPATH}/bin/commit0
67-
packr2 clean
22+
go build -o ${GOPATH}/bin/commit0

README.md

Lines changed: 11 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Commit0 [POC]
22

33
[![Build Status](https://travis-ci.org/commitdev/commit0.svg)](https://travis-ci.org/commitdev/commit0)
4+
[![Go Report Card](https://goreportcard.com/badge/github.com/commitdev/commit0?style=flat-square)](https://goreportcard.com/report/github.com/commitdev/commit0)
5+
[![Go Doc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](http://godoc.org/github.com/commitdev/commit0)
46

57
Status: Proof of Concept
68

@@ -15,57 +17,26 @@ With Commit0:
1517

1618
## Installation
1719

18-
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`.
20+
As there some dependencies it will be easier to use this tool within the provided image, clone the repo and then run `make build-docker-local`.
1921
The best way then to use this is to add an alias, then you can use the CLI as if it was installed as usual on your machine:
2022
`alias commit0='docker run -it -v "$(pwd):/project" -v "${HOME}/.aws:/root/.aws" commit0:v0'`
2123

2224
## Usage
2325

2426
1) To create a project run `commit0 create [PROJECT_NAME]`
25-
2) A folder will be created and within that update the `commit0.yml` and then run `commit0 generate -c <commit0.yml>`
26-
3) You will see that there is now an idl folder created.
27-
4) Within the idl folder modify the the protobuf services generated with your desired methods
28-
5) Go up to the parent directory and re run `commit0 generate -c <commit0.yml>`
29-
6) You will now see a `server` folder navigate to your service folder within that directory and implement the methods generated for it
30-
7) Once you have tested your implementation and are happy with it return to the idl repo push that directory up to git
31-
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
32-
10) Test and push up your implementation!
33-
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.
34-
35-
36-
## What does it generate?
37-
38-
The generation will create project folder, within this there will be your implementation and an IDL folder
39-
40-
* A parent directory that implements a skeleton and sets up your service implementation of the generated artifacts
41-
* A child directory for the IDL's, this folder will also contain generated artifacts from the IDL under 'gen'
42-
43-
Based on specified config it will generate:
44-
* Proto files [Done]
45-
* Proto libraries [Done]
46-
* GraphQL files [Later]
47-
* GraphQL libraries [Later]
48-
* grpc web [Partial - Libraries generates for typescript]
49-
* grpc gateway [ Partial - generates swagger & grpc gateway libraries]
50-
* Layout [Done for go]
51-
* Kubernetes manifests [In progress]
52-
53-
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.
54-
27+
2) It will prompt you to select a cloud provider and an account profile to use
28+
3) A folder `PROJECT_NAME` will be created. You can `cd [PROJECT_NAME]` and configure the example `commit0.yml` that's generated
29+
4) Run `commit0 generate -c <commit0.yml>` to generate all the all the project repos
30+
5) You can go to each project repo and follow the project readme to start the service
31+
6) `commit0 ui` launches the locally hosted web UI (Static SPA) and the API server
5532

5633
## Development
5734
We are looking for contributors!
5835

5936
Building from the source
6037
```
61-
make build-deps
62-
make deps-go
63-
```
64-
this will create a commit0 executable in your working direcory. To install install it into your go path use:
65-
```
6638
make install-go
6739
```
68-
6940
Compile a new `commit0` binary in the working directory
7041
```
7142
make build
@@ -80,88 +51,13 @@ cd test-app
8051
../../commit0 generate -c commit0.yml
8152
```
8253

83-
### Configuration UI
84-
85-
If you're working on the configuration UI locally, you can run just the ui by doing the following.
86-
87-
``` bash
88-
cd internal/ui
89-
yarn
90-
yarn start
54+
To run a single test for development
9155
```
92-
93-
If you want to test the full integration with the go app, you'll need to do a build and run the app with `./commit0 ui`.
94-
95-
``` bash
96-
make build
97-
./commit0 ui
56+
go test -run TestGenerateModules "github.com/commitdev/commit0/internal/generate" -v
9857
```
9958

100-
[http://localhost:8080/](http://localhost:8080/)
101-
102-
### Architecture
103-
The project is built with GoLang and requires Docker
104-
- /cmd - the CLI command entry points
105-
- /internal/generate
106-
- /internal/config
107-
- /internal/templator - the templating service
108-
109-
Example Flow:
110-
The application starts at `cmd/generate.go`
111-
1. loads all the templates from packr
112-
- TODO: eventually this should be loaded remotely throug a dependency management system
113-
2. loads the config from the commit0.yml config file
114-
3. based on the configs, run the appropriate generators
115-
- templator is passed in to the Generate function for dependency injection
116-
- `internal/generate/generate_helper.go` iterates through all the configs and runs each generator
117-
4. each generator (`react/generate.go`, `ci/generate.go` etc) further delegates and actually executes the templating based on the configs passed in.
118-
- `internal/templator/templator.go` is the base class and includes generic templating handling logic
119-
- it CI is required, it'll also call a CI generator and pass in the service specific CI configs
120-
- TOOD: CI templates have to call separate templates based on the context
121-
- TODO: templator should be generic and not have any knowledge of the specific templating implementation (go, ci etc), move that logic upstream
122-
5. Depending on the config (`deploy == true` for certain) it'll also run the `Execute` function and actually deploy the infrastructure
123-
12459
### Building locally
125-
126-
As the templates are embeded into the binary you will need to ensure packr2 is installed.
127-
128-
You can run `make deps-go` to install this.
129-
130-
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`.
60+
As there are some dependencies it will be easier to use this tool within the provided image, clone the repo and then run `make build-docker-local`.
13161

13262
The best way then to use this is to add an alias, then you can use the CLI as if it was installed as usual on your machine:
13363
`alias commit0='docker run -it -v "$(pwd):/project" commit0:v0'`
134-
135-
### Dependencies
136-
137-
In order to use this you need ensure you have these installed.
138-
* protoc
139-
* protoc-gen-go [Go]
140-
* protoc-gen-web [gRPC Web]
141-
* protoc-gen-gateway [Http]
142-
* protoc-gen-swagger [Swagger]
143-
144-
145-
### Commit0 Demo
146-
- clone the repo
147-
- run `make build-docker-local`
148-
- add an alias `alias commit0='docker run -it -v "$(pwd):/project" -v "${HOME}/.aws:/root/.aws" commit0:v0'`
149-
- remember to also add this alias to your bash profile if you want it to persist when you open a new terminal
150-
- create a temporary directory `mkdir tmp; cd tmp`
151-
- create the project `commit0 create beier-demo`
152-
- when prompted, select `Amazon AWS`, `us-west-2`, and your commit AWS profile
153-
- `cd beier-demo`
154-
- generate the codebase `commit0 generate --apply`
155-
- go to the react repo `cd react`
156-
- push to the prepped Github Repo. This repo already has AWS credentials loaded in Github Secrets
157-
```
158-
git init
159-
git add -A
160-
git commit -m commit0
161-
git remote add origin git@github.com:commitdev/commit0-demo.git
162-
git push -u origin master --force
163-
```
164-
- Wait for Github Actions to finish
165-
- View the site at http://beier-demo-staging.s3-website-us-west-2.amazonaws.com/
166-
- go to signup, just ensure you have a strong enough password it needs caps, symbol and numerics ex `@Testing123`
167-
- Alternatively you can run the app locally `npm install; npm start`

0 commit comments

Comments
 (0)