Skip to content

Commit 2287292

Browse files
authored
feat: add xud-docker api (#726)
* feat: add xud-docker api * keep proxy service align with other optional services * fix proxy default ports * fix status command "proxy"
1 parent 2636c0d commit 2287292

File tree

11 files changed

+134
-1
lines changed

11 files changed

+134
-1
lines changed

images/proxy/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM golang:1.15.2-alpine3.12 as builder
2+
ADD .src github.com/ExchangeUnion/xud-docker-api-poc
3+
WORKDIR github.com/ExchangeUnion/xud-docker-api-poc
4+
RUN go build
5+
6+
FROM alpine:3.12
7+
COPY --from=builder /go/github.com/ExchangeUnion/xud-docker-api-poc/xud-docker-api-poc /usr/local/bin/proxy
8+
ADD entrypoint.sh /
9+
ENTRYPOINT ["/entrypoint.sh"]

images/proxy/entrypoint.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
3+
while [ ! -e /root/.xud/tls.cert ]; do
4+
echo "[entrypoint] Waiting for xud tls.cert to be created..."
5+
sleep 3
6+
done
7+
8+
#shellcheck disable=2068
9+
exec proxy $@

images/proxy/src.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
REPO_URL = "https://github.com/ExchangeUnion/xud-docker-api-poc"

images/utils/launcher/config/config.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ def parse_command_line_arguments(self):
103103
metavar="<images>",
104104
help="Use other local built images"
105105
)
106+
parser.add_argument(
107+
"--api",
108+
action="store_true",
109+
help="Expose xud-docker API (REST + WebSocket)"
110+
)
106111

107112
group = parser.add_argument_group("bitcoind")
108113
group.add_argument(
@@ -344,6 +349,19 @@ def parse_command_line_arguments(self):
344349
help="Expose webui service ports to your host machine"
345350
)
346351

352+
group = parser.add_argument_group("proxy")
353+
group.add_argument(
354+
"--proxy.disabled",
355+
nargs='?',
356+
metavar="true|false",
357+
help="Enable/Disable proxy service"
358+
)
359+
group.add_argument(
360+
"--proxy.expose-ports",
361+
metavar="<ports>",
362+
help="Expose proxy service ports to your host machine"
363+
)
364+
347365
self.args = parser.parse_args()
348366
self.logger.info("Parsed command-line arguments: %r", self.args)
349367

@@ -762,6 +780,18 @@ def update_webui(self, parsed):
762780
"28888": "28888:8080",
763781
})
764782

783+
def update_proxy(self, parsed):
784+
"""Update proxy related configurations from parsed TOML webui section
785+
:param parsed: Parsed proxy TOML section
786+
"""
787+
node = self.nodes["proxy"]
788+
self.update_disabled(node, parsed, "proxy.disabled")
789+
self.update_ports(node, parsed, mapping={
790+
"8889": "8889:8080",
791+
"18889": "18889:8080",
792+
"28889": "28889:8080",
793+
})
794+
765795
def parse_network_config(self):
766796
network = self.network
767797

images/utils/launcher/config/mainnet.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,7 @@
134134
[webui]
135135
#disabled = false
136136
#expose-ports = ["8888:8080"]
137+
138+
[proxy]
139+
#disabled = false
140+
#expose-ports = ["8889"]

images/utils/launcher/config/simnet.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@
4747
[webui]
4848
#disabled = false
4949
#expose-ports = ["28888:8080"]
50+
51+
[proxy]
52+
#disabled = false
53+
#expose-ports = ["28889"]

images/utils/launcher/config/template.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,21 @@ def __eq__(self, other):
133133
"use_local_image": False,
134134
"disabled": True,
135135
},
136+
"proxy": {
137+
"name": "proxy",
138+
"image": "exchangeunion/proxy:latest",
139+
"volumes": [
140+
{
141+
"host": "$data_dir/xud",
142+
"container": "/root/.xud",
143+
}
144+
],
145+
"ports": [PortPublish("28889:8080")],
146+
"mode": "native",
147+
"preserve_config": False,
148+
"use_local_image": False,
149+
"disabled": True,
150+
},
136151
"xud": {
137152
"name": "xud",
138153
"image": "exchangeunion/xud:latest",
@@ -320,6 +335,21 @@ def __eq__(self, other):
320335
"use_local_image": False,
321336
"disabled": True,
322337
},
338+
"proxy": {
339+
"name": "proxy",
340+
"image": "exchangeunion/proxy:latest",
341+
"volumes": [
342+
{
343+
"host": "$data_dir/xud",
344+
"container": "/root/.xud",
345+
}
346+
],
347+
"ports": [PortPublish("18889:8080")],
348+
"mode": "native",
349+
"preserve_config": False,
350+
"use_local_image": False,
351+
"disabled": True,
352+
},
323353
"xud": {
324354
"name": "xud",
325355
"image": "exchangeunion/xud:latest",
@@ -506,6 +536,21 @@ def __eq__(self, other):
506536
"use_local_image": False,
507537
"disabled": True,
508538
},
539+
"proxy": {
540+
"name": "proxy",
541+
"image": "exchangeunion/proxy:latest",
542+
"volumes": [
543+
{
544+
"host": "$data_dir/xud",
545+
"container": "/root/.xud",
546+
}
547+
],
548+
"ports": [PortPublish("8889:8080")],
549+
"mode": "native",
550+
"preserve_config": False,
551+
"use_local_image": False,
552+
"disabled": True,
553+
},
509554
"xud": {
510555
"name": "xud",
511556
"image": "exchangeunion/xud:1.0.1",

images/utils/launcher/config/testnet.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,7 @@
137137
[webui]
138138
#disabled = false
139139
#expose-ports = ["18888:8080"]
140+
141+
[proxy]
142+
#disabled = false
143+
#expose-ports = ["18889"]

images/utils/launcher/node/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from .lnd import Lndbtc, Lndltc
2222
from .webui import Webui
2323
from .xud import Xud, XudApiError
24+
from .proxy import Proxy
2425
from .DockerTemplate import DockerTemplate
2526
from ..config import Config
2627
from ..errors import FatalError
@@ -328,7 +329,7 @@ def cli(self, name, *args):
328329
self.get_node(name).cli(" ".join(args), self.shell)
329330

330331
def _get_status_nodes(self):
331-
optional_nodes = ["arby", "boltz", "webui"]
332+
optional_nodes = ["arby", "boltz", "webui", "proxy"]
332333
result = {}
333334
for node in self.nodes.values():
334335
if node.name in optional_nodes:
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from .base import Node
2+
3+
4+
class Proxy(Node):
5+
def __init__(self, name, ctx):
6+
super().__init__(name, ctx)
7+
8+
command = [
9+
"--xud.rpchost=xud",
10+
"--xud.rpccert=/root/.xud/tls.cert",
11+
]
12+
if self.network == "simnet":
13+
command.append("--xud.rpcport=28886")
14+
elif self.network == "testnet":
15+
command.append("--xud.rpcport=18886")
16+
elif self.network == "mainnet":
17+
command.append("--xud.rpcport=8886")
18+
19+
self.container_spec.command.extend(command)
20+
21+
def status(self):
22+
return "Ready"

0 commit comments

Comments
 (0)