Skip to content

Commit ec57617

Browse files
committed
testserver: Add a couple of usability improvements
The `.envrc` file can make it simpler to configure your shell.
1 parent 4bf0bb9 commit ec57617

File tree

4 files changed

+120
-4
lines changed

4 files changed

+120
-4
lines changed

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,22 @@ docs-publish: docs
191191
--push \
192192
--branch gh-pages \
193193
--remote origin
194+
195+
gltestserver-image: docker/gl-testserver/Dockerfile
196+
docker build \
197+
--build-arg DOCKER_USER=$(shell whoami) \
198+
--build-arg UID=$(shell id -u) \
199+
--build-arg GID=$(shell id -g) \
200+
-t gltestserver \
201+
-f docker/gl-testserver/Dockerfile \
202+
.
203+
204+
gltestserver: gltestserver-image
205+
mkdir -p /tmp/gltestserver
206+
docker run \
207+
--user $(shell id -u):$(shell id -g) \
208+
-e DOCKER_USER=$(shell whoami) \
209+
--net=host \
210+
-ti \
211+
-v $(shell pwd)/.testserver:/tmp/gltestserver \
212+
gltestserver

docker/gl-testserver/Dockerfile

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
FROM ubuntu:22.04 AS python-builder
2+
3+
ENV RUST_VERSION=1.74
4+
ENV PATH=$CARGO_HOME/bin:$PATH
5+
ENV PROTOC_VERSION=3.19.3
6+
ENV CFSSL_VERSION=1.6.5
7+
ENV GL_TESTING_IGNORE_HASH=true
8+
ARG BITCOIN_VERSION=24.0
9+
ARG GID=0
10+
ARG UID=0
11+
ARG DOCKER_USER=dev
12+
ENV PATH=$PATH:/home/$DOCKER_USER/.local/bin/:/opt/bitcoin/bin:/home/$DOCKER_USER/.cargo/bin
13+
#ENV VIRTUAL_ENV=/tmp/venv
14+
ENV CARGO_TARGET_DIR=/tmp/cargo
15+
16+
RUN apt update && apt install -qqy \
17+
curl \
18+
python3 \
19+
python3-pip \
20+
python3-venv \
21+
libpq-dev \
22+
unzip \
23+
sudo \
24+
git \
25+
build-essential \
26+
wget
27+
28+
RUN groupadd -g $GID -o $DOCKER_USER &&\
29+
useradd -m -u $UID -g $GID -G sudo -o -s /bin/bash $DOCKER_USER && \
30+
echo '%sudo ALL=(ALL:ALL) ALL' >> /etc/sudoers
31+
32+
RUN wget -q https://github.com/cloudflare/cfssl/releases/download/v${CFSSL_VERSION}/cfssl_${CFSSL_VERSION}_linux_amd64 -O /usr/bin/cfssl && \
33+
chmod a+x /usr/bin/cfssl
34+
RUN wget -q https://github.com/cloudflare/cfssl/releases/download/v${CFSSL_VERSION}/cfssljson_${CFSSL_VERSION}_linux_amd64 -O /usr/bin/cfssljson && \
35+
chmod a+x /usr/bin/cfssljson
36+
37+
RUN mkdir /tmp/protoc && \
38+
cd /tmp/protoc && \
39+
wget --quiet \
40+
-O protoc.zip \
41+
https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip && \
42+
unzip protoc.zip && \
43+
sudo mv /tmp/protoc/bin/protoc /usr/local/bin && \
44+
chmod a+x /usr/local/bin/protoc && \
45+
rm -rf /tmp/protoc
46+
47+
RUN cd /tmp/ && \
48+
wget "https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/bitcoin-${BITCOIN_VERSION}-x86_64-linux-gnu.tar.gz" -O bitcoin.tar.gz && \
49+
tar -xvzf bitcoin.tar.gz && \
50+
mv /tmp/bitcoin-$BITCOIN_VERSION/ /opt/bitcoin && \
51+
rm -rf bitcoin.tar.gz /tmp/bitcoin-$BITCOIN_VERSION
52+
53+
ADD ../ /repo/libs
54+
RUN chown $DOCKER_USER:users -R /repo
55+
56+
USER $DOCKER_USER
57+
58+
RUN curl \
59+
--proto '=https' \
60+
--tlsv1.2 \
61+
-sSf https://sh.rustup.rs | sh \
62+
-s -- -y --default-toolchain ${RUST_VERSION}
63+
RUN rustup default stable
64+
65+
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
66+
67+
WORKDIR /repo/libs/gl-testserver/
68+
RUN echo $PATH
69+
RUN uv sync --locked -v
70+
RUN uv run clnvm get-all
71+
CMD uv run gltestserver run --metadata /tmp/gltestserver

