Skip to content

Commit 1817da8

Browse files
reliveyyraladev
andauthored
feat: add status api (#734)
* feat: add status api * map config dump into proxy * remove temp_file of xud.sh * capitalize Internet * forward xud.sh params to setup.sh * fix ports * update utils and proxy base images * enlarge image checking timeout * use proxy master * change proxy repo url * change branch to add-proxy * revert proxy to master Co-authored-by: raladev <[email protected]>
1 parent eab2eed commit 1817da8

File tree

9 files changed

+121
-38
lines changed

9 files changed

+121
-38
lines changed

images/proxy/Dockerfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
FROM golang:1.15.2-alpine3.12 as builder
2-
ADD .src github.com/ExchangeUnion/xud-docker-api-poc
1+
FROM golang:1.15-alpine3.12 as builder
32
WORKDIR github.com/ExchangeUnion/xud-docker-api-poc
4-
RUN go build
3+
COPY .src/go.mod .
4+
COPY .src/go.sum .
5+
RUN go mod download
6+
ADD .src .
7+
RUN go build ./cmd/proxy
58

69
FROM alpine:3.12
7-
COPY --from=builder /go/github.com/ExchangeUnion/xud-docker-api-poc/xud-docker-api-poc /usr/local/bin/proxy
10+
COPY --from=builder /go/github.com/ExchangeUnion/xud-docker-api-poc/proxy /usr/local/bin/proxy
811
ADD entrypoint.sh /
912
ENTRYPOINT ["/entrypoint.sh"]

images/proxy/entrypoint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,15 @@ while [ ! -e /root/.xud/tls.cert ]; do
55
sleep 3
66
done
77

8+
while [ ! -e /root/.lndbtc/tls.cert ]; do
9+
echo "[entrypoint] Waiting for lndbtc tls.cert to be created..."
10+
sleep 3
11+
done
12+
13+
while [ ! -e /root/.lndltc/tls.cert ]; do
14+
echo "[entrypoint] Waiting for lndltc tls.cert to be created..."
15+
sleep 3
16+
done
17+
818
#shellcheck disable=2068
919
exec proxy $@

images/proxy/src.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
1-
REPO_URL = "https://github.com/ExchangeUnion/xud-docker-api-poc"
1+
from tools.core import src
2+
3+
4+
class SourceManager(src.SourceManager):
5+
def __init__(self):
6+
super().__init__("https://github.com/ExchangeUnion/xud-docker-api")
7+
8+
def get_ref(self, version):
9+
if version == "latest":
10+
# change "master" to a another xud branch for testing
11+
return "master"
12+
else:
13+
return "v" + version

images/utils/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.8.2-alpine3.11
1+
FROM python:3.8-alpine3.12
22
RUN pip install toml docker demjson
33
ADD . /usr/local/src/utils
44
WORKDIR /usr/local/src/utils

images/utils/launcher/config/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,8 @@ def expand_vars(self, value):
929929
value = value.replace(f"${self.network}_dir", self.network_dir)
930930
if "$data_dir" in value:
931931
value = value.replace("$data_dir", self.network_dir + "/data")
932+
if "$logs_dir" in value:
933+
value = value.replace("$logs_dir", self.logs_dir)
932934
return value
933935

934936
@property

images/utils/launcher/config/template.py

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class PortPublish:
66
def __init__(self, value):
77
p1 = re.compile(r"^(\d+)$") # 8080
88
p2 = re.compile(r"^(\d+):(\d+)$") # 80:8080
9-
p3 = re.compile(r"^(\d+):(\d+):(\d+)$") # 127.0.0.1:80:8080
9+
p3 = re.compile(r"^(.+):(\d+):(\d+)$") # 127.0.0.1:80:8080
1010

1111
protocol = "tcp"
1212
if "/" in value:
@@ -35,6 +35,8 @@ def __init__(self, value):
3535
host = m.group(1)
3636
host_port = int(m.group(2))
3737
port = int(m.group(3))
38+
else:
39+
raise FatalError("Invalid port publish: {}".format(value))
3840

3941
self.protocol = protocol
4042
self.host = host
@@ -152,12 +154,28 @@ def __str__(self):
152154
"name": "proxy",
153155
"image": "exchangeunion/proxy:latest",
154156
"volumes": [
157+
{
158+
"host": "/var/run/docker.sock",
159+
"container": "/var/run/docker.sock",
160+
},
161+
{
162+
"host": "$logs_dir/config.sh",
163+
"container": "/root/config.sh",
164+
},
155165
{
156166
"host": "$data_dir/xud",
157167
"container": "/root/.xud",
158-
}
168+
},
169+
{
170+
"host": "$data_dir/lndbtc",
171+
"container": "/root/.lndbtc",
172+
},
173+
{
174+
"host": "$data_dir/lndltc",
175+
"container": "/root/.lndltc",
176+
},
159177
],
160-
"ports": [PortPublish("28889:8080")],
178+
"ports": [PortPublish("127.0.0.1:28889:8080")],
161179
"mode": "native",
162180
"preserve_config": False,
163181
"use_local_image": False,
@@ -354,12 +372,29 @@ def __str__(self):
354372
"name": "proxy",
355373
"image": "exchangeunion/proxy:latest",
356374
"volumes": [
375+
{
376+
"host": "/var/run/docker.sock",
377+
"container": "/var/run/docker.sock",
378+
},
379+
{
380+
"host": "$logs_dir/config.sh",
381+
"container": "/root/config.sh",
382+
},
357383
{
358384
"host": "$data_dir/xud",
359385
"container": "/root/.xud",
360-
}
386+
},
387+
{
388+
"host": "$data_dir/lndbtc",
389+
"container": "/root/.lndbtc",
390+
},
391+
{
392+
"host": "$data_dir/lndltc",
393+
"container": "/root/.lndltc",
394+
},
395+
361396
],
362-
"ports": [PortPublish("18889:8080")],
397+
"ports": [PortPublish("127.0.0.1:18889:8080")],
363398
"mode": "native",
364399
"preserve_config": False,
365400
"use_local_image": False,
@@ -555,12 +590,28 @@ def __str__(self):
555590
"name": "proxy",
556591
"image": "exchangeunion/proxy:latest",
557592
"volumes": [
593+
{
594+
"host": "/var/run/docker.sock",
595+
"container": "/var/run/docker.sock",
596+
},
597+
{
598+
"host": "$logs_dir/config.sh",
599+
"container": "/root/config.sh",
600+
},
558601
{
559602
"host": "$data_dir/xud",
560603
"container": "/root/.xud",
561-
}
604+
},
605+
{
606+
"host": "$data_dir/lndbtc",
607+
"container": "/root/.lndbtc",
608+
},
609+
{
610+
"host": "$data_dir/lndltc",
611+
"container": "/root/.lndltc",
612+
},
562613
],
563-
"ports": [PortPublish("8889:8080")],
614+
"ports": [PortPublish("127.0.0.1:8889:8080")],
564615
"mode": "native",
565616
"preserve_config": False,
566617
"use_local_image": False,

