Skip to content

Commit 3f710c5

Browse files
author
Alexander Indenbaum
committed
build: add build-time protobuf generation infrastructure
Signed-off-by: Alexander Indenbaum <aindenba@redhat.com>
1 parent 1f2706f commit 3f710c5

File tree

8 files changed

+1047
-9
lines changed

8 files changed

+1047
-9
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# yamllint disable rule:truthy
2+
---
3+
name: Check Proto Changes
4+
5+
on:
6+
pull_request:
7+
paths:
8+
- 'internal/nvme/gateway/proto/gateway.proto'
9+
- 'build.env'
10+
push:
11+
branches:
12+
- devel
13+
paths:
14+
- 'internal/nvme/gateway/proto/gateway.proto'
15+
- 'build.env'
16+
17+
jobs:
18+
check-proto-changes:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
24+
with:
25+
fetch-depth: 0
26+
27+
- name: Verify committed proto file matches build.env specification
28+
# yamllint disable rule:line-length
29+
run: |
30+
# Source build.env to get version information
31+
source build.env
32+
33+
# Fetch the specific version from ceph-nvmeof based on build.env
34+
echo "Fetching proto file from ${PROTO_SOURCE_REPO} branch " \
35+
"${PROTO_SOURCE_BRANCH} SHA ${PROTO_SOURCE_SHA}..."
36+
37+
# Create fetch URL, handle 'latest' case
38+
if [[ "${PROTO_SOURCE_SHA}" == "latest" ]]; then
39+
# Fetch from branch tip
40+
FETCH_URL="${PROTO_SOURCE_REPO}/raw/refs/heads/${PROTO_SOURCE_BRANCH}/control/proto/gateway.proto"
41+
else
42+
# Fetch from specific SHA
43+
FETCH_URL="${PROTO_SOURCE_REPO}/raw/${PROTO_SOURCE_SHA}/control/proto/gateway.proto"
44+
fi
45+
46+
# Fetch proto file
47+
curl -fsSL "${FETCH_URL}" -o /tmp/gateway.proto.expected
48+
49+
# Normalize the committed proto file by removing go_package option
50+
echo "Normalizing committed proto file (removing go_package option)..."
51+
grep -v "option go_package" internal/nvme/gateway/proto/gateway.proto > \
52+
/tmp/gateway.proto.normalized
53+
54+
# Compare normalized committed file with fetched file
55+
if diff -u /tmp/gateway.proto.normalized /tmp/gateway.proto.expected; then
56+
echo "✅ Committed proto file matches build.env specification"
57+
echo " Repository: ${PROTO_SOURCE_REPO}"
58+
echo " Branch: ${PROTO_SOURCE_BRANCH}"
59+
echo " SHA: ${PROTO_SOURCE_SHA}"
60+
echo " Note: go_package option is added by the build process"
61+
else
62+
echo "❌ Committed proto file does not match build.env specification"
63+
echo " Expected: ${PROTO_SOURCE_REPO} branch ${PROTO_SOURCE_BRANCH} SHA " \
64+
"${PROTO_SOURCE_SHA}"
65+
echo " Please update the committed proto file to match the build.env specification"
66+
exit 1
67+
fi

Makefile

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,23 @@ commitlint:
168168
@test $(REBASE) -eq 0 || git -c user.name=commitlint -c user.email=commitline@localhost rebase FETCH_HEAD
169169
commitlint --verbose --from $(GIT_SINCE)
170170

171-
.PHONY: cephcsi
172-
cephcsi: check-env
171+
.PHONY: cephcsi generate-proto clean-proto force-generate-proto
172+
cephcsi: check-env generate-proto
173173
if [ ! -d ./vendor ]; then (go mod tidy && go mod vendor); fi
174174
GOOS=linux go build $(GO_TAGS) -mod vendor -a -ldflags '$(LDFLAGS)' -o _output/cephcsi ./cmd/
175175