libs/gl-testing/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencies = [
1010
"gl-client",
1111
"grpcio-tools>=1.66",
1212
"grpcio>=1.66.0",
13-
"httpx>=0.27.2",
13+
"httpx[http2]>=0.27.2",
1414
"purerpc>=0.8.0",
1515
"pyln-client==24.2",
1616
"pyln-testing==24.2",

libs/gl-testserver/gltestserver/__main__.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import click
1111
import gltesting
1212
import json
13+
import os
1314
import logging
1415
import tempfile
1516
import time
@@ -47,10 +48,15 @@ def stop(self):
4748

4849
def metadata(self):
4950
"""Construct a dict of config values for this TestServer."""
51+
cert_path = Path(os.environ.get('GL_CERT_PATH'))
5052
return {
5153
"scheduler_grpc_uri": self.scheduler.grpc_addr,
5254
"grpc_web_proxy_uri": f"http://localhost:{self.grpc_web_proxy.web_port}",
5355
"bitcoind_rpc_uri": f"http://rpcuser:rpcpass@localhost:{self.bitcoind.rpcport}",
56+
"cert_path": str(cert_path),
57+
"ca_crt_path": str(cert_path / "ca.crt"),
58+
"nobody_crt_path": str(cert_path / "users" / "nobody.crt"),
59+
"nobody_key_path": str(cert_path / "users" / "nobody-key.pem"),
5460
}
5561

5662

@@ -120,27 +126,47 @@ def cli():
120126
different top-level directory. Defaults to '/tmp/'
121127
""",
122128
)
123-
def run(directory):
129+
@click.option(
130+
'--metadata',
131+
type=click.Path(),
132+
help="Where to store the metadata.json and .envrc files"
133+
)
134+
def run(directory, metadata=None):
124135
"""Start a gl-testserver instance to test against."""
125136
if not directory:
126137
directory = Path(tempfile.gettempdir())
127138
else:
128139
directory = Path(directory)
129140

141+
metadata = Path(metadata) if metadata else directory
142+
130143
gl = build(base_dir=directory)
131144
try:
132145
meta = gl.metadata()
133-
metafile = gl.directory / "metadata.json"
146+
metafile = metadata / "metadata.json"
134147
metafile.parent.mkdir(parents=True, exist_ok=True)
135148
logger.debug(f"Writing testserver metadata to {metafile}")
136149
with metafile.open(mode="w") as f:
137150
json.dump(meta, f)
138151

152+
envfile = metadata / ".env"
153+
logger.info(f"Writing .env file to {envfile}")
154+
with envfile.open(mode="w") as f:
155+
f.write(f"""\
156+
export GL_SCHEDULER_GRPC_URI={meta['scheduler_grpc_uri']}
157+
export GL_CERT_PATH={meta['cert_path']}
158+
export GL_CA_CRT={meta['ca_crt_path']}
159+
export GL_NOBODY_CRT={meta['nobody_crt_path']}
160+
export GL_NOBODY_KEY={meta['nobody_key_path']}
161+
export RUST_LOG=glclient=debub,info
162+
""")
163+
139164
pprint(meta)
140165
logger.info(
141166
"Server is up and running with the above config values. To stop press Ctrl-C."
142167
)
143-
time.sleep(1800)
168+
while True:
169+
time.sleep(1800)
144170
except Exception as e:
145171
logger.warning(f"Caught exception running testserver: {e}")
146172
pass

0 commit comments

Comments
 (0)