Skip to content

Commit eeb085b

Browse files
committed
move to one project directory, dockerize cli
1 parent eba25fe commit eeb085b

File tree

22 files changed

+146
-621
lines changed

22 files changed

+146
-621
lines changed

Dockerfile

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,63 @@
1-
FROM golang:1.12.6@sha256:83e8267be041b3ddf6a5792c7e464528408f75c446745642db08cfe4e8d58d18 AS build
2-
WORKDIR /cache
1+
FROM golang:1.12.4-alpine3.9 as builder
2+
3+
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.9.2
8+
9+
RUN apk add --update --no-cache build-base curl git upx && \
10+
rm -rf /var/cache/apk/*
11+
12+
RUN go get \
13+
github.com/golang/protobuf/protoc-gen-go@v${GOLANG_PROTOBUF_VERSION} &&\
14+
mv /go/bin/protoc-gen-go* /usr/local/bin/
15+
16+
RUN curl -sSL \
17+
https://github.com/grpc-ecosystem/grpc-gateway/releases/download/v${GRPC_GATEWAY_VERSION}/protoc-gen-grpc-gateway-v${GRPC_GATEWAY_VERSION}-linux-x86_64 \
18+
-o /usr/local/bin/protoc-gen-grpc-gateway && \
19+
curl -sSL \
20+
https://github.com/grpc-ecosystem/grpc-gateway/releases/download/v${GRPC_GATEWAY_VERSION}/protoc-gen-swagger-v${GRPC_GATEWAY_VERSION}-linux-x86_64 \
21+
-o /usr/local/bin/protoc-gen-swagger && \
22+
chmod +x /usr/local/bin/protoc-gen-grpc-gateway && \
23+
chmod +x /usr/local/bin/protoc-gen-swagger
24+
25+
RUN curl -sSL \
26+
https://github.com/grpc/grpc-web/releases/download/${GRPC_WEB_VERSION}/protoc-gen-grpc-web-${GRPC_WEB_VERSION}-linux-x86_64 \
27+
-o /usr/local/bin/protoc-gen-grpc-web && \
28+
chmod +x /usr/local/bin/protoc-gen-grpc-web
29+
30+
RUN mkdir -p /tmp/protoc && \
31+
curl -sSL \
32+
https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VERSION}/protoc-${PROTOBUF_VERSION}-linux-x86_64.zip \
33+
-o /tmp/protoc/protoc.zip && \
34+
cd /tmp/protoc && \
35+
unzip protoc.zip && \
36+
mv /tmp/protoc/include /usr/local/include
37+
38+
RUN GO111MODULE=off go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
39+
40+
WORKDIR tmp/sprout
341
COPY go.mod .
442
COPY go.sum .
543
RUN go mod tidy && go mod download
644
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-
45+
RUN make build-deps && make build && \
46+
mv sprout /usr/local/bin
47+
RUN upx --lzma /usr/local/bin/*
1248

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
49+
FROM alpine:edge
50+
ENV \
51+
PROTOTOOL_PROTOC_BIN_PATH=/usr/bin/protoc \
52+
PROTOTOOL_PROTOC_WKT_PATH=/usr/local/include \
53+
PROTOBUF_VERSION=3.9.2 \
54+
ALPINE_PROTOBUF_VERSION_SUFFIX=r0 \
55+
GOPATH=/proto-libs
56+
RUN mkdir ${GOPATH}
57+
COPY --from=builder /usr/local/bin /usr/local/bin
58+
COPY --from=builder /usr/local/include /usr/local/include
59+
COPY --from=builder /go/src/github.com/grpc-ecosystem/grpc-gateway ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway
60+
WORKDIR /project
61+
RUN apk add --update --no-cache make bash curl git protobuf=${PROTOBUF_VERSION}-${ALPINE_PROTOBUF_VERSION_SUFFIX} && \
62+
rm -rf /var/cache/apk/*
63+
ENTRYPOINT ["sprout"]

Makefile

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ PROTOC_WEB_VERSION := 1.0.6
44
PROTO_SOURCES := -I /usr/local/include
55
PROTO_SOURCES += -I .
66
PROTO_SOURCES += -I ${GOPATH}/src
7-
PROTO_SOURCES += -I ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis
87
PROTO_SOURCES += -I ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway
98

109
VERSION:= 0.0.1
@@ -14,21 +13,23 @@ deps-linux: deps-go deps-protoc-linux deps-grpc-web-linux
1413
deps-protoc-linux:
1514
curl -OL https://github.com/google/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-linux-x86_64.zip
1615
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
16+
mv protoc3/bin/protoc /usr/local/bin
17+
mv protoc3/include/* /usr/local/include
1918
rm -rf protoc3 protoc-$(PROTOC_VERSION)-linux-x86_64.zip
2019

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

2625
deps-go:
27-
go get -u github.com/gobuffalo/packr/v2/packr2
2826
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
2927
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
3028
go get -u github.com/golang/protobuf/protoc-gen-go
3129

30+
build-deps:
31+
go install github.com/gobuffalo/packr/v2/packr2
32+
3233
fmt:
3334
go fmt ./...
3435

@@ -44,6 +45,11 @@ build-example: build clean-example
4445
cd example && ../sprout create "hello-world"
4546
cd example/hello-world && ../../sprout generate -l go
4647

48+
build-example-docker: clean-example
49+
mkdir -p example
50+
docker run -v "$(shell pwd)/example:/project" --user $(shell id -u):$(shell id -g) sprout:v0 create "hello-world"
51+
docker run -v "$(shell pwd)/example/hello-world:/project" --user $(shell id -u):$(shell id -g) sprout:v0 generate -l go
52+
4753
build-docker-local:
4854
docker build . -t sprout:v0
4955

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@ It will also live with your project, when you add a new service to the config it
2020

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

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

26-
27-
`NOTE: You`
28-
2926
## The development cycle
3027

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

4239
## Usage & installation
4340

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.
41+
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.
4542

4643
## Dependencies
4744

cmd/create.go

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

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

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

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

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-
4537
sproutConfigPath := fmt.Sprintf("%v/sprout.yml", rootDir)
4638

4739
f, err := os.Create(sproutConfigPath)

example/hello-world-idl/gen/http/health/health.pb.gw.go

Lines changed: 0 additions & 159 deletions
This file was deleted.

0 commit comments

Comments
 (0)