Skip to content

Commit

Permalink
move to one project directory, dockerize cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Pritesh-Patel committed Oct 6, 2019
1 parent eba25fe commit eeb085b
Show file tree
Hide file tree
Showing 22 changed files with 146 additions and 621 deletions.
70 changes: 58 additions & 12 deletions Dockerfile
@@ -1,17 +1,63 @@
FROM golang:1.12.6@sha256:83e8267be041b3ddf6a5792c7e464528408f75c446745642db08cfe4e8d58d18 AS build
WORKDIR /cache
FROM golang:1.12.4-alpine3.9 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.9.2

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

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 && \
chmod +x /usr/local/bin/protoc-gen-grpc-gateway && \
chmod +x /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 && \
chmod +x /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 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
COPY . .
RUN apt-get update && apt-get -y install sudo && apt-get -y install unzip
RUN make deps-linux && mv /go/bin/protoc-* /usr/local/bin/
RUN make install-go && \
mv /go/bin/sprout /usr/local/bin/

RUN make build-deps && make build && \
mv sprout /usr/local/bin
RUN upx --lzma /usr/local/bin/*

FROM alpine
WORKDIR project
RUN apk add --update make
COPY --from=build /usr/local/bin /usr/local/bin
COPY --from=build /usr/local/include /usr/include
FROM alpine:edge
ENV \
PROTOTOOL_PROTOC_BIN_PATH=/usr/bin/protoc \
PROTOTOOL_PROTOC_WKT_PATH=/usr/local/include \
PROTOBUF_VERSION=3.9.2 \
ALPINE_PROTOBUF_VERSION_SUFFIX=r0 \
GOPATH=/proto-libs
RUN mkdir ${GOPATH}
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 bash curl git protobuf=${PROTOBUF_VERSION}-${ALPINE_PROTOBUF_VERSION_SUFFIX} && \
rm -rf /var/cache/apk/*
ENTRYPOINT ["sprout"]
16 changes: 11 additions & 5 deletions Makefile
Expand Up @@ -4,7 +4,6 @@ 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/third_party/googleapis
PROTO_SOURCES += -I ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway

VERSION:= 0.0.1
Expand All @@ -14,21 +13,23 @@ 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
sudo mv protoc3/bin/* /usr/local/bin
sudo mv protoc3/include/* /usr/local/include
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
sudo mv protoc-gen-grpc-web-$(PROTOC_WEB_VERSION)-linux-x86_64 /usr/local/bin/protoc-gen-grpc-web
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/gobuffalo/packr/v2/packr2
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

fmt:
go fmt ./...

Expand All @@ -44,6 +45,11 @@ build-example: build clean-example
cd example && ../sprout create "hello-world"
cd example/hello-world && ../../sprout 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

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

Expand Down
7 changes: 2 additions & 5 deletions README.md
Expand Up @@ -20,12 +20,9 @@ It will also live with your project, when you add a new service to the config it

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

* A parrent directory that implements a skeleton and sets up your service implementation of the generated artifacts
* 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'


`NOTE: You`

## The development cycle

1) To create a project run `sprout create [PROJECT_NAME]`
Expand All @@ -41,7 +38,7 @@ The generation will create project folder, within this there will be your implem

## 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" sprout:local` 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) sprout:v0` as sprout from then you can use the CLI as if it was installed as usual on your machine.

## Dependencies

Expand Down
8 changes: 0 additions & 8 deletions cmd/create.go
Expand Up @@ -24,7 +24,6 @@ var createCmd = &cobra.Command{
projectName := args[0]

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

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

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

err = os.Mkdir(idlDir, os.ModePerm)
if os.IsExist(err) {
log.Fatalf("Directory %v already exists! Error: %v", projectName, err)
} else if err != nil {
log.Fatalf("Error creating root: %v ", err)
}

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

f, err := os.Create(sproutConfigPath)
Expand Down
159 changes: 0 additions & 159 deletions example/hello-world-idl/gen/http/health/health.pb.gw.go

This file was deleted.

0 comments on commit eeb085b

Please sign in to comment.