Skip to content

Commit 1377204

Browse files
authored
Add grpc-ecosystem/grpc-gateway to spec base image (#757)
Add protoc-builder plugins to support OpenAPI annotations in protobuf generation. Signed-off-by: Colleen Murphy <[email protected]>
1 parent bf6fb41 commit 1377204

File tree

5 files changed

+44
-8
lines changed

5 files changed

+44
-8
lines changed

.github/workflows/googleapis-update.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,26 @@ jobs:
4343
--body "This pull request updates the DEFAULT_GOOGLEAPIS_COMMIT variable in protoc-builder/versions.mk with the latest commit hash from the googleapis/googleapis repository." \
4444
--base main \
4545
--head googleapis-${RUN_ID}
46+
47+
- name: Extract latest commit hash from grpc-ecosystem/grpc-gateway and create PR
48+
env:
49+
RUN_ID: ${{ github.run_id }}
50+
GH_TOKEN: ${{ secrets.GOOGLEAPIS_SIGSTOREBOT_TOKEN }}
51+
run: |
52+
(cd /tmp && git clone --depth=1 https://github.com/grpc-ecosystem/grpc-gateway)
53+
export LATEST_COMMIT_HASH=$(cd /tmp/grpc-gateway && git log -n 1 --format=%H)
54+
sed -i "s/^\(DEFAULT_GRPC_GATEWAY_COMMIT\s*=\s*\).*/\1${LATEST_COMMIT_HASH}/" protoc-builder/versions.mk
55+
56+
make all
57+
58+
git config user.name "Sigstore Bot"
59+
git config user.email "[email protected]"
60+
git config --global --type bool push.autoSetupRemote true
61+
git add -A
62+
git checkout -b grpc-gateway-${RUN_ID}
63+
git commit -sam "Update GRPC_GATEWAY_COMMIT in versions.mk"
64+
git push
65+
gh pr create --title "build(deps): bump github.com/grpc-ecosystem/grpc-gateway to latest commit in protoc-builder/versions.mk" \
66+
--body "This pull request updates the DEFAULT_GRPC_GATEWAY_COMMIT variable in protoc-builder/versions.mk with the latest commit hash from the grpc-ecosystem/grpc-gateway repository." \
67+
--base main \
68+
--head grpc-gateway-${RUN_ID}

Makefile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,39 +94,44 @@ base-image-go:
9494
cd protoc-builder && ${DOCKER_BUILD} ${DOCKER_CACHE} -t ${PROTOC_IMAGE}:go -f Dockerfile.protoc \
9595
--build-arg PROTOC_VERSION=${GO_PROTOC_VERSION} \
9696
--build-arg PROTOC_CHECKSUM=${GO_PROTOC_CHECKSUM} \
97-
--build-arg GOOGLEAPIS_COMMIT=${GO_GOOGLEAPIS_COMMIT} .
97+
--build-arg GOOGLEAPIS_COMMIT=${GO_GOOGLEAPIS_COMMIT} \
98+
--build-arg GRPC_GATEWAY_COMMIT=${GO_GRPC_GATEWAY_COMMIT} .
9899

99100
.PHONY: base-image-python
100101
base-image-python:
101102
@echo "Building base docker image for Python"
102103
cd protoc-builder && ${DOCKER_BUILD} ${DOCKER_CACHE} -t ${PROTOC_IMAGE}:python -f Dockerfile.protoc \
103104
--build-arg PROTOC_VERSION=${PYTHON_PROTOC_VERSION} \
104105
--build-arg PROTOC_CHECKSUM=${PYTHON_PROTOC_CHECKSUM} \
105-
--build-arg GOOGLEAPIS_COMMIT=${PYTHON_GOOGLEAPIS_COMMIT} .
106+
--build-arg GOOGLEAPIS_COMMIT=${PYTHON_GOOGLEAPIS_COMMIT} \
107+
--build-arg GRPC_GATEWAY_COMMIT=${PYTHON_GRPC_GATEWAY_COMMIT} .
106108

107109
.PHONY: base-image-ruby
108110
base-image-ruby:
109111
@echo "Building base docker image for Ruby"
110112
cd protoc-builder && ${DOCKER_BUILD} ${DOCKER_CACHE} -t ${PROTOC_IMAGE}:ruby -f Dockerfile.protoc \
111113
--build-arg PROTOC_VERSION=${RUBY_PROTOC_VERSION} \
112114
--build-arg PROTOC_CHECKSUM=${RUBY_PROTOC_CHECKSUM} \
113-
--build-arg GOOGLEAPIS_COMMIT=${RUBY_GOOGLEAPIS_COMMIT} .
115+
--build-arg GOOGLEAPIS_COMMIT=${RUBY_GOOGLEAPIS_COMMIT} \
116+
--build-arg GRPC_GATEWAY_COMMIT=${RUBY_GRPC_GATEWAY_COMMIT} .
114117

115118
.PHONY: base-image-rust
116119
base-image-rust:
117120
@echo "Building base docker image for Rust"
118121
cd protoc-builder && ${DOCKER_BUILD} ${DOCKER_CACHE} -t ${PROTOC_IMAGE}:rust -f Dockerfile.protoc \
119122
--build-arg PROTOC_VERSION=${RUST_PROTOC_VERSION} \
120123
--build-arg PROTOC_CHECKSUM=${RUST_PROTOC_CHECKSUM} \
121-
--build-arg GOOGLEAPIS_COMMIT=${RUST_GOOGLEAPIS_COMMIT} .
124+
--build-arg GOOGLEAPIS_COMMIT=${RUST_GOOGLEAPIS_COMMIT} \
125+
--build-arg GRPC_GATEWAY_COMMIT=${RUST_GRPC_GATEWAY_COMMIT} .
122126

123127
.PHONY: base-image-typescript
124128
base-image-typescript:
125129
@echo "Building base docker image for Typescript"
126130
cd protoc-builder && ${DOCKER_BUILD} ${DOCKER_CACHE} -t ${PROTOC_IMAGE}:typescript -f Dockerfile.protoc \
127131
--build-arg PROTOC_VERSION=${TYPESCRIPT_PROTOC_VERSION} \
128132
--build-arg PROTOC_CHECKSUM=${TYPESCRIPT_PROTOC_CHECKSUM} \
129-
--build-arg GOOGLEAPIS_COMMIT=${TYPESCRIPT_GOOGLEAPIS_COMMIT} .
133+
--build-arg GOOGLEAPIS_COMMIT=${TYPESCRIPT_GOOGLEAPIS_COMMIT} \
134+
--build-arg GRPC_GATEWAY_COMMIT=${TYPESCRIPT_GRPC_GATEWAY_COMMIT} .
130135

131136
# to recover from a situation where a stale layer exist, just purging the
132137
# docker image via `make clean` is not enough. Re-building without layer

protoc-builder/Dockerfile.protoc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
FROM debian:bullseye-slim@sha256:b5f9bc44bdfbd9d551dfdd432607cbc6bb5d9d6dea726a1191797d7749166973 AS protoc-builder
66

77
# Create output directories
8-
RUN mkdir /protobuf /googleapis
8+
RUN mkdir /protobuf /googleapis /grpc-gateway
99
# Install needed utilities
1010
RUN apt-get update && apt-get install -y unzip git
1111

@@ -15,7 +15,7 @@ ARG UID
1515
RUN adduser --uid ${UID} --disabled-password myuser
1616

1717
# Set permissions on the output directories so the user can write to them
18-
RUN chown myuser /protobuf /googleapis
18+
RUN chown myuser /protobuf /googleapis /grpc-gateway
1919

2020
# Switch to user to execute the remaining commands
2121
USER myuser
@@ -33,7 +33,12 @@ RUN chmod 755 /protobuf/bin/protoc
3333
ARG GOOGLEAPIS_COMMIT
3434
RUN git clone --filter=tree:0 https://github.com/googleapis/googleapis.git /googleapis && \
3535
cd /googleapis && git checkout ${GOOGLEAPIS_COMMIT}
36+
# fetch sparse checkout of grpc-gateway to add openapiv2/options
37+
ARG GRPC_GATEWAY_COMMIT
38+
RUN git clone --filter=tree:0 --no-checkout --sparse https://github.com/grpc-ecosystem/grpc-gateway.git /grpc-gateway && \
39+
cd /grpc-gateway && git sparse-checkout add protoc-gen-openapiv2/options && git checkout ${GRPC_GATEWAY_COMMIT}
3640

3741
FROM scratch
3842
COPY --from=protoc-builder /protobuf /protobuf
3943
COPY --from=protoc-builder /googleapis /googleapis
44+
COPY --from=protoc-builder /grpc-gateway /grpc-gateway

protoc-builder/Dockerfile.services

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ ARG GO_BASE # no default
33
FROM ${GO_BASE}
44

55
COPY /protos /protobuf-specs
6+
COPY --from=protoc-base:go /grpc-gateway /grpc-gateway
67

78
# just add the plugins for grpc-gateway and openapiv2 into the entrypoint
89
ENTRYPOINT ["/usr/local/bin/protoc", \

protoc-builder/versions.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ DEFAULT_PROTOC_CHECKSUM=sha256:327e9397c6fb3ea2a542513a3221334c6f76f7aa524a7d256
1616

1717
# git commit from https://github.com/googleapis/googleapis
1818
DEFAULT_GOOGLEAPIS_COMMIT=376467058c288ad34dd7aafa892a95883e4acd0c
19+
# git commit from https://github.com/grpc-ecosystem/grpc-gateway
20+
DEFAULT_GRPC_GATEWAY_COMMIT=5757e1e4616289cf1ff6f2b6ec0673a43da7da54
1921

2022
##################################################################################
2123
### DO NOT EDIT BELOW THIS LINE, AS THESE VALUES ARE USED IN THE CORE MAKEFILE ###
2224
##################################################################################
2325

2426
LANGUAGES := GO PYTHON RUBY RUST TYPESCRIPT
25-
COMPONENTS := PROTOC_VERSION PROTOC_CHECKSUM GOOGLEAPIS_COMMIT
27+
COMPONENTS := PROTOC_VERSION PROTOC_CHECKSUM GOOGLEAPIS_COMMIT GRPC_GATEWAY_COMMIT
2628

2729
# This is creating each possible variable permutation, e.g.
2830
# GO_PROTOC_VERSION, etc

0 commit comments

Comments
 (0)