176+
generate-proto: check-env
177+
@echo "Generating protobuf stubs..."
178+
./scripts/generate-proto.sh
179+
180+
clean-proto: check-env
181+
@echo "Cleaning protobuf generated files..."
182+
./scripts/generate-proto.sh --clean
183+
184+
force-generate-proto: check-env
185+
@echo "Force regenerating protobuf stubs..."
186+
./scripts/generate-proto.sh --force
187+
176188
e2e.test: check-env
177189
cd e2e && go test $(GO_TAGS) -mod=vendor -c -o ../e2e.test ./
178190

@@ -217,6 +229,9 @@ containerized-build: TARGET = cephcsi
217229
containerized-build: .container-cmd .devel-container-id
218230
$(CONTAINER_CMD) run --rm -v $(CURDIR):/go/src/github.com/ceph/ceph-csi$(SELINUX_VOL_FLAG) $(CSI_IMAGE_NAME):devel make $(TARGET) CONTAINERIZED=yes
219231

232+
containerized-generate-proto: .container-cmd .devel-container-id
233+
$(CONTAINER_CMD) run --rm -v $(CURDIR):/go/src/github.com/ceph/ceph-csi$(SELINUX_VOL_FLAG) $(CSI_IMAGE_NAME):devel make generate-proto CONTAINERIZED=yes
234+
220235
containerized-test: TARGET = test
221236
containerized-test: REBASE ?= 0
222237
containerized-test: .container-cmd .test-container-id
@@ -272,6 +287,7 @@ clean:
272287
rm -f _output/cephcsi
273288
$(RM) scripts/golangci.yml
274289
$(RM) e2e.test
290+
rm -f internal/nvme/gateway/proto/*.pb.go
275291
[ ! -f .devel-container-id ] || $(CONTAINER_CMD) rmi $(CSI_IMAGE_NAME):devel
276292
$(RM) .devel-container-id
277293
[ ! -f .test-container-id ] || $(CONTAINER_CMD) rmi $(CSI_IMAGE_NAME):test

build.env

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ COMMITLINT_VERSION=latest
3535
# static checks and linters
3636
GOLANGCI_VERSION=v2.1.5
3737

38+
# protobuf tool versions
39+
PROTOC_VERSION=3.14.0
40+
PROTOC_GEN_GO_VERSION=v1.36.6
41+
PROTOC_GEN_GO_GRPC_VERSION=v1.5.1
42+
43+
# protobuf source configuration
44+
# Using committed gateway.proto file instead of fetching
45+
# The committed file should match the current devel branch tip
46+
PROTO_SOURCE_REPO=https://github.com/ceph/ceph-nvmeof
47+
PROTO_SOURCE_BRANCH=devel
48+
PROTO_SOURCE_SHA=latest
49+
# 'latest' for branch tip, or specific commit SHA for reproducible builds
50+
3851
# external snapshotter version
3952
# Refer: https://github.com/kubernetes-csi/external-snapshotter/releases
4053
SNAPSHOT_VERSION=v8.2.0

deploy/cephcsi/image/Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ RUN source /build.env && \
4040
# test if the downloaded version of Golang works (different arch?)
4141
RUN ${GOROOT}/bin/go version && ${GOROOT}/bin/go env
4242

43-
# other/conflicting versions of protobuf get installed as dependency
44-
RUN dnf -y remove protobuf
45-
4643
RUN dnf -y install --nodocs \
4744
librados-devel librbd-devel libcephfs-devel \
4845
/usr/bin/cc \
4946
make \
5047
git \
48+
protobuf-compiler \
5149
&& dnf clean all \
5250
&& rm -rf /var/cache/yum \
5351
&& true
@@ -60,6 +58,10 @@ ENV GOROOT=${GOROOT} \
6058
ENV_CSI_IMAGE_NAME="${CSI_IMAGE_NAME}" \
6159
PATH="${GOROOT}/bin:${GOPATH}/bin:${PATH}"
6260

61+
# Install Go protobuf plugins using versions from build.env
62+
RUN source /build.env \
63+
&& ${GOROOT}/bin/go install google.golang.org/protobuf/cmd/protoc-gen-go@${PROTOC_GEN_GO_VERSION} \
64+
&& ${GOROOT}/bin/go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@${PROTOC_GEN_GO_GRPC_VERSION}
6365

6466
WORKDIR ${SRC_DIR}
6567

0 commit comments

Comments
 (0)