Skip to content

Commit

Permalink
Merge branch 'feature/docker' of https://github.com/stakwork/sphinx-r…
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed May 4, 2020
2 parents c969e63 + d16f978 commit eddfa95
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 35 deletions.
93 changes: 79 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,81 @@
FROM node:8
RUN apt-get update
RUN apt-get install -f sqlite3
USER node
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH=$PATH:/home/node/.npm-global/bin
WORKDIR /home/node
COPY package.json .
FROM golang:1.13-alpine as builder
LABEL maintainer="[email protected]"

# Force Go to use the cgo based DNS resolver. This is required to ensure DNS
# queries required to connect to linked containers succeed.
ENV GODEBUG netdns=cgo

# Pass a tag, branch or a commit using build-arg. This allows a docker
# image to be built from a specified Git state. The default image
# will use the Git tip of master by default.
ARG checkout="v0.9.0-beta"
# ARG checkout="master"

# Install dependencies and build the binaries.
RUN apk add --no-cache --update alpine-sdk git make gcc openssh-client

# RUN mkdir /root/.ssh/
# ADD id_rsa /root/.ssh/id_rsa
# RUN touch /root/.ssh/known_hosts
# RUN ssh-keyscan github.com >> /root/.ssh/known_hosts
# RUN git clone [email protected]:stakwork/lnd-lean.git /go/src/github.com/lightningnetwork/lnd

RUN git clone https://github.com/lightningnetwork/lnd /go/src/github.com/lightningnetwork/lnd
RUN cd /go/src/github.com/lightningnetwork/lnd \
&& git checkout $checkout \
&& make \
&& make install tags="signrpc walletrpc chainrpc invoicesrpc experimental"

# Start a new, final image.
FROM alpine as final

EXPOSE 80
EXPOSE 9735/tcp
EXPOSE 9735/udp
EXPOSE 10009/tcp
EXPOSE 10009/udp

ENV NODE_ENV production

# Add bash and ca-certs, for quality of life and SSL-related reasons.
RUN apk --no-cache add \
bash \
ca-certificates

# Copy the binaries from the builder image.
COPY --from=builder /go/bin/lncli /bin/
COPY --from=builder /go/bin/lnd /bin/

RUN apk add --update nodejs nodejs-npm sqlite git supervisor

RUN git clone https://github.com/stakwork/sphinx-relay /relay/

WORKDIR /relay/

RUN git checkout feature/docker

RUN npm install
RUN npm install -g nodemon --save-dev
RUN npm install -g express --save-dev
RUN npm install -g webpack webpack-cli --save-dev
RUN npm install -g sqlite3 --build-from-source --save-dev
RUN npm install -g --save-dev sequelize
RUN npm install nodemon --save-dev
RUN npm install express --save-dev
RUN npm install webpack webpack-cli --save-dev

RUN apk --no-cache add g++ gcc libgcc libstdc++ linux-headers make python jq git
RUN npm install --quiet node-gyp -g

RUN npm install sqlite3 --build-from-source --save-dev
RUN npm install --save-dev sequelize
RUN npm rebuild
COPY . .
RUN npm run tsc

VOLUME /relay/.lnd

COPY ./lnd.conf.sample /relay/.lnd/lnd.conf

COPY init.sh /etc/profile.d/
RUN sudo chmod +x /etc/profile.d/init.sh

RUN mkdir -p /var/log/supervisor
COPY ./supervisord.conf /etc/supervisord.conf
COPY ./lnd_supervisor.conf /etc/supervisor.d/lnd_supervisor.ini
COPY ./relay_supervisor.conf /etc/supervisor.d/relay_supervisor.ini
CMD ["/usr/bin/supervisord"]
58 changes: 57 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Relay

