Skip to content

Commit 880f79c

Browse files
authored
Generate protobuf code for TypeScript service - Frontend (open-telemetry#1954)
* Generate protobuf code for Typescript service - Frontend * additional changes for generating protobuf open-telemetry#1787 * Included generated files open-telemetry#1787 * Ignore copyright license for generated proto open-telemetry#1787 * Update MakeFile to clean working directory open-telemetry#1787 * Update Generated proto open-telemetry#1787 * chore: update CHANGELOG.md
1 parent 75cfdc0 commit 880f79c

11 files changed

+4063
-11
lines changed

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ test/tracetesting/tracetesting-vars.yaml
4444
/src/accounting/src/protos/
4545
/src/cart/src/protos/
4646
/src/fraud-detection/src/main/proto
47-
/src/frontend/pb/
48-
/src/frontend/protos/
4947
/src/payment/demo.proto
5048
/src/shipping/proto/
5149
/src/currency/proto

.licenserc.json

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"src/react-native-app/expo-env.d.ts",
5353
"src/recommendation/demo_pb2.py",
5454
"src/recommendation/demo_pb2_grpc.py",
55+
"src/frontend/protos/demo.ts",
5556
"internal/tools/"
5657
]
5758
}

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ the release.
7676
([#1923](https://github.com/open-telemetry/opentelemetry-demo/pull/1923))
7777
* [chore] Add memory for frontend-proxy, kafka, grafana, opensearch
7878
([#1931](https://github.com/open-telemetry/opentelemetry-demo/pull/1931))
79+
* [chore] Generate protobuf code for Typescript service - Frontend
80+
([#1954](https://github.com/open-telemetry/opentelemetry-demo/pull/1954))
7981

8082
## 1.12.0
8183

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ docker-generate-protobuf:
150150
clean:
151151
rm -rf ./src/{checkout,product-catalog}/genproto/oteldemo/
152152
rm -rf ./src/recommendation/{demo_pb2,demo_pb2_grpc}.py
153+
rm -rf ./src/frontend/protos/demo.ts
153154

154155
.PHONY: check-clean-work-tree
155156
check-clean-work-tree:

docker-gen-proto.sh

+14-1
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,27 @@ gen_proto_python() {
3030
python -m grpc_tools.protoc -I /build/pb/ --python_out="./src/$1/" --grpc_python_out="./src/$1/" /build/pb/demo.proto
3131
}
3232

33+
gen_proto_ts() {
34+
echo "Generating Typescript protobuf files for $1"
35+
docker build -f "src/$1/genproto/Dockerfile" -t "$1-genproto" .
36+
docker run --rm -e SERVICE=$1 -v $(pwd):/build "$1-genproto" /bin/sh -c '
37+
mkdir -p /build/src/$SERVICE/protos && \
38+
protoc -I /build/pb \
39+
--plugin=protoc-gen-ts_proto=/app/node_modules/.bin/protoc-gen-ts_proto \
40+
--ts_proto_opt=esModuleInterop=true \
41+
--ts_proto_out="/build/src/$SERVICE/protos" \
42+
--ts_proto_opt=outputServices=grpc-js \
43+
/build/pb/demo.proto'
44+
}
45+
3346
if [ -z "$1" ]; then
3447
#gen_proto_dotnet accounting
3548
#gen_proto_java ad
3649
#gen_proto_dotnet cart
3750
gen_proto_go checkout
3851
gen_proto_cpp currency
3952
#gen_proto_ruby email
40-
#gen_proto_ts frontend
53+
gen_proto_ts frontend
4154
#gen_proto_js payment
4255
gen_proto_go product-catalog
4356
#gen_proto_php quote

src/frontend/.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ build
44
dist
55
.husky
66
node_modules
7+
protos/

src/frontend/Dockerfile

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright The OpenTelemetry Authors
22
# SPDX-License-Identifier: Apache-2.0
33

4-
54
FROM node:20-alpine AS deps
65
RUN apk add --no-cache libc6-compat
76

@@ -11,18 +10,16 @@ COPY ./src/frontend/package*.json ./
1110
RUN npm ci
1211

1312
FROM node:20-alpine AS builder
14-
RUN apk add --no-cache libc6-compat protobuf-dev protoc
13+
RUN apk add --no-cache libc6-compat
1514
WORKDIR /app
1615
COPY --from=deps /app/node_modules ./node_modules
17-
COPY ./pb ./pb
16+
COPY ./src/frontend/protos ./protos
1817
COPY ./src/frontend .
1918

20-
RUN npm run grpc:generate
2119
RUN npm run build
2220

2321
FROM node:20-alpine AS runner
2422
WORKDIR /app
25-
RUN apk add --no-cache protobuf-dev protoc
2623

2724
ENV NODE_ENV=production
2825

src/frontend/genproto/Dockerfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
FROM node:20-alpine
5+
6+
WORKDIR /app
7+
8+
RUN apk add --no-cache libc6-compat protobuf-dev protoc
9+
10+
COPY ./src/frontend/package*.json ./
11+
12+
RUN npm ci
13+
14+
COPY ./pb /build/pb

src/frontend/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
6-
"dev": "npm run grpc:generate && NODE_OPTIONS='-r ./utils/telemetry/Instrumentation.js' next dev",
6+
"dev": "NODE_OPTIONS='-r ./utils/telemetry/Instrumentation.js' next dev",
77
"build": "next build",
88
"start": "node --require ./Instrumentation.js server.js",
99
"lint": "next lint",
@@ -44,7 +44,6 @@
4444
"react-dom": "19.0.0",
4545
"sharp": "0.33.5",
4646
"styled-components": "6.1.14",
47-
"ts-proto": "1.181.1",
4847
"uuid": "11.0.5"
4948
},
5049
"devDependencies": {
@@ -61,6 +60,7 @@
6160
"eslint-plugin-react": "7.37.4",
6261
"eslint-plugin-react-hooks": "5.1.0",
6362
"openapi-typescript": "7.5.2",
63+
"ts-proto": "1.181.1",
6464
"typescript": "5.7.3"
6565
}
6666
}

0 commit comments

Comments
 (0)