Skip to content

Commit

Permalink
feat: refactor build grpc (#6)
Browse files Browse the repository at this point in the history
- add grpc-tools to dev dep
- use submodule to import layotto
- mv pb to proto/runtime/v1 prepare for proto/extension/v1
  • Loading branch information
killagu authored Oct 13, 2022
1 parent a21e11d commit 08df5b7
Show file tree
Hide file tree
Showing 39 changed files with 275 additions and 13,658 deletions.
30 changes: 28 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,50 @@ on:
jobs:
build:
runs-on: ${{ matrix.os }}
services:
redis:
image: redis
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
etcd:
image: bitnami/etcd
env:
ALLOW_NONE_AUTHENTICATION: yes
ports:
- 2380:2379

strategy:
fail-fast: false
matrix:
node-version: [16]
os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest]

steps:
- name: Checkout Git Source
uses: actions/checkout@v2
with:
submodules: recursive

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Bootstrap layotto
run: |
cd demo
wget -q https://github.com/mosn/layotto/releases/download/v0.4.0/layotto.linux_amd64.zip
unzip layotto.linux_amd64.zip
chmod +x layotto
./layotto start -c ./config.json &
- name: Install Dependencies
run: npm i -g npminstall && npminstall
run: npm i

- name: Continuous Integration
run: npm run ci
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
coverage/
dist/
node_modules/
.idea
proto
.fleet
.DS_Store
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "layotto"]
path = layotto
url = git@github.com:mosn/layotto.git
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ The Layotto Node.js SDK to build your application.
[![Test coverage](https://img.shields.io/codecov/c/github/layotto/js-sdk.svg?style=flat-square)](https://codecov.io/gh/layotto/js-sdk)
[![Known Vulnerabilities](https://snyk.io/test/npm/layotto/badge.svg?style=flat-square)](https://snyk.io/test/npm/layotto)

## Clone
```shell
git clone --recurse-submodules git@github.com:layotto/js-sdk.git
```

If forgot to add `--recurse-submodules`, you can run `git submodule update --init --recursive` to clone the submodules.

More git submodule commands, please refer to [Git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules).

## Usage

### State
Expand Down Expand Up @@ -48,7 +57,6 @@ Should install [grpc-tools](https://github.com/grpc/grpc-node) first.
MacOS M1 follow [this issue](https://github.com/grpc/grpc-node/issues/1405).

```bash
npm install grpc-tools
npm run build:grpc
```

Expand Down
142 changes: 142 additions & 0 deletions demo/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{
"servers": [
{
"default_log_path": "stdout",
"default_log_level": "DEBUG",
"routers": [
{
"router_config_name": "actuator_dont_need_router"
}
],
"listeners": [
{
"name": "grpc",
"address": "127.0.0.1:34904",
"bind_port": true,
"filter_chains": [
{
"filters": [
{
"type": "grpc",
"config": {
"server_name": "runtime",
"grpc_config": {
"hellos": {
"helloworld": {
"type": "helloworld",
"hello": "greeting"
}
},
"state": {
"state_demo": {
"type": "redis",
"metadata": {
"redisHost": "localhost:6379",
"redisPassword": ""
}
},
"redis": {
"type": "redis",
"metadata": {
"redisHost": "localhost:6379",
"redisPassword": ""
}
}
},
"config_store": {
},
"sequencer": {
"sequencer_demo": {
"type": "redis",
"metadata": {
"redisHost": "localhost:6379",
"redisPassword": ""
}
},
"etcd": {
"type": "redis",
"metadata": {
"redisHost": "localhost:6379",
"redisPassword": ""
}
}
},
"lock": {
"lock_demo": {
"type": "redis",
"metadata": {
"redisHost": "localhost:6379",
"redisPassword": ""
}
},
"redis": {
"type": "redis",
"metadata": {
"redisHost": "localhost:6379",
"redisPassword": ""
}
}
},
"bindings": {
"http": {
"type": "http",
"metadata": {
"url": "https://mosn.io/layotto"
}
}
},
"pub_subs": {
"pub_subs_demo": {
"type": "redis",
"metadata": {
"redisHost": "localhost:6379",
"redisPassword": ""
}
},
"redis": {
"type": "redis",
"metadata": {
"redisHost": "localhost:6379",
"redisPassword": ""
}
}
},
"app": {
"app_id": "app1",
"grpc_callback_port": 9999
}
}
}
}
]
}
]
},
{
"name": "actuator",
"address": "127.0.0.1:34999",
"bind_port": true,
"filter_chains": [
{
"filters": [
{
"type": "proxy",
"config": {
"downstream_protocol": "Http1",
"upstream_protocol": "Http1",
"router_config_name": "actuator_dont_need_router"
}
}
]
}
],
"stream_filters": [
{
"type": "actuator_filter"
}
]
}
]
}
]
}
1 change: 1 addition & 0 deletions layotto
Submodule layotto added at 1507aa
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
"build:grpc": "scripts/build-grpc.sh",
"tsc:clean": "rm -rf dist",
"tsc:cjs": "tsc -p tsconfig.json",
"build": "npm run tsc:clean && npm run tsc:cjs",
"tsc:check": "tsc -p tsconfig.json --noEmit",
"build": "npm run tsc:clean && npm run build:grpc && npm run tsc:cjs",
"rename:cjs": "for f in cjs/*.js; do mv -- \"$f\" \"${f/.js/.cjs}\"; done",
"prepublishOnly": "npm run build"
"prepublishOnly": "npm run build",
"postinstall": "npm run build:grpc"
},
"repository": {
"type": "git",
Expand All @@ -40,15 +42,16 @@
"@eggjs/tsconfig": "^1.0.0",
"@types/google-protobuf": "^3.15.5",
"@types/jest": "^27.0.2",
"egg-ci": "^1.19.0",
"egg-ci": "^2.1.0",
"grpc_tools_node_protoc_ts": "^5.3.2",
"jest": "^27.2.5",
"ts-jest": "^27.0.7",
"ts-node": "^10.3.0",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"type-fest": "^2.5.2",
"typescript": "^4.4.4"
"typescript": "^4.4.4",
"grpc-tools": "^1.11.3"
},
"dependencies": {
"@grpc/grpc-js": "^1.4.1",
Expand All @@ -60,8 +63,6 @@
"ci": {
"version": "16",
"type": "github",
"os": {
"github": "linux, macos"
}
"os": [ "linux", "macos" ]
}
}
59 changes: 0 additions & 59 deletions proto/appcallback_grpc_pb.d.ts

This file was deleted.

Loading

0 comments on commit 08df5b7

Please sign in to comment.