Skip to content

Commit 0b12995

Browse files
authored
Merge pull request #24 from ezimanyi/reproducible-proto
feat(stats): Ensure reproducible proto compilation
2 parents adaabf3 + 0994d9c commit 0b12995

7 files changed

Lines changed: 101 additions & 28 deletions

File tree

.github/workflows/ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Stats CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
build:
11+
if: startsWith(github.repository, 'spinnaker/')
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Ensure autogenerated protos match checked-in protos
16+
run: make checkproto

Dockerfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ FROM mirror.gcr.io/library/golang as builder
33
ADD . /workspace
44
WORKDIR /workspace
55

6-
RUN ./proto/regen-protos.sh
7-
86
ENV GOPROXY=https://proxy.golang.org
97
ENV GO111MODULE=on
108
ENV CGO_ENABLED=0

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
protobuilder:
2+
docker build -q -t stats-protobuilder:latest build/protoc/
3+
4+
proto_command = docker run --rm -v $(abspath proto/stats):/output/go stats-protobuilder:latest
5+
6+
proto: protobuilder
7+
$(proto_command) update
8+
9+
checkproto: protobuilder
10+
$(proto_command) check

build/protoc/Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM alpine:3.12.0 as curl
2+
RUN apk add --no-cache curl unzip
3+
4+
FROM curl as protoc
5+
ARG PROTOC_VERSION=3.9.0
6+
RUN curl -vLo protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip \
7+
&& unzip protoc.zip
8+
9+
FROM curl as protoc-gen-go
10+
ARG PROTOC_GEN_GO_TAG=v1.23.0
11+
RUN curl -L https://github.com/protocolbuffers/protobuf-go/releases/download/$PROTOC_GEN_GO_TAG/protoc-gen-go.$PROTOC_GEN_GO_TAG.linux.amd64.tar.gz \
12+
| tar -xz
13+
14+
FROM golang:1.14.4-buster as protoc-gen-go-json
15+
ARG PROTOC_GEN_GO_JSON_TAG=069933b8c8344593ed8905d46d59c6647c886f47
16+
RUN go get -d github.com/mitchellh/protoc-gen-go-json \
17+
&& git -C "$(go env GOPATH)"/src/github.com/mitchellh/protoc-gen-go-json checkout $PROTOC_GEN_GO_JSON_TAG \
18+
&& go install github.com/mitchellh/protoc-gen-go-json
19+
20+
FROM curl as kork
21+
ARG KORK_VERSION=7.45.9
22+
RUN curl -L https://github.com/spinnaker/kork/archive/v$KORK_VERSION.tar.gz | tar -xz \
23+
&& mv kork-$KORK_VERSION kork
24+
25+
FROM debian:buster-slim
26+
COPY --from=protoc /bin/protoc /usr/local/bin/protoc
27+
COPY --from=protoc /include/google /usr/local/include/google
28+
COPY --from=protoc-gen-go /protoc-gen-go /usr/local/bin/protoc-gen-go
29+
COPY --from=protoc-gen-go-json /go/bin/protoc-gen-go-json /bin/
30+
COPY --from=kork /kork/kork-proto/src/main/proto/stats/ /proto/
31+
RUN mkdir -p /output /staging/go
32+
COPY genproto.sh .
33+
ENTRYPOINT ["./genproto.sh"]

build/protoc/genproto.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/sh
2+
set -e
3+
4+
PROTOC_FLAGS=""
5+
6+
gen_proto() {
7+
output_dir=$1
8+
find /proto -name *.proto | sort | xargs protoc \
9+
$PROTOC_FLAGS \
10+
--proto_path=/proto \
11+
--go_out=paths=source_relative:$1/go \
12+
--go-json_out=$1/go
13+
}
14+
15+
update_proto() {
16+
gen_proto /staging
17+
rm -rf /output/go/*
18+
cp -r /staging/go/* /output/go/
19+
}
20+
21+
check_proto() {
22+
gen_proto /staging
23+
if ! diff -r /staging /output; then
24+
echo "Protocol buffer compilation out of date. Please run 'make proto' and commit the changes."
25+
echo "To help with debugging, the difference between the committed and generated code is printed above."
26+
exit 1
27+
fi
28+
}
29+
30+
command=$1
31+
case $command in
32+
update)
33+
update_proto
34+
;;
35+
check)
36+
check_proto
37+
;;
38+
*)
39+
echo "Unrecognized command: $command"
40+
exit 2
41+
;;
42+
esac

proto/protoc

-4.74 MB
Binary file not shown.

proto/regen-protos.sh

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

0 commit comments

Comments
 (0)