Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@ main-packr.go
packrd
/commit0
.history/
tmp/

# Generated files from Config UI.
intenral/ui/node_modules
intenral/ui/build
tmp
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
language: go

script:
- GO111MODULE=on make build-deps
- GO111MODULE=on make build
- GO111MODULE=on make check

go:
- 1.12.x
- 1.13.x
31 changes: 1 addition & 30 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,41 +1,13 @@
FROM golang:1.12.12-alpine3.10 as builder

ENV GO111MODULE=on
ENV GOLANG_PROTOBUF_VERSION=1.3.1
ENV GRPC_GATEWAY_VERSION=1.11.3
ENV GRPC_WEB_VERSION=1.0.6
ENV PROTOBUF_VERSION=3.6.1
ENV TERRAFORM_VERSION=0.12.13
ENV K8S_VERSION=1.14.8

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

RUN apk add --update nodejs npm

RUN go get \
github.com/golang/protobuf/protoc-gen-go@v${GOLANG_PROTOBUF_VERSION} &&\
mv /go/bin/protoc-gen-go* /usr/local/bin/

RUN curl -sSL \
https://github.com/grpc-ecosystem/grpc-gateway/releases/download/v${GRPC_GATEWAY_VERSION}/protoc-gen-grpc-gateway-v${GRPC_GATEWAY_VERSION}-linux-x86_64 \
-o /usr/local/bin/protoc-gen-grpc-gateway && \
curl -sSL \
https://github.com/grpc-ecosystem/grpc-gateway/releases/download/v${GRPC_GATEWAY_VERSION}/protoc-gen-swagger-v${GRPC_GATEWAY_VERSION}-linux-x86_64 \
-o /usr/local/bin/protoc-gen-swagger

RUN curl -sSL \
https://github.com/grpc/grpc-web/releases/download/${GRPC_WEB_VERSION}/protoc-gen-grpc-web-${GRPC_WEB_VERSION}-linux-x86_64 \
-o /usr/local/bin/protoc-gen-grpc-web

RUN mkdir -p /tmp/protoc && \
curl -sSL \
https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VERSION}/protoc-${PROTOBUF_VERSION}-linux-x86_64.zip \
-o /tmp/protoc/protoc.zip && \
cd /tmp/protoc && \
unzip protoc.zip && \
mv /tmp/protoc/include /usr/local/include

