Browse Source

Merge branch 'feature/docker' of https://github.com/stakwork/sphinx-relay

feature/dockerfile-arm
Evan Feenstra 5 years ago
parent
commit
eddfa95f42
  1. 93
      Dockerfile
  2. 58
      README.md
  3. 32
      config/app.json
  4. 4
      config/config.json
  5. 22
      docker-compose.yml
  6. 2
      init.sh
  7. 12
      lnd.conf.sample
  8. 6
      lnd_supervisor.conf
  9. 6
      relay_supervisor.conf
  10. 17
      supervisord.conf

93
Dockerfile

@ -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="gonzaloaune@stakwork.com"
# 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 git@github.com: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
README.md

@ -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)
@ -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

32
config/app.json

@ -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",

4
config/config.json

@ -1,7 +1,7 @@
{
"development": {
"dialect": "sqlite",
"storage": "/Users/Shared/sphinx.db"
"storage": "./sphinx.db"
},
"docker_development": {
"dialect": "sqlite",
@ -13,6 +13,6 @@
},
"production": {
"dialect": "sqlite",
"storage": "/home/ubuntu/sphinx.db"
"storage": "./.lnd/sphinx.db"
}
}

22
docker-compose.yml

@ -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
init.sh

@ -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
lnd.conf.sample

@ -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
lnd_supervisor.conf

@ -0,0 +1,6 @@
[program:lnd]
user=root
command=lnd --lnddir=/relay/.lnd/
startretries=999999999999999999999999999
autostart=true
autorestart=true

6
relay_supervisor.conf

@ -0,0 +1,6 @@
[program:relay]
user=root
command=npm start --prefix /relay/
startretries=999999999999999999999999999
autostart=true
autorestart=true

17
supervisord.conf

@ -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
Loading…
Cancel
Save