Skip to content

Commit 10cbbf4

Browse files
committed
Switch to latest prototool and other generators
1 parent c7b7909 commit 10cbbf4

File tree

6 files changed

+93
-75
lines changed

6 files changed

+93
-75
lines changed

Dockerfile

Lines changed: 60 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,62 @@
1-
FROM golang:1.11-alpine AS build
2-
ARG PROTOTOOL_VERSION=1.3.0
3-
ARG PROTOC_VERSION=3.6.1
4-
ARG PROTOC_GEN_GO_VERSION=1.2.0
5-
ARG PROTOC_GEN_GOGO_VERSION=1.1.1
6-
ARG PROTOC_GEN_JAVA_GRPC_VERSION=1.16.1
7-
ARG PROTOC_GEN_VALIDATE_VERSION=0.0.10
8-
9-
RUN apk --no-cache add --update curl git libc6-compat make
10-
RUN \
11-
curl -sSL https://github.com/uber/prototool/releases/download/v$PROTOTOOL_VERSION/prototool-Linux-x86_64 -o /bin/prototool && \
12-
chmod +x /bin/prototool
13-
RUN \
14-
mkdir /tmp/prototool-bootstrap && \
15-
echo $'protoc:\n version:' $PROTOC_VERSION > /tmp/prototool-bootstrap/prototool.yaml && \
16-
echo 'syntax = "proto3";' > /tmp/prototool-bootstrap/tmp.proto && \
17-
prototool compile /tmp/prototool-bootstrap && \
18-
rm -rf /tmp/prototool-bootstrap
19-
RUN go get github.com/golang/protobuf/... && \
20-
cd /go/src/github.com/golang/protobuf && \
21-
git checkout v$PROTOC_GEN_GO_VERSION && \
22-
go install ./protoc-gen-go
23-
RUN go get github.com/gogo/protobuf/... && \
24-
cd /go/src/github.com/gogo/protobuf && \
25-
git checkout v$PROTOC_GEN_GOGO_VERSION && \
26-
go install ./protoc-gen-gogofast ./protoc-gen-gogofaster ./protoc-gen-gogoslick
27-
RUN go get -d github.com/lyft/protoc-gen-validate && \
28-
cd /go/src/github.com/lyft/protoc-gen-validate && \
29-
git checkout v$PROTOC_GEN_VALIDATE_VERSION && \
30-
make build
31-
RUN curl -sSL https://search.maven.org/remotecontent?filepath=io/grpc/protoc-gen-grpc-java/$PROTOC_GEN_JAVA_GRPC_VERSION/protoc-gen-grpc-java-$PROTOC_GEN_JAVA_GRPC_VERSION-linux-x86_64.exe -o /bin/protoc-gen-grpc-java && \
32-
chmod +x /bin/protoc-gen-grpc-java
33-
34-
FROM alpine:3.8
35-
WORKDIR /in
36-
RUN apk --no-cache add --update libc6-compat
37-
COPY --from=build /bin/prototool /bin/prototool
38-
COPY --from=build /root/.cache/prototool /.cache/prototool
39-
COPY --from=build /go/bin/protoc-gen-go /bin/protoc-gen-go
40-
COPY --from=build /go/bin/protoc-gen-gogofast /bin/protoc-gen-gogofast
41-
COPY --from=build /go/bin/protoc-gen-gogofaster /bin/protoc-gen-gogofaster
42-
COPY --from=build /go/bin/protoc-gen-gogoslick /bin/protoc-gen-gogoslick
43-
COPY --from=build /go/bin/protoc-gen-validate /bin/protoc-gen-validate
44-
COPY --from=build /go/src/github.com/lyft/protoc-gen-validate/validate /include/validate
45-
COPY --from=build /bin/protoc-gen-grpc-java /bin/protoc-gen-grpc-java
46-
47-
RUN chmod -R 755 /.cache
48-
ENTRYPOINT ["/bin/prototool"]
1+
FROM golang:1.12.4-alpine3.9 AS build
492

3+
ARG PROTOTOOL_VERSION=1.6.0
4+
ARG PROTOC_GEN_JAVA_GRPC_VERSION=1.20.0
5+
ARG GOLANG_PROTOBUF_VERSION=1.3.1
6+
ARG GOGO_PROTOBUF_VERSION=1.2.1
7+
ARG GRPC_GATEWAY_VERSION=1.8.5
8+
ARG GRPC_WEB_VERSION=1.0.4
509