**Relay** is a Node.js wrapper around [LND](https://github.com/lightningnetwork/lnd), handling connectivity and storage for [**Sphinx**](https://sphinx.chat). Communication between Relay nodes takes place entirely on the Lightning Network, so is decentralized, untraceable, and encrypted. Message content is also end-to-end encrypted using client public keys, on the **Sphinx** app itself.
**Relay** is a Node.js wrapper around [LND](https://github.com/lightningnetwork/lnd), handling connectivity and storage for [**Sphinx**](https://sphinx.chat). Communication between Relay nodes takes place entirely on the Lightning Network, so is decentralized, untraceable, and encrypted. Message content is also end-to-end encrypted using client public keys, on the **Sphinx** app itself.

![Relay](https://github.com/stakwork/sphinx-relay/raw/master/public/relay.jpg)

Expand All @@ -13,6 +13,62 @@ Relay stores:

# run your own sphinx node

## Using Docker on Raspberry Pi

Install docker-compose: https://medium.com/@techiebouncer/install-docker-and-docker-compose-on-raspberry-pi-4-raspbian-buster-c5b78b9a0d08

Clone this repo.

Copy your id_rsa to clone the private lnd-lean repo.

```
cp ~/.ssh/id_rsa .
```

Build it.

```
docker-compose build
```

Edit your docker-compose.yml file replacing NODE_IP and NODE_ALIAS.

Relay will run on port 3000 local. You would need to point your router's port forwarding from 80 to 3000 to your docker machine.

Start up LND separately first.

```
docker-compose up lnd
```

- In another terminal, go to the project folder and run.

```
docker-compose exec lnd bash
```

Once you're given a bash, run `ping lnd` and take note of the IP, this is because we need to tell Relay where lnd is via the IP, this is a temporary measure due to the limitation of the grpc connection can only be done via IP and not domain name.

Edit your app.json file inside config and on the `production` key replace `node_ip` with the one from the ping.

Run Relay.

```
docker-compose up node_server
```

Create / Unlock your wallet

```
docker-compose exec lnd lncli create
docker-compose exec lnd lncli unlock
```

NOTE: All lncli commands need to be prepended with `docker-compose exec lnd`, this tells docker to execute **something** on the lnd container.

## Without Docker

You can run your own Sphinx node in order to have full ownership over your communication!

### guide
Expand Down
32 changes: 14 additions & 18 deletions config/app.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
{
"development": {
"senza_url": "http://localhost:3000/api/v2",
"macaroon_location": "/Users/evanfeenstra/code/lnd-dev/alice/data/chain/bitcoin/simnet/admin.macaroon",
"tls_location": "/Users/evanfeenstra/Library/Application Support/Lnd/tls.cert",
"node_ip": "127.0.0.1",
"lnd_port": "10001",
"macaroon_location": "/relay/.lnd/data/chain/bitcoin/mainnet/admin.macaroon",
"tls_location": "/relay/.lnd/tls.cert",
"node_ip": "172.22.0.2",
"lnd_port": "10009",
"node_http_protocol": "http",
"node_http_port": "3001",
"hub_api_url": "http://lvh.me/api/v1",
"hub_url": "http://lvh.me/ping",
"hub_invite_url": "http://lvh.me/invites",
"hub_check_invite_url": "http://lvh.me/check_invite",
"media_host": "localhost:5000"
"node_http_port": "3000",
"hub_api_url": "http://hub.sphinx.chat/api/v1",
"hub_url": "http://hub.sphinx.chat/ping",
"hub_invite_url": "http://hub.sphinx.chat/invites",
"hub_check_invite_url": "http://hub.sphinx.chat/check_invite",
"media_host": "memes.sphinx.chat"
},
"production": {
"senza_url": "https://staging.senza.us/api/v2/",
"macaroon_location": "/home/ubuntu/.lnd/data/chain/bitcoin/mainnet/admin.macaroon",
"tls_location": "/home/ubuntu/.lnd/tls.cert",
"lnd_log_location": "/home/ubuntu/.lnd/logs/bitcoin/mainnet/lnd.log",
"lncli_location": "/home/ubuntu/go/bin",
"macaroon_location": "/relay/.lnd/data/chain/bitcoin/mainnet/admin.macaroon",
"tls_location": "/relay/.lnd/tls.cert",
"node_ip": "localhost",
"node_http_protocol": "http",
"node_http_port": "80",
"lnd_port": "10009",
"node_http_protocol": "http",
"node_http_port": "3000",
"hub_api_url": "https://hub.sphinx.chat/api/v1",
"hub_url": "https://hub.sphinx.chat/ping",
"hub_invite_url": "https://hub.sphinx.chat/invites",
Expand Down
4 changes: 2 additions & 2 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"development": {
"dialect": "sqlite",
"storage": "/Users/Shared/sphinx.db"
"storage": "./sphinx.db"
},
"docker_development": {
"dialect": "sqlite",
Expand All @@ -13,6 +13,6 @@
},
"production": {
"dialect": "sqlite",
"storage": "/home/ubuntu/sphinx.db"
"storage": "./.lnd/sphinx.db"
}
}
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '2'
volumes:
node_modules:

services:
relay:
build:
context: .
volumes:
- .:/relay
- .lnd/:/relay/.lnd
- node_modules:/relay/node_modules
ports:
- "3000:3000"
- "9735:9735"
- "10009:10009"
command: "lnd --accept-keysend --configfile=/relay/.lnd/lnd.conf && npm start"
environment:
- PORT=3000
- NODE_IP=mynodeip
- NODE_ALIAS=myalias
- NODE_ENV=production
2 changes: 2 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NODE_IP=$(curl http://169.254.170.2/v4/e52231f4-0246-4fc5-bc3e-ac20df1b118e | echo $(jq -r .DockerName).$NODE_DOMAIN)
NODE_ALIAS=$(curl http://169.254.170.2/v4/e52231f4-0246-4fc5-bc3e-ac20df1b118e | echo $(jq -r .DockerName))
12 changes: 12 additions & 0 deletions lnd.conf.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
bitcoin.mainnet=1
bitcoin.active=1
bitcoin.node=neutrino
accept-keysend=1

listen=0.0.0.0:9735
rpclisten=0.0.0.0:10009

ignore-historical-gossip-filters=true
nobootstrap=true
numgraphsyncpeers=1
routing.assumechanvalid=1
6 changes: 6 additions & 0 deletions lnd_supervisor.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[program:lnd]
user=root
command=lnd --lnddir=/relay/.lnd/
startretries=999999999999999999999999999
autostart=true
autorestart=true
6 changes: 6 additions & 0 deletions relay_supervisor.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[program:relay]
user=root
command=npm start --prefix /relay/
startretries=999999999999999999999999999
autostart=true
autorestart=true
17 changes: 17 additions & 0 deletions supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[unix_http_server]
file=/run/supervisord.sock ; (the path to the socket file)

[supervisord]
logfile=/var/log/supervisord.log ; (main log file;default $CWD/supervisord.log)
loglevel=info ; (log level;default info; others: debug,warn,trace)
nodaemon=true

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///run/supervisord.sock ; use a unix:// URL for a unix socket

[include]
files = /etc/supervisor.d/*.ini

0 comments on commit eddfa95

Please sign in to comment.