Skip to content

Commit

Permalink
feat: add webui (#582)
Browse files Browse the repository at this point in the history
* feat: add webui

This commit adds xud-webui-poc (ReactJS based frontend) and xud-socketio (NodeJS based backend) into one container `webui`. And the container will expose port 8080 to your host. The frontend app uses REST + Websocket (socketio) API to get the order book of different trading pairs. The backend server translates the REST + Websocket API to gRPC calls and send it back to xud container.

* revert xud changes

* fixup! testnet and mainnet

* add --webui option

* fix arm grpc-tools

* update

* update favicon

* use fontsource-roboto

* add --webui.disabled and --webui.expose-ports options

* move webui before xud

* add missing --use-local-images

* expose webui port by default

* stop webui gracefully

* add webui expose-ports option in network.conf

* 8080
  • Loading branch information
reliveyy authored Jul 9, 2020
1 parent 1464541 commit 47cd7a8
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 41 deletions.
84 changes: 46 additions & 38 deletions images/utils/launcher/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,11 @@ def parse_command_line_arguments(self):

parser.add_argument("--boltz.disabled", nargs='?')

parser.add_argument("--use-local-images")
parser.add_argument("--webui.disabled", nargs='?')
parser.add_argument("--webui.expose-ports")

parser.add_argument("--dev", action="store_true")
parser.add_argument("--use-local-images")

self.args = parser.parse_args()
self.logger.info("Parsed command-line arguments: %r", self.args)
Expand Down Expand Up @@ -161,17 +164,21 @@ def update_volume(self, volumes, container_dir, host_dir):
target = target[0]
target["host"] = host_dir

def update_ports(self, node, parsed):
def update_ports(self, node, parsed, mapping=None):
if "expose-ports" in parsed:
value = parsed["expose-ports"]
for p in value:
if mapping and p in mapping:
p = mapping[p]
p = PortPublish(str(p))
if p not in node["ports"]:
node["ports"].append(p)
opt = "{}.expose_ports".format(node["name"])
if hasattr(self.args, opt):
value = getattr(self.args, opt)
for p in value.split(","):
if mapping and p in mapping:
p = mapping[p]
p = PortPublish(p.strip())
if p not in node["ports"]:
node["ports"].append(p)
Expand Down Expand Up @@ -394,21 +401,35 @@ def update_lndltc(self, parsed):
self.update_ports(node, parsed)

def update_connext(self, parsed):
"""Update Connext related configurations from parsed TOML raiden section
"""Update Connext related configurations from parsed TOML connext section
:param parsed: Parsed raiden TOML section
"""
node = self.nodes["connext"]
self.update_ports(node, parsed)

def update_raiden(self, parsed):
"""Update raiden related configurations from parsed TOML raiden section
:param parsed: Parsed raiden TOML section
def update_xud(self, parsed):
"""Update xud related configurations from parsed TOML xud section
:param parsed: Parsed xud TOML section
"""
if self.network in ["simnet", "testnet", "mainnet"]:
return
node = self.nodes["raiden"]
node = self.nodes["xud"]
self.update_ports(node, parsed)

def update_disabled(self, node, parsed, opt):
if "disabled" in parsed:
value = parsed["disabled"]
assert isinstance(value, bool)
node["disabled"] = value
if hasattr(self.args, opt):
value: str = getattr(self.args, opt)
if value:
value = value.strip().lower()
if not value or value == "true" or value == "":
node["disabled"] = True
elif value == "false":
node["disabled"] = False
else:
raise ValueError("Invalid value of option \"{}\": {}".format(opt, value))

def update_arby(self, parsed):
"""Update arby related configurations from parsed TOML arby section
:param parsed: Parsed xud TOML section
Expand Down Expand Up @@ -474,41 +495,28 @@ def update_arby(self, parsed):
if value:
node["margin"] = value

if "disabled" in parsed:
value = parsed["disabled"]
assert isinstance(value, bool)
node["disabled"] = value
opt = "arby.disabled"
if hasattr(self.args, opt):
value: str = getattr(self.args, opt)
if value:
value = value.strip().lower()
if not value or value == "true" or value == "":
node["disabled"] = True
elif value == "false":
node["disabled"] = False
else:
raise ValueError("Invalid value of option \"arby.disabled\": {}".format(value))

self.update_disabled(node, parsed, "arby.disabled")
self.update_ports(node, parsed)

def update_xud(self, parsed):
"""Update xud related configurations from parsed TOML xud section
:param parsed: Parsed xud TOML section
def update_boltz(self, parsed):
"""Update webui related configurations from parsed TOML boltz section
:param parsed: Parsed raiden TOML section
"""
node = self.nodes["xud"]
node = self.nodes["boltz"]
self.update_disabled(node, parsed, "boltz.disabled")
self.update_ports(node, parsed)

def update_ltcd(self, parsed):
"""Update ltcd related configurations from parsed TOML ltcd section
:param parsed: Parsed ltcd TOML section
def update_webui(self, parsed):
"""Update webui related configurations from parsed TOML webui section
:param parsed: Parsed raiden TOML section
"""
node = self.nodes["ltcd"]
self.update_ports(node, parsed)

def update_boltz(self, parsed):
node = self.nodes["boltz"]
self.update_ports(node, parsed)
node = self.nodes["webui"]
self.update_disabled(node, parsed, "webui.disabled")
self.update_ports(node, parsed, mapping={
"8888": "8888:8080",
"18888": "18888:8080",
"28888": "28888:8080",
})

def parse_network_config(self):
network = self.network
Expand Down
4 changes: 4 additions & 0 deletions images/utils/launcher/config/mainnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,7 @@
#binance-api-secret = "your api secret"
#margin = "0.04"
#disabled = false

[webui]
#disabled = false
#expose-ports = ["8888:8080"]
4 changes: 4 additions & 0 deletions images/utils/launcher/config/simnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@
#binance-api-secret = "your api secret"
#margin = "0.04"
#disabled = false

[webui]
#disabled = false
#expose-ports = ["28888:8080"]
51 changes: 48 additions & 3 deletions images/utils/launcher/config/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,21 @@ def __eq__(self, other):
"disabled": True,
"use_local_image": False,
},
"webui": {
"name": "webui",
"image": "exchangeunion/webui:latest",
"volumes": [
{
"host": "$data_dir/xud",
"container": "/root/.xud",
}
],
"ports": [PortPublish("28888:8080")],
"mode": "native",
"preserve_config": False,
"use_local_image": False,
"disabled": True,
},
"xud": {
"name": "xud",
"image": "exchangeunion/xud:latest",
Expand All @@ -143,7 +158,7 @@ def __eq__(self, other):
"mode": "native",
"preserve_config": False,
"use_local_image": False,
}
},
},
"testnet": {
"bitcoind": {
Expand Down Expand Up @@ -290,6 +305,21 @@ def __eq__(self, other):
"disabled": False,
"use_local_image": False,
},
"webui": {
"name": "webui",
"image": "exchangeunion/webui:latest",
"volumes": [
{
"host": "$data_dir/xud",
"container": "/root/.xud",
}
],
"ports": [PortPublish("18888:8080")],
"mode": "native",
"preserve_config": False,
"use_local_image": False,
"disabled": True,
},
"xud": {
"name": "xud",
"image": "exchangeunion/xud:latest",
Expand All @@ -315,7 +345,7 @@ def __eq__(self, other):
"mode": "native",
"preserve_config": False,
"use_local_image": False,
}
},
},
"mainnet": {
"bitcoind": {
Expand Down Expand Up @@ -461,6 +491,21 @@ def __eq__(self, other):
"disabled": False,
"use_local_image": False,
},
"webui": {
"name": "webui",
"image": "exchangeunion/webui:latest",
"volumes": [
{
"host": "$data_dir/xud",
"container": "/root/.xud",
}
],
"ports": [PortPublish("8888:8080")],
"mode": "native",
"preserve_config": False,
"use_local_image": False,
"disabled": True,
},
"xud": {
"name": "xud",
"image": "exchangeunion/xud:1.0.0-beta.4",
Expand All @@ -486,7 +531,7 @@ def __eq__(self, other):
"mode": "native",
"preserve_config": False,
"use_local_image": False,
}
},
}
}

Expand Down
4 changes: 4 additions & 0 deletions images/utils/launcher/config/testnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,7 @@

[boltz]
#disabled = false

[webui]
#disabled = false
#expose-ports = ["18888:8080"]
1 change: 1 addition & 0 deletions images/utils/launcher/node/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from .geth import Geth
from .image import Image, ImageManager
from .lnd import Lndbtc, Lndltc
from .webui import Webui
from .xud import Xud, XudApiError
from ..config import Config
from ..errors import FatalError
Expand Down
9 changes: 9 additions & 0 deletions images/utils/launcher/node/webui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from .base import Node


class Webui(Node):
def __init__(self, name, ctx):
super().__init__(name, ctx)

def status(self):
return "Ready"
28 changes: 28 additions & 0 deletions images/webui/latest/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM node:14-alpine as builder
RUN apk --no-cache add git

RUN git clone -b socketio https://github.com/ExchangeUnion/xud-webui-poc /src/frontend
WORKDIR /src/frontend
RUN git fetch && git checkout b94cb330
RUN yarn install
RUN yarn build

RUN git clone -b dev https://github.com/ExchangeUnion/xud-socketio /src/backend
WORKDIR /src/backend
RUN git fetch && git checkout a3fd8648
RUN sed -Ei 's/^.*grpc-tools.*$//g' package.json
RUN yarn install
RUN apk --no-cache add bash
RUN yarn build


FROM node:14-alpine
COPY --from=builder /src/backend/node_modules /app/node_modules
COPY --from=builder /src/backend/dist /app/dist
COPY --from=builder /src/backend/bin /app/bin
COPY --from=builder /src/frontend/build /app/public
COPY entrypoint.sh /
WORKDIR /app
RUN apk --no-cache add supervisor
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
29 changes: 29 additions & 0 deletions images/webui/latest/Dockerfile.aarch64
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM node:14-alpine as builder
RUN apk --no-cache add git

RUN git clone -b socketio https://github.com/ExchangeUnion/xud-webui-poc /src/frontend
WORKDIR /src/frontend
RUN git fetch && git checkout b94cb330
RUN yarn install
RUN yarn build

RUN git clone -b dev https://github.com/ExchangeUnion/xud-socketio /src/backend
WORKDIR /src/backend
RUN git fetch && git checkout a3fd8648
RUN sed -Ei 's/^.*grpc-tools.*$//g' package.json
RUN apk --no-cache add python3 make g++
RUN yarn install
RUN apk --no-cache add bash
RUN yarn build


FROM node:14-alpine
COPY --from=builder /src/backend/node_modules /app/node_modules
COPY --from=builder /src/backend/dist /app/dist
COPY --from=builder /src/backend/bin /app/bin
COPY --from=builder /src/frontend/build /app/public
COPY entrypoint.sh /
WORKDIR /app
RUN apk --no-cache add supervisor
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
ENTRYPOINT ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
23 changes: 23 additions & 0 deletions images/webui/latest/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

case $NETWORK in
simnet)
RPCPORT=28886
;;
testnet)
RPCPORT=18886
;;
mainnet)
RPCPORT=8886
;;
*)
echo "Invalid NETWORK"
exit 1
esac

while ! [ -e /root/.xud/tls.cert ]; do
echo "Waiting for /root/.xud/tls.cert"
sleep 1
done

exec bin/server --xud.rpchost=xud --xud.rpcport=$RPCPORT --xud.rpccert=/root/.xud/tls.cert
11 changes: 11 additions & 0 deletions images/webui/latest/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[supervisord]
nodaemon=true
logfile=/supervisord.log
childlogdir=/app
user=root

[program:webui]
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
command=/entrypoint.sh
stopsignal=SIGINT
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ pytest-html
pytest-integration
pytest-timeout
pytest-dotenv
toml
demjson

0 comments on commit 47cd7a8

Please sign in to comment.