mirror of
https://github.com/yzernik/squeaknode.git
synced 2026-08-18 13:09:08 +02:00
Add envoy proxy (#95)
* Add envoy proxy * Add frontend, still not working * Open port to frontend * Fix static html page * Fix url in client js code, but CORS is still blocked * Successfully make request from browser to sqkserver through proxy * Expose ports for sqkserver in docker * Remove unused frontend files * Remove duplicate envoy config file
This commit is contained in:
parent
235ec52b03
commit
a45c3b62be
11 changed files with 223 additions and 0 deletions
|
|
@ -41,7 +41,9 @@ services:
|
|||
- ./config.ini:/app/config.ini
|
||||
ports:
|
||||
- 8774:8774
|
||||
- 8994:8994
|
||||
- 18774:18774
|
||||
- 18994:18994
|
||||
links:
|
||||
- "lnd:lnd"
|
||||
depends_on:
|
||||
|
|
|
|||
20
docker/envoy/Dockerfile
Normal file
20
docker/envoy/Dockerfile
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Copyright 2018 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
FROM envoyproxy/envoy:v1.15.0
|
||||
|
||||
# COPY "docker/envoy/envoy.yaml" /etc/envoy/envoy.yaml
|
||||
COPY "frontend/envoy.yaml" /etc/envoy/envoy.yaml
|
||||
|
||||
CMD /usr/local/bin/envoy -c /etc/envoy/envoy.yaml -l trace --log-path /tmp/envoy_info.log
|
||||
47
docker/frontend/Dockerfile
Normal file
47
docker/frontend/Dockerfile
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# Copyright 2018 Google LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
FROM node:10-stretch
|
||||
|
||||
RUN apt-get -qq update && apt-get -qq install -y \
|
||||
unzip
|
||||
|
||||
WORKDIR /tmp
|
||||
|
||||
RUN curl -sSL https://github.com/protocolbuffers/protobuf/releases/download/v3.12.2/\
|
||||
protoc-3.12.2-linux-x86_64.zip -o protoc.zip && \
|
||||
unzip -qq protoc.zip && \
|
||||
cp ./bin/protoc /usr/local/bin/protoc
|
||||
|
||||
RUN curl -sSL https://github.com/grpc/grpc-web/releases/download/1.2.0/\
|
||||
protoc-gen-grpc-web-1.2.0-linux-x86_64 -o /usr/local/bin/protoc-gen-grpc-web && \
|
||||
chmod +x /usr/local/bin/protoc-gen-grpc-web
|
||||
|
||||
COPY frontend .
|
||||
|
||||
RUN mkdir proto
|
||||
COPY proto/squeak_admin.proto proto/
|
||||
RUN curl -o rpc.proto -s https://raw.githubusercontent.com/lightningnetwork/lnd/master/lnrpc/rpc.proto
|
||||
RUN cp rpc.proto proto/lnd.proto
|
||||
|
||||
RUN protoc -I=. proto/squeak_admin.proto proto/lnd.proto \
|
||||
--js_out=import_style=commonjs:. \
|
||||
--grpc-web_out=import_style=commonjs,mode=grpcwebtext:.
|
||||
|
||||
RUN npm install && \
|
||||
npm link grpc-web && \
|
||||
npx webpack client.js
|
||||
|
||||
EXPOSE 8081
|
||||
CMD ["python", "-m", "SimpleHTTPServer", "8081"]
|
||||
|
|
@ -33,6 +33,9 @@ RUN ./install-rpc.sh
|
|||
RUN python3 setup.py install
|
||||
|
||||
EXPOSE 8774
|
||||
EXPOSE 8994
|
||||
EXPOSE 18774
|
||||
EXPOSE 18994
|
||||
|
||||
# Copy the entrypoint script.
|
||||
COPY "docker/sqkserver/start-sqkserver.sh" .
|
||||
|
|
|
|||
33
frontend/client.js
Normal file
33
frontend/client.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2018 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
const {HelloRequest,
|
||||
HelloReply} = require('./proto/squeak_admin_pb.js');
|
||||
const {SqueakAdminClient} = require('./proto/squeak_admin_grpc_web_pb.js');
|
||||
|
||||
var client = new SqueakAdminClient('http://' + window.location.hostname + ':8080',
|
||||
null, null);
|
||||
|
||||
var request = new HelloRequest();
|
||||
request.setName('World');
|
||||
|
||||
console.log('Testing...');
|
||||
|
||||
client.sayHello(request, {}, (err, response) => {
|
||||
console.log(response.getMessage());
|
||||
});
|
||||
54
frontend/envoy.yaml
Normal file
54
frontend/envoy.yaml
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
admin:
|
||||
access_log_path: /tmp/admin_access.log
|
||||
address:
|
||||
socket_address: { address: 0.0.0.0, port_value: 9901 }
|
||||
|
||||
static_resources:
|
||||
listeners:
|
||||
- name: listener_0
|
||||
address:
|
||||
socket_address: { address: 0.0.0.0, port_value: 8080 }
|
||||
filter_chains:
|
||||
- filters:
|
||||
- name: envoy.filters.network.http_connection_manager
|
||||
typed_config:
|
||||
"@type": type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager
|
||||
codec_type: auto
|
||||
stat_prefix: ingress_http
|
||||
route_config:
|
||||
name: local_route
|
||||
virtual_hosts:
|
||||
- name: local_service
|
||||
domains: ["*"]
|
||||
routes:
|
||||
- match: { prefix: "/" }
|
||||
route:
|
||||
cluster: squeak_admin_service
|
||||
max_grpc_timeout: 0s
|
||||
cors:
|
||||
allow_origin_string_match:
|
||||
- prefix: "*"
|
||||
allow_methods: GET, PUT, DELETE, POST, OPTIONS
|
||||
allow_headers: keep-alive,user-agent,cache-control,content-type,content-transfer-encoding,custom-header-1,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout
|
||||
max_age: "1728000"
|
||||
expose_headers: custom-header-1,grpc-status,grpc-message
|
||||
http_filters:
|
||||
- name: envoy.filters.http.grpc_web
|
||||
- name: envoy.filters.http.cors
|
||||
- name: envoy.filters.http.router
|
||||
clusters:
|
||||
- name: squeak_admin_service
|
||||
connect_timeout: 0.25s
|
||||
type: logical_dns
|
||||
http2_protocol_options: {}
|
||||
lb_policy: round_robin
|
||||
# win/mac hosts: Use address: host.docker.internal instead of address: localhost in the line below
|
||||
load_assignment:
|
||||
cluster_name: cluster_0
|
||||
endpoints:
|
||||
- lb_endpoints:
|
||||
- endpoint:
|
||||
address:
|
||||
socket_address:
|
||||
address: sqkserver
|
||||
port_value: 8994
|
||||
11
frontend/index.html
Normal file
11
frontend/index.html
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>gRPC-Web Example</title>
|
||||
<script src="./dist/main.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<p>Open up the developer console and see the logs for the output.</p>
|
||||
</body>
|
||||
</html>
|
||||
16
frontend/package.json
Normal file
16
frontend/package.json
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "grpc-web-simple-example",
|
||||
"version": "0.1.0",
|
||||
"description": "gRPC-Web simple example",
|
||||
"main": "server.js",
|
||||
"devDependencies": {
|
||||
"@grpc/grpc-js": "~1.0.5",
|
||||
"@grpc/proto-loader": "~0.5.4",
|
||||
"async": "~1.5.2",
|
||||
"google-protobuf": "~3.12.0",
|
||||
"grpc-web": "~1.2.0",
|
||||
"lodash": "~4.17.0",
|
||||
"webpack": "~4.43.0",
|
||||
"webpack-cli": "~3.3.11"
|
||||
}
|
||||
}
|
||||
|
|
@ -100,6 +100,11 @@ services:
|
|||
- test_shared:/rpc
|
||||
- test_lnd_server_dir:/root/.lnd
|
||||
- ./config.ini:/app/config.ini
|
||||
ports:
|
||||
- 8774:8774
|
||||
- 8994:8994
|
||||
- 18774:18774
|
||||
- 18994:18994
|
||||
links:
|
||||
- "btcd:btcd"
|
||||
- "lnd_server:lnd"
|
||||
|
|
@ -122,6 +127,26 @@ services:
|
|||
- "lnd_client:lnd"
|
||||
command: tail -f /dev/null
|
||||
|
||||
envoy:
|
||||
image: envoy
|
||||
container_name: test_envoy
|
||||
build:
|
||||
context: ../
|
||||
dockerfile: docker/envoy/Dockerfile
|
||||
ports:
|
||||
- 8080:8080
|
||||
links:
|
||||
- "sqkserver:sqkserver"
|
||||
|
||||
frontend:
|
||||
image: frontend
|
||||
container_name: test_frontend
|
||||
build:
|
||||
context: ../
|
||||
dockerfile: docker/frontend/Dockerfile
|
||||
ports:
|
||||
- 8081:8081
|
||||
|
||||
volumes:
|
||||
# btcctl and lnd containers.
|
||||
test_shared:
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ import "proto/lnd.proto";
|
|||
// Interface exported by the server.
|
||||
service SqueakAdmin {
|
||||
|
||||
rpc SayHello (HelloRequest) returns (HelloReply);
|
||||
|
||||
/** sqkadmin: `getsqueak`
|
||||
*/
|
||||
rpc GetBalance (GetBalanceRequest) returns (GetBalanceReply) {}
|
||||
|
|
@ -38,6 +40,13 @@ service SqueakAdmin {
|
|||
|
||||
}
|
||||
|
||||
message HelloRequest {
|
||||
string name = 1;
|
||||
}
|
||||
|
||||
message HelloReply {
|
||||
string message = 1;
|
||||
}
|
||||
message GetBalanceRequest {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,9 @@ class SqueakAdminServerServicer(squeak_admin_pb2_grpc.SqueakAdminServicer):
|
|||
self.port = port
|
||||
self.handler = handler
|
||||
|
||||
def SayHello(self, request, context):
|
||||
return squeak_admin_pb2.HelloReply(message='Hello, %s!' % request.name)
|
||||
|
||||
def GetBalance(self, request, context):
|
||||
wallet_balance_response = self.handler.handle_get_balance()
|
||||
return squeak_admin_pb2.GetBalanceReply(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue