Skip to content

Commit

Permalink
Merge pull request #7 from pubg/feature/types
Browse files Browse the repository at this point in the history
Introducing Dynamic TypeScript Type Generation from Envoy Proto Files
  • Loading branch information
bitofsky authored May 15, 2023
2 parents f68b0f7 + 9484298 commit c6cc5fa
Show file tree
Hide file tree
Showing 325 changed files with 10,500 additions and 418 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/test
.git
.gitignore
**/*.md
.repos
**/*.md
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@ dist

# TernJS port file
.tern-port

.repos
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

```bash
npm run generate-types
```
12 changes: 8 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
FROM node:20.1.0
ARG ENVOY_VERSION=v1.26.1

FROM envoyproxy/envoy:${ENVOY_VERSION} as envoy

FROM node:20.1.0 as base

RUN apt-get update && apt-get install -y \
curl \
Expand All @@ -9,16 +13,16 @@ RUN apt-get update && apt-get install -y \

WORKDIR /app

COPY --from=envoyproxy/envoy:v1.26.1 /usr/local/bin/envoy /usr/local/bin/envoy

COPY package*.json ./

RUN ["npm", "install", "--only=production"]
RUN ["npm", "install", "--omit=dev"]

COPY bin/run.sh .

RUN ["chmod", "+x", "/app/run.sh"]

COPY src ./src

COPY --from=envoy /usr/local/bin/envoy /usr/local/bin/envoy

CMD ["/app/run.sh"]
58 changes: 58 additions & 0 deletions bin/generate-types.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash -e
# This script is used to generate the typescript types for the envoy proto files.

# read ENVOY_VERSION from ../Dockerfile
ENVOY_VERSION=`grep 'ARG ENVOY_VERSION' Dockerfile | cut -d '=' -f 2`
echo "Generating types for envoy version $ENVOY_VERSION"

# Install the dependencies
echo "Installing dependencies"
npm install -g @grpc/proto-loader

# Clone the repos
echo "Cloning repos"
[ ! -d '.repos/envoy' ] && git clone --depth=1 --branch $ENVOY_VERSION [email protected]:envoyproxy/envoy.git .repos/envoy
[ ! -d '.repos/udpa' ] && git clone --depth=1 [email protected]:cncf/udpa.git .repos/udpa
[ ! -d '.repos/protoc-gen-validate' ] && git clone --depth=1 [email protected]:bufbuild/protoc-gen-validate.git .repos/protoc-gen-validate
[ ! -d '.repos/xds' ] && git clone --depth=1 [email protected]:cncf/xds.git .repos/xds

# Generate the types
echo "Generating types"
proto-loader-gen-types \
--keepCase \
--enums=string \
--json=true \
--grpcLib=@grpc/grpc-js \
-I .repos/envoy/api .repos/udpa .repos/protoc-gen-validate .repos/xds \
--outDir=types/ \
.repos/envoy/api/envoy/config/bootstrap/v3/bootstrap.proto \
.repos/envoy/api/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.proto \
.repos/envoy/api/envoy/extensions/filters/network/tcp_proxy/v3/tcp_proxy.proto \
.repos/envoy/api/envoy/extensions/access_loggers/file/v3/file.proto \
.repos/envoy/api/envoy/extensions/transport_sockets/tls/v3/tls.proto

# Cleanup
# echo "Cleaning up"
# rm -rf .repos

# Fix the generated types
echo "Fixing BoolValue"
cat > types/google/protobuf/BoolValue.ts << 'EOT'
// generate-types.sh generated
export type BoolValue = boolean;
export type BoolValue__Output = boolean;
EOT

echo "Fixing UInt32Value"
cat > types/google/protobuf/UInt32Value.ts << 'EOT'
// generate-types.sh generated
export type UInt32Value = number;
export type UInt32Value__Output = number;
EOT

echo "Fixing Duration"
cat > types/google/protobuf/Duration.ts << 'EOT'
// generate-types.sh generated
export type Duration = string;
export type Duration__Output = string;
EOT
2 changes: 1 addition & 1 deletion examples/grpc-mtls/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
echo-client (insecure) -> simple-grpc-router (mTLS) -> simple-grpc-router (mTLS) -> echo-server (insecure)

```bash
docker-compose up
npm run grpc-mtls
```
```bash
...
Expand Down
2 changes: 1 addition & 1 deletion examples/grpc-test/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
echo-client - echo-server

```bash
docker-compose up
npm run grpc-test
```
```bash
...
Expand Down
Loading

0 comments on commit c6cc5fa

Please sign in to comment.