10+
RUN apk --no-cache add --update curl git libc6-compat make upx
11+
12+
RUN GO111MODULE=on go get \
13+
github.com/uber/prototool/cmd/prototool@v${PROTOTOOL_VERSION} && \
14+
mv /go/bin/prototool /usr/local/bin
15+
16+
RUN GO111MODULE=on go get \
17+
github.com/golang/protobuf/protoc-gen-go@v${GOLANG_PROTOBUF_VERSION} \
18+
github.com/gogo/protobuf/protoc-gen-gofast@v${GOGO_PROTOBUF_VERSION} \
19+
github.com/gogo/protobuf/protoc-gen-gogo@v${GOGO_PROTOBUF_VERSION} \
20+
github.com/gogo/protobuf/protoc-gen-gogofast@v${GOGO_PROTOBUF_VERSION} \
21+
github.com/gogo/protobuf/protoc-gen-gogofaster@v${GOGO_PROTOBUF_VERSION} \
22+
github.com/gogo/protobuf/protoc-gen-gogoslick@v${GOGO_PROTOBUF_VERSION} && \
23+
mv /go/bin/protoc-gen-go* /usr/local/bin/
24+
25+
RUN go get -d github.com/gogo/protobuf/gogoproto && \
26+
mkdir -p /usr/include/gogoproto && \
27+
mv /go/src/github.com/gogo/protobuf/gogoproto/gogo.proto /usr/include/gogoproto/gogo.proto
28+
29+
RUN curl -sSL \
30+
https://github.com/grpc-ecosystem/grpc-gateway/releases/download/v${GRPC_GATEWAY_VERSION}/protoc-gen-grpc-gateway-v${GRPC_GATEWAY_VERSION}-linux-x86_64 \
31+
-o /usr/local/bin/protoc-gen-grpc-gateway && \
32+
curl -sSL \
33+
https://github.com/grpc-ecosystem/grpc-gateway/releases/download/v${GRPC_GATEWAY_VERSION}/protoc-gen-swagger-v${GRPC_GATEWAY_VERSION}-linux-x86_64 \
34+
-o /usr/local/bin/protoc-gen-swagger && \
35+
chmod +x /usr/local/bin/protoc-gen-grpc-gateway && \
36+
chmod +x /usr/local/bin/protoc-gen-swagger
37+
38+
RUN curl -sSL \
39+
https://github.com/grpc/grpc-web/releases/download/${GRPC_WEB_VERSION}/protoc-gen-grpc-web-${GRPC_WEB_VERSION}-linux-x86_64 \
40+
-o /usr/local/bin/protoc-gen-grpc-web && \
41+
chmod +x /usr/local/bin/protoc-gen-grpc-web
42+
43+
RUN go get -d github.com/envoyproxy/protoc-gen-validate && \
44+
cd /go/src/github.com/envoyproxy/protoc-gen-validate && \
45+
make build && \
46+
mv /go/bin/protoc-gen-validate /usr/local/bin && \
47+
mkdir -p /usr/include/validate && \
48+
mv /go/src/github.com/envoyproxy/protoc-gen-validate/validate/validate.proto /usr/include/validate/validate.proto
49+
50+
RUN curl -sSL https://search.maven.org/remotecontent?filepath=io/grpc/protoc-gen-grpc-java/$PROTOC_GEN_JAVA_GRPC_VERSION/protoc-gen-grpc-java-$PROTOC_GEN_JAVA_GRPC_VERSION-linux-x86_64.exe -o /usr/local/bin/protoc-gen-grpc-java && \
51+
chmod +x /usr/local/bin/protoc-gen-grpc-java
52+
53+
RUN upx --lzma /usr/local/bin/*
54+
55+
FROM alpine:3.9
56+
ENV PROTOTOOL_CACHE_PATH=/tmp
57+
ENV LD_LIBRARY_PATH=/lib64:/lib
58+
WORKDIR /work
59+
RUN apk --no-cache add --update ca-certificates libc6-compat
60+
COPY --from=build /usr/local/bin /usr/local/bin
61+
COPY --from=build /usr/include /usr/include
62+
RUN chmod -R 755 /usr/include

README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,34 @@ Prototool Docker Helper
55

66

77
Docker image with [prototool](https://github.com/uber/prototool), [gogoproto](https://github.com/gogo/protobuf),
8-
[protoc-gen-validate](https://github.com/lyft/protoc-gen-validate) and `protoc-gen-grpc-java` pre-installed.
8+
[protoc-gen-validate](https://github.com/envoyproxy/protoc-gen-validate), [grpc-gateway](https://github.com/grpc-ecosystem/grpc-gateway), [grpc-web](https://github.com/grpc/grpc-web) and `protoc-gen-grpc-java` pre-installed.
99

10-
The accompanying `prototool.sh` script mounts the current working directory as `/in` and runs the Docker image
10+
The accompanying `prototool.sh` script mounts the current working directory as `/work` and runs the Docker image
1111
as the current user. This results in the generated artifacts having the correct permissions.
1212

1313

1414
Installation
1515
------------
1616

1717
```shell
18-
curl -o prototool.sh https://raw.githubusercontent.com/charithe/prototool-docker/v0.0.2/prototool.sh
18+
curl -o prototool.sh https://raw.githubusercontent.com/charithe/prototool-docker/v0.1.0/prototool.sh
1919
```
2020

2121
Optionally, add `prototool.sh` to your `PATH`.
2222

2323
Usage
2424
-----
2525

26+
See [example](example) for a full example.
27+
28+
2629
Create a `prototool.yaml` file in your project root as usual. For example:
2730

2831
```yaml
2932
protoc:
30-
version: 3.6.1
31-
include:
32-
- /include
33+
version: 3.7.1
34+
includes:
35+
- /usr/include
3336

3437
lint:
3538
rules:
@@ -38,35 +41,33 @@ lint:
3841

3942
generate:
4043
go_options:
41-
import_path: github.com/charithe/grpc-gizmo
44+
import_path: github.com/charithe/telemetry
4245

4346
plugins:
4447
- name: gogofast
4548
type: gogo
46-
path: /bin/protoc-gen-gogofast
4749
flags: plugins=grpc
48-
output: ./go/pkg/v1pb
50+
output: ./go/pkg/gen
4951
- name: validate
50-
path: /bin/protoc-gen-validate
5152
flags: lang=go
52-
output: ./go/pkg/v1pb
53+
output: ./go/pkg/gen
5354
- name: java
5455
output: ./java/src/main/java
5556
- name: grpc-java
56-
path: /bin/protoc-gen-grpc-java
5757
output: ./java/src/main/java
58+
59+
5860
```
5961

6062
Prototool can now be invoked as follows:
6163

6264
```shell
6365
# Lint
64-
/path/to/prototool.sh lint
66+
./prototool.sh lint
6567

6668
# Compile
67-
/path/to/prototool.sh compile
69+
./prototool.sh compile
6870

6971
# All
70-
/path/to/prototool.sh all
72+
./prototool.sh all
7173
```
72-

example/build.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!/usr/bin/env bash
22

33
USER="$(id -u):$(id -g)"
4-
5-
rm -rf go java
6-
docker run --rm --user $USER -i -t -v $(pwd):/in charithe/prototool-docker all
4+
docker run -it \
5+
--rm \
6+
--user $USER \
7+
--mount type=bind,source="$(pwd)",target=/work \
8+
--tmpfs /tmp:exec \
9+
charithe/prototool-docker prototool $@

example/proto/telemetry.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import "google/protobuf/timestamp.proto";
1111
import "validate/validate.proto";
1212

1313
service Telemetry {
14-
// Record receives and persists telemetry data from remote devices
14+
// Record receives and persists telemetry data from remote devices
1515
rpc Record(RecordRequest) returns (RecordResponse);
1616
}
1717

@@ -53,7 +53,7 @@ message TelemetryData {
5353
message LogEntry {
5454
// timestamp must be after 2018-01-01
5555
google.protobuf.Timestamp timestamp = 1 [(validate.rules).timestamp.gte.seconds = 1514764800];
56-
// component must be at least 5 characters long
56+
// component must be at least 5 characters long
5757
string component = 2 [(validate.rules).string.min_len = 5];
5858
// state must be at least 10 bytes long
5959
bytes state = 3 [(validate.rules).bytes.min_len = 10];

example/prototool.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
protoc:
2-
version: 3.6.1
2+
version: 3.7.1
33
includes:
4-
- /include
4+
- /usr/include
55

66
lint:
77
rules:
@@ -15,17 +15,14 @@ generate:
1515
plugins:
1616
- name: gogofast
1717
type: gogo
18-
path: /bin/protoc-gen-gogofast
1918
flags: plugins=grpc
2019
output: ./go/pkg/gen
2120
- name: validate
22-
path: /bin/protoc-gen-validate
2321
flags: lang=go
2422
output: ./go/pkg/gen
2523
- name: java
2624
output: ./java/src/main/java
2725
- name: grpc-java
28-
path: /bin/protoc-gen-grpc-java
2926
output: ./java/src/main/java
3027

3128

prototool.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
#!/usr/bin/env bash
22

33
USER="$(id -u):$(id -g)"
4-
docker run --rm --user $USER -i -t -v $(pwd):/in charithe/prototool-docker $@
4+
docker run -it \
5+
--rm \
6+
--user $USER \
7+
--mount type=bind,source="$(pwd)",target=/work \
8+
--tmpfs /tmp:exec \
9+
charithe/prototool-docker prototool $@

0 commit comments

Comments
 (0)