From 6090e21f6a8d46b8754be1834aa9f9ae2b9a029e Mon Sep 17 00:00:00 2001 From: ShatteredBunny <110309244+ShatteredBunny@users.noreply.github.com> Date: Fri, 12 Aug 2022 18:29:27 +0200 Subject: [PATCH] Add grpc generation script and update setup.md to run it using docker container (#209) * Add grpc generation script and update setup.md to run it using docker container * Change local url from localhost to 127.0.0.1 --- Dockerfile | 15 +-------------- generate_grpc.sh | 18 ++++++++++++++++++ setup.md | 29 +++-------------------------- 3 files changed, 22 insertions(+), 40 deletions(-) create mode 100755 generate_grpc.sh diff --git a/Dockerfile b/Dockerfile index 2c012c19..2ae8e8b4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,20 +18,7 @@ RUN pip install --no-cache-dir -r requirements.txt COPY . . # install lnd grpc services -RUN cd api/lightning && git clone https://github.com/googleapis/googleapis.git -RUN cd api/lightning && curl -o lightning.proto -s https://raw.githubusercontent.com/lightningnetwork/lnd/master/lnrpc/lightning.proto -RUN cd api/lightning && python3 -m grpc_tools.protoc --proto_path=googleapis:. --python_out=. --grpc_python_out=. lightning.proto -RUN cd api/lightning && curl -o invoices.proto -s https://raw.githubusercontent.com/lightningnetwork/lnd/master/lnrpc/invoicesrpc/invoices.proto -RUN cd api/lightning && python3 -m grpc_tools.protoc --proto_path=googleapis:. --python_out=. --grpc_python_out=. invoices.proto -RUN cd api/lightning && curl -o router.proto -s https://raw.githubusercontent.com/lightningnetwork/lnd/master/lnrpc/routerrpc/router.proto -RUN cd api/lightning && python3 -m grpc_tools.protoc --proto_path=googleapis:. --python_out=. --grpc_python_out=. router.proto - -# patch generated files relative imports -RUN sed -i 's/^import .*_pb2 as/from . \0/' api/lightning/router_pb2.py -RUN sed -i 's/^import .*_pb2 as/from . \0/' api/lightning/invoices_pb2.py -RUN sed -i 's/^import .*_pb2 as/from . \0/' api/lightning/router_pb2_grpc.py -RUN sed -i 's/^import .*_pb2 as/from . \0/' api/lightning/lightning_pb2_grpc.py -RUN sed -i 's/^import .*_pb2 as/from . \0/' api/lightning/invoices_pb2_grpc.py +RUN sh generate_grpc.sh EXPOSE 8000 diff --git a/generate_grpc.sh b/generate_grpc.sh new file mode 100755 index 00000000..4fef7782 --- /dev/null +++ b/generate_grpc.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +# generate grpc definitions +cd api/lightning +[ -d googleapis ] || git clone https://github.com/googleapis/googleapis.git googleapis +curl -o lightning.proto -s https://raw.githubusercontent.com/lightningnetwork/lnd/master/lnrpc/lightning.proto +python3 -m grpc_tools.protoc --proto_path=googleapis:. --python_out=. --grpc_python_out=. lightning.proto +curl -o invoices.proto -s https://raw.githubusercontent.com/lightningnetwork/lnd/master/lnrpc/invoicesrpc/invoices.proto +python3 -m grpc_tools.protoc --proto_path=googleapis:. --python_out=. --grpc_python_out=. invoices.proto +curl -o router.proto -s https://raw.githubusercontent.com/lightningnetwork/lnd/master/lnrpc/routerrpc/router.proto +python3 -m grpc_tools.protoc --proto_path=googleapis:. --python_out=. --grpc_python_out=. router.proto + +# patch generated files relative imports +sed -i 's/^import .*_pb2 as/from . \0/' router_pb2.py +sed -i 's/^import .*_pb2 as/from . \0/' invoices_pb2.py +sed -i 's/^import .*_pb2 as/from . \0/' router_pb2_grpc.py +sed -i 's/^import .*_pb2 as/from . \0/' lightning_pb2_grpc.py +sed -i 's/^import .*_pb2 as/from . \0/' invoices_pb2_grpc.py diff --git a/setup.md b/setup.md index 88af2bd4..1440c87e 100644 --- a/setup.md +++ b/setup.md @@ -46,6 +46,8 @@ Make "{robosats-site}/static/css/index.css" redirect to "127.0.0.1:8080/css/inde Spinning up docker for the first time ``` docker-compose build --no-cache +# Install LND python dependencies into local repository +docker run --mount type=bind,src=$(pwd),dst=/usr/src/robosats backend sh generate_grpc.sh docker-compose up -d docker exec -it django-dev python3 manage.py makemigrations docker exec -it django-dev python3 manage.py migrate @@ -54,31 +56,6 @@ docker-compose restart ``` Copy the `.env-sample` file into `.env` and check the environmental variables are right for your development. -### (optional, if error) Install LND python dependencies -Depending on your system your dev setup might already be good to start working. However, it might happen that when mounting "." into "/src/usr/robosats" in the docker-compose.yml, it deletes the lnd grpc files that where previously generated during the docker build. If this is the case, run the following: -``` -cd api/lightning -pip install grpcio grpcio-tools googleapis-common-protos -git clone https://github.com/googleapis/googleapis.git -curl -o lightning.proto -s https://raw.githubusercontent.com/lightningnetwork/lnd/master/lnrpc/lightning.proto -python3 -m grpc_tools.protoc --proto_path=googleapis:. --python_out=. --grpc_python_out=. lightning.proto -``` -We also use the *Invoices* and *Router* subservices for invoice validation and payment routing. -``` -curl -o invoices.proto -s https://raw.githubusercontent.com/lightningnetwork/lnd/master/lnrpc/invoicesrpc/invoices.proto -python3 -m grpc_tools.protoc --proto_path=googleapis:. --python_out=. --grpc_python_out=. invoices.proto -curl -o router.proto -s https://raw.githubusercontent.com/lightningnetwork/lnd/master/lnrpc/routerrpc/router.proto -python3 -m grpc_tools.protoc --proto_path=googleapis:. --python_out=. --grpc_python_out=. router.proto -``` -Generated files can be automatically patched for relative imports like this: -``` -sed -i 's/^import .*_pb2 as/from . \0/' api/lightning/router_pb2.py -sed -i 's/^import .*_pb2 as/from . \0/' api/lightning/invoices_pb2.py -sed -i 's/^import .*_pb2 as/from . \0/' api/lightning/router_pb2_grpc.py -sed -i 's/^import .*_pb2 as/from . \0/' api/lightning/lightning_pb2_grpc.py -sed -i 's/^import .*_pb2 as/from . \0/' api/lightning/invoices_pb2_grpc.py -``` - **All set!** Commands you will need to startup: @@ -112,7 +89,7 @@ You will need these commands also often or eventually: * Open channel `docker exec -it lnd-dev lncli --network=testnet openchannel node_id --local_amt LOCAL_AMT --push_amt PUSH_AMT` -**RoboSats development site should be accessible on localhost:8000** +**RoboSats development site should be accessible on 127.0.0.1:8000** ## The harder way (deprecated)