images/utils/launcher/node/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def wrapper(i):
344344
self.logger.info("(%s) Checking for updates: %s", i.name, i.status)
345345

346346
try:
347-
parallel_execute(images, lambda i: wrapper(i), 20, print_failed, try_again)
347+
parallel_execute(images, lambda i: wrapper(i), 30, print_failed, try_again)
348348
except ParallelExecutionError as e:
349349
for image, error in e.failed:
350350
error_msg = str(error)

images/utils/launcher/node/proxy.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,5 @@ class Proxy(Node):
55
def __init__(self, name, ctx):
66
super().__init__(name, ctx)
77

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-
218
def status(self):
229
return "Ready"

xud.sh

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function parse_arguments() {
1515
OPTION=$1
1616
shift
1717
if [[ $# -eq 0 || $1 =~ ^- ]]; then
18-
echo >&2 "Missing option value: $OPTION"
18+
echo >&2 "Missing option value: $OPTION"
1919
exit 1
2020
fi
2121
VALUE=$1
@@ -30,15 +30,33 @@ function parse_arguments() {
3030

3131
parse_arguments "$@"
3232

33-
temp_file=$(mktemp)
34-
HTTPCODE=$(curl -Ls -w "%{http_code}" -o temp_file "https://raw.githubusercontent.com/ExchangeUnion/xud-docker/$BRANCH/setup.sh" ||
35-
echo >&2 "Timeout error: Couldn't connect to GitHub: please check your internet connection and githubstatus.com")
36-
if [ $HTTPCODE -eq 404 ]; then
37-
echo >&2 "❌ Branch \"$BRANCH\" does not exist"
38-
elif [ $HTTPCODE -ne 200 ]; then
39-
echo >&2 "Something went wrong: got "$HTTPCODE" response code from GitHub. Please check githubstatus.com"
33+
URL="https://raw.githubusercontent.com/ExchangeUnion/xud-docker/$BRANCH/setup.sh"
34+
35+
if ! command -v curl >/dev/null; then
36+
echo >&2 "Command \"curl\" not found"
37+
exit 1
38+
fi
39+
40+
if SCRIPT=$(curl -s "$URL"); then
41+
if [[ "$SCRIPT" == "404: Not Found" ]]; then
42+
echo >&2 "Xud-docker branch \"$BRANCH\" does not exist"
43+
exit 1
44+
fi
45+
bash -c "$SCRIPT" -- "$@"
4046
else
41-
bash temp_file "$@"
42-
rm ${temp_file} && exit 0
47+
EXIT_CODE="$?"
48+
case "$EXIT_CODE" in
49+
6)
50+
echo >&2 "Couldn't resolve host: raw.githubusercontent.com (please check your Internet connection and https://githubstatus.com)"
51+
exit 1
52+
;;
53+
7)
54+
echo >&2 "Failed to connect to host: raw.githubusercontent.com (please check your Internet connection and https://githubstatus.com)"
55+
exit 1
56+
;;
57+
*)
58+
echo >&2 "Failed to fetch setup.sh for branch \"$BRANCH\" (curl exits with $EXIT_CODE)"
59+
exit 1
60+
;;
61+
esac
4362
fi
44-
exit 1

0 commit comments

Comments
 (0)