Skip to content

Commit

Permalink
Generate protobuf code for Typescript service - Frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
Sozhan308 committed Jan 25, 2025
1 parent 98e85e1 commit a544937
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 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
8 changes: 7 additions & 1 deletion docker-gen-proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@ 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 -v $(pwd):/build "$1-genproto"
}

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
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
13 changes: 13 additions & 0 deletions src/frontend/genproto/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

FROM node:20-alpine

WORKDIR /build

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

COPY ./src/frontend/package*.json ./
RUN npm ci

CMD ["npm", "run", "grpc:generate"]
2 changes: 1 addition & 1 deletion 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

0 comments on commit a544937

Please sign in to comment.