Skip to content

Commit

Permalink
Generate protobuf code for TypeScript service - Frontend (#1954)
Browse files Browse the repository at this point in the history
* Generate protobuf code for Typescript service - Frontend

* additional changes for generating protobuf #1787

* Included generated files #1787

* Ignore copyright license for generated proto #1787

* Update MakeFile to clean working directory #1787

* Update Generated proto #1787

* chore: update CHANGELOG.md
  • Loading branch information
Sozhan308 authored Jan 28, 2025
1 parent 75cfdc0 commit 880f79c
Show file tree
Hide file tree
Showing 11 changed files with 4,063 additions and 11 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ test/tracetesting/tracetesting-vars.yaml
/src/accounting/src/protos/
/src/cart/src/protos/
/src/fraud-detection/src/main/proto
/src/frontend/pb/
/src/frontend/protos/
/src/payment/demo.proto
/src/shipping/proto/
/src/currency/proto
Expand Down
1 change: 1 addition & 0 deletions .licenserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"src/react-native-app/expo-env.d.ts",
"src/recommendation/demo_pb2.py",
"src/recommendation/demo_pb2_grpc.py",
"src/frontend/protos/demo.ts",
"internal/tools/"
]
}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ the release.
([#1923](https://github.com/open-telemetry/opentelemetry-demo/pull/1923))
* [chore] Add memory for frontend-proxy, kafka, grafana, opensearch
([#1931](https://github.com/open-telemetry/opentelemetry-demo/pull/1931))
* [chore] Generate protobuf code for Typescript service - Frontend
([#1954](https://github.com/open-telemetry/opentelemetry-demo/pull/1954))

## 1.12.0

Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ docker-generate-protobuf:
clean:
rm -rf ./src/{checkout,product-catalog}/genproto/oteldemo/
rm -rf ./src/recommendation/{demo_pb2,demo_pb2_grpc}.py
rm -rf ./src/frontend/protos/demo.ts

.PHONY: check-clean-work-tree
check-clean-work-tree:
Expand Down
15 changes: 14 additions & 1 deletion docker-gen-proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,27 @@ gen_proto_python() {
python -m grpc_tools.protoc -I /build/pb/ --python_out="./src/$1/" --grpc_python_out="./src/$1/" /build/pb/demo.proto
}

gen_proto_ts() {
echo "Generating Typescript protobuf files for $1"
docker build -f "src/$1/genproto/Dockerfile" -t "$1-genproto" .
docker run --rm -e SERVICE=$1 -v $(pwd):/build "$1-genproto" /bin/sh -c '
mkdir -p /build/src/$SERVICE/protos && \
protoc -I /build/pb \
--plugin=protoc-gen-ts_proto=/app/node_modules/.bin/protoc-gen-ts_proto \
--ts_proto_opt=esModuleInterop=true \
--ts_proto_out="/build/src/$SERVICE/protos" \
--ts_proto_opt=outputServices=grpc-js \
/build/pb/demo.proto'
}

if [ -z "$1" ]; then
#gen_proto_dotnet accounting
#gen_proto_java ad
#gen_proto_dotnet cart
gen_proto_go checkout
gen_proto_cpp currency
#gen_proto_ruby email
#gen_proto_ts frontend
gen_proto_ts frontend
#gen_proto_js payment
gen_proto_go product-catalog
#gen_proto_php quote
Expand Down
1 change: 1 addition & 0 deletions src/frontend/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ build
dist
.husky
node_modules
protos/
7 changes: 2 additions & 5 deletions src/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0


FROM node:20-alpine AS deps
RUN apk add --no-cache libc6-compat

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

FROM node:20-alpine AS builder
RUN apk add --no-cache libc6-compat protobuf-dev protoc
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY ./pb ./pb
COPY ./src/frontend/protos ./protos
COPY ./src/frontend .

RUN npm run grpc:generate
RUN npm run build

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

ENV NODE_ENV=production

Expand Down
14 changes: 14 additions & 0 deletions src/frontend/genproto/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

FROM node:20-alpine

WORKDIR /app

RUN apk add --no-cache libc6-compat protobuf-dev protoc

COPY ./src/frontend/package*.json ./

RUN npm ci

COPY ./pb /build/pb
4 changes: 2 additions & 2 deletions src/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "npm run grpc:generate && NODE_OPTIONS='-r ./utils/telemetry/Instrumentation.js' next dev",
"dev": "NODE_OPTIONS='-r ./utils/telemetry/Instrumentation.js' next dev",
"build": "next build",
"start": "node --require ./Instrumentation.js server.js",
"lint": "next lint",
Expand Down Expand Up @@ -44,7 +44,6 @@
"react-dom": "19.0.0",
"sharp": "0.33.5",
"styled-components": "6.1.14",
"ts-proto": "1.181.1",
"uuid": "11.0.5"
},
"devDependencies": {
Expand All @@ -61,6 +60,7 @@
"eslint-plugin-react": "7.37.4",
"eslint-plugin-react-hooks": "5.1.0",
"openapi-typescript": "7.5.2",
"ts-proto": "1.181.1",
"typescript": "5.7.3"
}
}
Loading

0 comments on commit 880f79c

Please sign in to comment.