RUN curl -sSL \
https://storage.googleapis.com/kubernetes-release/release/v${K8S_VERSION}/bin/linux/amd64/kubectl \
-o /usr/local/bin/kubectl
Expand Down Expand Up @@ -72,6 +44,5 @@ COPY --from=builder /usr/local/bin /usr/local/bin
COPY --from=builder /usr/local/include /usr/local/include
COPY --from=builder /go/src/github.com/grpc-ecosystem/grpc-gateway ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway
WORKDIR /project
RUN apk add --update --no-cache make protobuf=${PROTOBUF_VERSION} && \
rm -rf /var/cache/apk/*

ENTRYPOINT ["/usr/local/bin/commit0"]
49 changes: 2 additions & 47 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,46 +1,11 @@
PROTOC_VERSION := 3.9.2
PROTOC_WEB_VERSION := 1.0.6

PROTO_SOURCES := -I /usr/local/include
PROTO_SOURCES += -I .
PROTO_SOURCES += -I ${GOPATH}/src
PROTO_SOURCES += -I ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway

VERSION:= 0.0.1

deps-linux: deps-go deps-protoc-linux deps-grpc-web-linux

deps-protoc-linux:
curl -OL https://github.com/google/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-linux-x86_64.zip
unzip protoc-$(PROTOC_VERSION)-linux-x86_64.zip -d protoc3
mv protoc3/bin/protoc /usr/local/bin
mv protoc3/include/* /usr/local/include
rm -rf protoc3 protoc-$(PROTOC_VERSION)-linux-x86_64.zip

deps-grpc-web-linux:
curl -OL https://github.com/grpc/grpc-web/releases/download/$(PROTOC_WEB_VERSION)/protoc-gen-grpc-web-$(PROTOC_WEB_VERSION)-linux-x86_64
mv protoc-gen-grpc-web-$(PROTOC_WEB_VERSION)-linux-x86_64 /usr/local/bin/protoc-gen-grpc-web
chmod +x /usr/local/bin/protoc-gen-grpc-web

deps-go:
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
go get -u github.com/golang/protobuf/protoc-gen-go

build-deps:
go install github.com/gobuffalo/packr/v2/packr2

check:
go test ./...

fmt:
go fmt ./...

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

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

Expand All @@ -49,19 +14,9 @@ build-example-docker: clean-example
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

clean-example:
rm -rf example

watch-ui:
cd internal/ui && yarn start

# builds
build:
CGO_ENABLED=0 packr2 build -o commit0
packr2 clean
cd internal/ui && yarn && yarn build
go build -o commit0

# Installs the CLI int your GOPATH
install-go:
CGO_ENABLED=0 packr2 build -o ${GOPATH}/bin/commit0
packr2 clean
go build -o ${GOPATH}/bin/commit0
126 changes: 11 additions & 115 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Commit0 [POC]

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

Status: Proof of Concept

Expand All @@ -15,57 +17,26 @@ With Commit0:

## 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`.
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`.
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:
`alias commit0='docker run -it -v "$(pwd):/project" -v "${HOME}/.aws:/root/.aws" commit0:v0'`

## Usage

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 -c <commit0.yml>`
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 parent directory and re run `commit0 generate -c <commit0.yml>`
6) You will now see a `server` folder navigate to your service folder within that directory and implement the methods generated for it
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 commit0 config and re-run `commit0 generate` and repeat steps 4 - 7.


## What does it generate?

The generation will create project folder, within this there will be your implementation and an IDL folder

* A parent directory that implements a skeleton and sets up your service implementation of the generated artifacts
* A child directory for the IDL's, this folder will also contain generated artifacts from the IDL under 'gen'

Based on specified config it will generate:
* Proto files [Done]
* Proto libraries [Done]
* GraphQL files [Later]
* GraphQL libraries [Later]
* grpc web [Partial - Libraries generates for typescript]
* grpc gateway [ Partial - generates swagger & grpc gateway libraries]
* Layout [Done for go]
* Kubernetes manifests [In progress]

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.

2) It will prompt you to select a cloud provider and an account profile to use
3) A folder `PROJECT_NAME` will be created. You can `cd [PROJECT_NAME]` and configure the example `commit0.yml` that's generated
4) Run `commit0 generate -c <commit0.yml>` to generate all the all the project repos
5) You can go to each project repo and follow the project readme to start the service
6) `commit0 ui` launches the locally hosted web UI (Static SPA) and the API server

## Development
We are looking for contributors!

Building from the source
```
make build-deps
make deps-go
```
this will create a commit0 executable in your working direcory. To install install it into your go path use:
```
make install-go
```

Compile a new `commit0` binary in the working directory
```
make build
Expand All @@ -80,88 +51,13 @@ cd test-app
../../commit0 generate -c commit0.yml
```

### Configuration UI

If you're working on the configuration UI locally, you can run just the ui by doing the following.

``` bash
cd internal/ui
yarn
yarn start
To run a single test for development
```

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

``` bash
make build
./commit0 ui
go test -run TestGenerateModules "github.com/commitdev/commit0/internal/generate" -v
```

[http://localhost:8080/](http://localhost:8080/)

### Architecture
The project is built with GoLang and requires Docker
- /cmd - the CLI command entry points
- /internal/generate
- /internal/config
- /internal/templator - the templating service

Example Flow:
The application starts at `cmd/generate.go`
1. loads all the templates from packr
- TODO: eventually this should be loaded remotely throug a dependency management system
2. loads the config from the commit0.yml config file
3. based on the configs, run the appropriate generators
- templator is passed in to the Generate function for dependency injection
- `internal/generate/generate_helper.go` iterates through all the configs and runs each generator
4. each generator (`react/generate.go`, `ci/generate.go` etc) further delegates and actually executes the templating based on the configs passed in.
- `internal/templator/templator.go` is the base class and includes generic templating handling logic
- it CI is required, it'll also call a CI generator and pass in the service specific CI configs
- TOOD: CI templates have to call separate templates based on the context
- TODO: templator should be generic and not have any knowledge of the specific templating implementation (go, ci etc), move that logic upstream
5. Depending on the config (`deploy == true` for certain) it'll also run the `Execute` function and actually deploy the infrastructure

### Building locally

As the templates are embeded into the binary you will need to ensure packr2 is installed.

You can run `make deps-go` to install this.

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

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:
`alias commit0='docker run -it -v "$(pwd):/project" commit0:v0'`

### Dependencies

In order to use this you need ensure you have these installed.
* protoc
* protoc-gen-go [Go]
* protoc-gen-web [gRPC Web]
* protoc-gen-gateway [Http]
* protoc-gen-swagger [Swagger]


### Commit0 Demo
- clone the repo
- run `make build-docker-local`
- add an alias `alias commit0='docker run -it -v "$(pwd):/project" -v "${HOME}/.aws:/root/.aws" commit0:v0'`
- remember to also add this alias to your bash profile if you want it to persist when you open a new terminal
- create a temporary directory `mkdir tmp; cd tmp`
- create the project `commit0 create beier-demo`
- when prompted, select `Amazon AWS`, `us-west-2`, and your commit AWS profile
- `cd beier-demo`
- generate the codebase `commit0 generate --apply`
- go to the react repo `cd react`
- push to the prepped Github Repo. This repo already has AWS credentials loaded in Github Secrets
```
git init
git add -A
git commit -m commit0
git remote add origin git@github.com:commitdev/commit0-demo.git
git push -u origin master --force
```
- Wait for Github Actions to finish
- View the site at http://beier-demo-staging.s3-website-us-west-2.amazonaws.com/
- go to signup, just ensure you have a strong enough password it needs caps, symbol and numerics ex `@Testing123`
- Alternatively you can run the app locally `npm install; npm start`
Loading