From 014bda055e3004334aacee50132f01b5a6b0653c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?vlado=20pajic=CC=81?= Date: Thu, 24 Sep 2026 18:56:40 +0200 Subject: [PATCH] common code --- nim-test-node/.dockerignore | 6 ++++ nim-test-node/common/health_server.nim | 26 ++++++++++++++ nim-test-node/common/peer_ids.nim | 9 +++++ .../shutdown.nim} | 1 + nim-test-node/connmanager/Dockerfile | 11 +++--- nim-test-node/connmanager/README.md | 3 +- nim-test-node/connmanager/main.nim | 10 +++--- nim-test-node/connmanager/test_node.nimble | 4 ++- .../gossipsub-queues/Dockerfile_amd64 | 9 ++--- .../gossipsub-queues/Dockerfile_arm64 | 9 ++--- nim-test-node/gossipsub-queues/main.nim | 3 +- nim-test-node/kad-dht/Dockerfile | 9 ++--- nim-test-node/kad-dht/README.md | 2 ++ nim-test-node/kad-dht/core.nim | 12 +++---- nim-test-node/kad-dht/helpers.nim | 34 +------------------ nim-test-node/kad-dht/main.nim | 14 ++++---- nim-test-node/regression/Dockerfile | 7 ++-- nim-test-node/regression/Dockerfile_shadow | 7 ++-- nim-test-node/regression/README.md | 16 +++++---- nim-test-node/regression/bootstrap/main.nim | 2 +- nim-test-node/regression/node/main.nim | 2 +- nim-test-node/service-discovery/Dockerfile | 7 ++-- nim-test-node/service-discovery/helpers.nim | 27 +-------------- nim-test-node/service-discovery/main.nim | 8 ++--- nim-test-node/service-discovery/run.sh | 3 +- shadow/Dockerfile | 2 +- shadow/kaniko-build-test-node-job.yaml | 4 +-- 27 files changed, 122 insertions(+), 125 deletions(-) create mode 100644 nim-test-node/.dockerignore create mode 100644 nim-test-node/common/health_server.nim create mode 100644 nim-test-node/common/peer_ids.nim rename nim-test-node/{regression/shutdown_utils.nim => common/shutdown.nim} (87%) diff --git a/nim-test-node/.dockerignore b/nim-test-node/.dockerignore new file mode 100644 index 00000000..155371bc --- /dev/null +++ b/nim-test-node/.dockerignore @@ -0,0 +1,6 @@ +**/nimble.paths +**/nimble.develop +**/nimbledeps +**/nimcache* +**/main +**/build diff --git a/nim-test-node/common/health_server.nim b/nim-test-node/common/health_server.nim new file mode 100644 index 00000000..6a6effde --- /dev/null +++ b/nim-test-node/common/health_server.nim @@ -0,0 +1,26 @@ +import chronos +import chronos/apps/http/httpserver + +proc startHealthServer*(port: Port): Future[HttpServerRef] {.async.} = + ## Start a health server exposing GET /health and GET /ready. + proc handler(request: RequestFence): Future[HttpResponseRef] {.async.} = + if request.isErr(): + return defaultResponse() + + let req = request.get() + if req.meth == MethodGet and (req.uri.path == "/health" or req.uri.path == "/ready"): + return await req.respond( + Http200, "ok", HttpTable.init([("Content-Type", "text/plain")]) + ) + + return await req.respond(Http404, "Not Found") + + let serverRes = HttpServerRef.new(initTAddress("0.0.0.0:" & $port), handler) + if serverRes.isErr(): + raise newException( + CatchableError, "Failed to create health HTTP server: " & $serverRes.error + ) + + let server = serverRes.get() + server.start() + return server diff --git a/nim-test-node/common/peer_ids.nim b/nim-test-node/common/peer_ids.nim new file mode 100644 index 00000000..0f1d2d7a --- /dev/null +++ b/nim-test-node/common/peer_ids.nim @@ -0,0 +1,9 @@ +import libp2p/peerid + +proc randomPeerId*[R](rng: R): PeerId = + ## Generate a random peer ID using the caller's random number generator. + PeerId.random(rng).get() + +proc randomPeerIds*[R](rng: R, count: Natural): seq[PeerId] = + ## Generate `count` random peer IDs using the same random number generator. + PeerId.random(count.uint, rng).get() diff --git a/nim-test-node/regression/shutdown_utils.nim b/nim-test-node/common/shutdown.nim similarity index 87% rename from nim-test-node/regression/shutdown_utils.nim rename to nim-test-node/common/shutdown.nim index 81614d3c..0a64dc25 100644 --- a/nim-test-node/regression/shutdown_utils.nim +++ b/nim-test-node/common/shutdown.nim @@ -1,6 +1,7 @@ import chronos proc waitShutdownSignal*() {.async.} = + ## Wait until the process receives SIGINT or SIGTERM. let sigIntFut = waitSignal(SIGINT) sigTermFut = waitSignal(SIGTERM) diff --git a/nim-test-node/connmanager/Dockerfile b/nim-test-node/connmanager/Dockerfile index 57b11933..9132962d 100644 --- a/nim-test-node/connmanager/Dockerfile +++ b/nim-test-node/connmanager/Dockerfile @@ -13,17 +13,18 @@ RUN apt-get update && \ RUN curl https://nim-lang.org/choosenim/init.sh -sSf | sh -s -- -y ENV PATH="/root/.nimble/bin:${PATH}" -WORKDIR /node +WORKDIR /node/connmanager -COPY test_node.nimble . +COPY connmanager/test_node.nimble . RUN git config --global http.sslVerify false RUN --mount=type=cache,target=/root/.nimble/pkgs \ --mount=type=cache,target=/root/.nimble/pkgs2 \ - nimble install -dy + nimble install -dy --useSystemNim -COPY . . +COPY common /node/common +COPY connmanager/. . RUN nimble c \ -d:chronicles_colors=None \ @@ -48,7 +49,7 @@ RUN apt-get update && \ WORKDIR /node -COPY --from=build /node/main /node/main +COPY --from=build /node/connmanager/main /node/main RUN chmod +x main diff --git a/nim-test-node/connmanager/README.md b/nim-test-node/connmanager/README.md index 4ee132b5..29635691 100644 --- a/nim-test-node/connmanager/README.md +++ b/nim-test-node/connmanager/README.md @@ -17,7 +17,8 @@ nimble c \ To build with Docker: ``` -docker buildx build --platform linux/amd64 -t radiken/dst-test-node-connmanager:latest --push . +cd .. +docker buildx build --platform linux/amd64 -f connmanager/Dockerfile -t radiken/dst-test-node-connmanager:latest --push . ``` ## Environment variables diff --git a/nim-test-node/connmanager/main.nim b/nim-test-node/connmanager/main.nim index 3f19f143..5840d74c 100644 --- a/nim-test-node/connmanager/main.nim +++ b/nim-test-node/connmanager/main.nim @@ -4,6 +4,7 @@ import metrics, metrics/chronos_httpserver import libp2p, libp2p/[multiaddress, crypto/secp] from nativesockets import getHostname import env +import ../common/shutdown logScope: topics = "dst" @@ -92,8 +93,7 @@ proc runHub(cfg: HubConfig) {.async.} = info "Dialing peer hub", target = hubAddr asyncSpawn resolveAndConnect(switch, hubAddr) - while true: - await sleepAsync(1.hours) + await waitShutdownSignal() proc runPeer(cfg: PeerConfig) {.async.} = var builder = SwitchBuilder @@ -142,11 +142,9 @@ proc runPeer(cfg: PeerConfig) {.async.} = else: for addr in cfg.hubAddrs: await resolveAndConnect(switch, addr) - while true: - await sleepAsync(1.hours) + await waitShutdownSignal() else: - while true: - await sleepAsync(1.hours) + await waitShutdownSignal() proc main() {.async.} = case getRole() diff --git a/nim-test-node/connmanager/test_node.nimble b/nim-test-node/connmanager/test_node.nimble index 14489723..5e3dad38 100644 --- a/nim-test-node/connmanager/test_node.nimble +++ b/nim-test-node/connmanager/test_node.nimble @@ -7,4 +7,6 @@ description = "Connection manager test node" license = "MIT" requires "nim >= 2.2.0", - "nimcrypto 0.6.4", "libp2p#7cc4280e2efd5e6c2ebd732ce33d309376a9627e" + "nimcrypto >= 0.6.4", + "lsquic == 0.9.0", + "libp2p#7cc4280e2efd5e6c2ebd732ce33d309376a9627e" diff --git a/nim-test-node/gossipsub-queues/Dockerfile_amd64 b/nim-test-node/gossipsub-queues/Dockerfile_amd64 index c4f28ae9..ad49159d 100644 --- a/nim-test-node/gossipsub-queues/Dockerfile_amd64 +++ b/nim-test-node/gossipsub-queues/Dockerfile_amd64 @@ -1,8 +1,9 @@ FROM debian:bookworm-slim AS builder -WORKDIR /node +WORKDIR /node/gossipsub-queues -COPY . . +COPY common /node/common +COPY gossipsub-queues/. . RUN apt-get update && apt-get install -y \ curl git build-essential ca-certificates \ @@ -57,10 +58,10 @@ RUN nimble c \ --passL:"-static-libgcc -static-libstdc++" \ main -RUN chmod +x /node/main +RUN chmod +x /node/gossipsub-queues/main RUN nim --version > nim_version RUN nimble --version > nimble_version EXPOSE 5000 8008 8645 -ENTRYPOINT ["/node/main"] \ No newline at end of file +ENTRYPOINT ["/node/gossipsub-queues/main"] diff --git a/nim-test-node/gossipsub-queues/Dockerfile_arm64 b/nim-test-node/gossipsub-queues/Dockerfile_arm64 index 79ee333c..455c0a28 100644 --- a/nim-test-node/gossipsub-queues/Dockerfile_arm64 +++ b/nim-test-node/gossipsub-queues/Dockerfile_arm64 @@ -1,8 +1,9 @@ FROM nimlang/nim:latest AS builder -WORKDIR /node +WORKDIR /node/gossipsub-queues -COPY . . +COPY common /node/common +COPY gossipsub-queues/. . RUN apt-get update && apt-get install -y \ curl git build-essential ca-certificates \ @@ -40,10 +41,10 @@ RUN nimble c \ main -RUN chmod +x /node/main +RUN chmod +x /node/gossipsub-queues/main RUN nim --version > nim_version RUN nimble --version > nimble_version EXPOSE 5000 8008 8645 -ENTRYPOINT ["/node/main"] \ No newline at end of file +ENTRYPOINT ["/node/gossipsub-queues/main"] diff --git a/nim-test-node/gossipsub-queues/main.nim b/nim-test-node/gossipsub-queues/main.nim index 92c2e189..60b9017a 100644 --- a/nim-test-node/gossipsub-queues/main.nim +++ b/nim-test-node/gossipsub-queues/main.nim @@ -11,6 +11,7 @@ import sequtils, math, metrics, metrics/chronos_httpserver from times import getTime, Time, toUnix, fromUnix, `-`, initTime, `$`, inMilliseconds from times import getTime, toUnixFloat, `-`, initTime, `$`, inMilliseconds, Time from nativesockets import getHostname +import ../common/shutdown logScope: topics = "dst" @@ -511,6 +512,6 @@ proc main() {.async.} = info "Starting listening endpoint for publish controller" discard gossipSub.startHttpServer(myId) - await sleepAsync(2.days) + await waitShutdownSignal() waitFor(main()) diff --git a/nim-test-node/kad-dht/Dockerfile b/nim-test-node/kad-dht/Dockerfile index 75b22384..fafde12b 100644 --- a/nim-test-node/kad-dht/Dockerfile +++ b/nim-test-node/kad-dht/Dockerfile @@ -14,8 +14,9 @@ RUN apt-get update && \ RUN curl https://nim-lang.org/choosenim/init.sh -sSf | sh -s -- -y ENV PATH="/root/.nimble/bin:${PATH}" -WORKDIR /node -COPY . . +WORKDIR /node/kad-dht +COPY common /node/common +COPY kad-dht/. . RUN git config --global http.sslVerify false @@ -41,10 +42,10 @@ RUN apt-get update && \ WORKDIR /node -COPY --from=build /node/main /node/main +COPY --from=build /node/kad-dht/main /node/main RUN chmod +x main EXPOSE 5000 8008 8645 -ENTRYPOINT ["./main"] \ No newline at end of file +ENTRYPOINT ["./main"] diff --git a/nim-test-node/kad-dht/README.md b/nim-test-node/kad-dht/README.md index 66095185..0032ba06 100644 --- a/nim-test-node/kad-dht/README.md +++ b/nim-test-node/kad-dht/README.md @@ -13,8 +13,10 @@ This commit is already set in .nimble file. If you want to build with Docker, you can do it with: ``` +cd .. docker buildx build \ --platform linux/amd64 \ + -f kad-dht/Dockerfile \ -t docker.io// \ --push \ . diff --git a/nim-test-node/kad-dht/core.nim b/nim-test-node/kad-dht/core.nim index 005c29b8..c28e9c41 100644 --- a/nim-test-node/kad-dht/core.nim +++ b/nim-test-node/kad-dht/core.nim @@ -6,6 +6,7 @@ import sequtils, math, metrics, metrics/chronos_httpserver import chronicles import env import helpers +import ../common/peer_ids logScope: topics = "dst" @@ -14,7 +15,7 @@ from times import getTime, Time, toUnix, fromUnix, `-`, initTime, `$`, inMillise # --- Core Logic --- -proc runWarmup*(kad: KadDHT, selfId: PeerId) {.async.} = +proc runWarmup*[R](kad: KadDHT, selfId: PeerId, rng: R) {.async.} = info "Starting warmup phase" # 5x FIND_NODE(self) @@ -30,9 +31,8 @@ proc runWarmup*(kad: KadDHT, selfId: PeerId) {.async.} = await sleepAsync(1.seconds) # 15x FIND_NODE(random) - for i in 1 .. 15: - let target = getRandomPeerId() - debug "Warmup: Finding random node", iteration = i, target = target + for i, target in randomPeerIds(rng, 15): + debug "Warmup: Finding random node", iteration = i + 1, target = target let peers = await kad.findNode(target.toKey()) @@ -40,11 +40,11 @@ proc runWarmup*(kad: KadDHT, selfId: PeerId) {.async.} = info "Warmup complete" -proc runProbe*(kad: KadDHT) {.async.} = +proc runProbe*[R](kad: KadDHT, rng: R) {.async.} = info "Starting probe loop" while true: let - targetPeer = getRandomPeerId() + targetPeer = randomPeerId(rng) targetKey = targetPeer.toKey() try: diff --git a/nim-test-node/kad-dht/helpers.nim b/nim-test-node/kad-dht/helpers.nim index 8c36cada..0c2769ac 100644 --- a/nim-test-node/kad-dht/helpers.nim +++ b/nim-test-node/kad-dht/helpers.nim @@ -1,5 +1,5 @@ import libp2p -import chronos, chronos/apps/http/httpserver +import chronos import chronicles import libp2p/protocols/[kademlia, kad_disco] import os @@ -8,13 +8,6 @@ import env logScope: topics = "dst" -# --- Helpers --- - -proc getRandomPeerId*(): PeerId = - # Generates a random peer ID for FIND_NODE targets - let rng = newRng() - return PeerId.init(PrivateKey.random(Secp256k1, rng[]).get()).get() - proc buildSwitch*(muxer: string, address: string): Switch = var builder = SwitchBuilder .new() @@ -91,28 +84,3 @@ proc connectToBootstraps*( ) ok(bootstraps) - -proc startHealthServer*(port: Port): Future[HttpServerRef] {.async.} = - proc handler(request: RequestFence): Future[HttpResponseRef] {.async.} = - if request.isErr(): - return defaultResponse() - - let req = request.get() - - if req.meth == MethodGet and (req.uri.path == "/health" or req.uri.path == "/ready"): - return await req.respond( - Http200, "ok", HttpTable.init([("Content-Type", "text/plain")]) - ) - - return await req.respond(Http404, "Not Found") - - let addrs = initTAddress("0.0.0.0:" & $port) - let serverRes = HttpServerRef.new(addrs, handler) - if serverRes.isErr(): - raise newException( - CatchableError, "Failed to create health HTTP server: " & $serverRes.error - ) - - let server = serverRes.get() - server.start() - return server diff --git a/nim-test-node/kad-dht/main.nim b/nim-test-node/kad-dht/main.nim index a145b616..08d8a7e0 100644 --- a/nim-test-node/kad-dht/main.nim +++ b/nim-test-node/kad-dht/main.nim @@ -13,6 +13,8 @@ from times import getTime, Time, toUnix, fromUnix, `-`, initTime, `$`, inMillise from nativesockets import getHostname import helpers import core +import ../common/health_server +import ../common/shutdown logScope: topics = "dst" @@ -40,8 +42,7 @@ proc main() {.async.} = var kad = await mountDiscovery(switch, discovery, @[]) discard await startHealthServer(prometheusPort) # Just stay alive and serve queries - while true: - await sleepAsync(1.hours) + await waitShutdownSignal() of RoleNormal: let jitter = myId * 200 if jitter > 0: @@ -54,11 +55,10 @@ proc main() {.async.} = quit(1) var kad = await mountDiscovery(switch, discovery, bootAddresses) - await runWarmup(kad, selfId) + await runWarmup(kad, selfId, rng) discard await startHealthServer(prometheusPort) # Keep node alive for steady state refresh - while true: - await sleepAsync(1.hours) + await waitShutdownSignal() of RoleProbe: let jitter = myId * 200 if jitter > 0: @@ -71,8 +71,6 @@ proc main() {.async.} = quit(1) var kad = await mountDiscovery(switch, discovery, bootAddresses) - await runProbe(kad) - while true: - await sleepAsync(1.hours) + await runProbe(kad, rng) waitFor(main()) diff --git a/nim-test-node/regression/Dockerfile b/nim-test-node/regression/Dockerfile index 7beacbb0..a4536cba 100644 --- a/nim-test-node/regression/Dockerfile +++ b/nim-test-node/regression/Dockerfile @@ -1,7 +1,7 @@ ARG NIM_BUILDPLATFORM=linux/amd64 FROM --platform=${NIM_BUILDPLATFORM} nimlang/nim:2.2.10 AS builder -WORKDIR /node +WORKDIR /node/regression RUN apt-get update && apt-get install -y --no-install-recommends \ git \ @@ -21,10 +21,11 @@ RUN git config --global http.version HTTP/1.1 RUN nimble install -y 'nimble@#07caee397d628c9e93d81048268365c4c2414a80' ENV PATH="/root/.nimble/bin:${PATH}" -COPY test_node.nimble nimble.lock config.nims ./ +COPY regression/test_node.nimble regression/nimble.lock regression/config.nims ./ RUN nimble refresh && nimble setup -COPY . . +COPY common /node/common +COPY regression/. . ARG TARGETARCH ARG NODE_BINARY=node diff --git a/nim-test-node/regression/Dockerfile_shadow b/nim-test-node/regression/Dockerfile_shadow index 2de995ad..8382c350 100644 --- a/nim-test-node/regression/Dockerfile_shadow +++ b/nim-test-node/regression/Dockerfile_shadow @@ -15,7 +15,7 @@ FROM debian:bookworm-slim AS builder ARG NODE_BINARY=node ARG NIM_VERSION=2.2.6 -WORKDIR /node +WORKDIR /node/regression RUN apt-get update && apt-get install -y --no-install-recommends \ curl git build-essential ca-certificates \ @@ -33,14 +33,15 @@ RUN curl -fsSL "https://nim-lang.org/download/nim-${NIM_VERSION}-linux_x64.tar.x && ln -sf "/usr/local/nim-${NIM_VERSION}/bin/nim" /usr/local/bin/nim \ && ln -sf "/usr/local/nim-${NIM_VERSION}/bin/nimble" /usr/local/bin/nimble -COPY . . +COPY common /node/common +COPY regression/. . RUN nimble refresh RUN nimble install -dy --verbose # Floor lsquic's engine tick re-arms so Shadow can advance simulated time. # Gated by LSQUIC_TICK_FLOOR_US (unset/0 = stock). See README.md. -COPY lsquic-tick-floor.patch /tmp/lsquic-tick-floor.patch +COPY regression/lsquic-tick-floor.patch /tmp/lsquic-tick-floor.patch RUN set -eu; \ patched=0; \ for d in /root/.nimble/pkgcache/*lsquic*/ /root/.nimble/pkgs2/lsquic-*/; do \ diff --git a/nim-test-node/regression/README.md b/nim-test-node/regression/README.md index 0190fc9f..0628f978 100644 --- a/nim-test-node/regression/README.md +++ b/nim-test-node/regression/README.md @@ -45,17 +45,19 @@ message delay and expose metrics on port `8008`. The normal Dockerfile can build four image variants: ```bash +# Run these commands from nim-test-node/ so the shared common modules are in context. + # amd64 normal node -docker buildx build --platform linux/amd64 -f Dockerfile -t regression-node-amd64 --load . +docker buildx build --platform linux/amd64 -f regression/Dockerfile -t regression-node-amd64 --load . # amd64 bootstrap node -docker buildx build --platform linux/amd64 -f Dockerfile --build-arg NODE_BINARY=bootstrap -t regression-bootstrap-amd64 --load . +docker buildx build --platform linux/amd64 -f regression/Dockerfile --build-arg NODE_BINARY=bootstrap -t regression-bootstrap-amd64 --load . # arm64 normal node -docker buildx build --platform linux/arm64 -f Dockerfile -t regression-node-arm64 --load . +docker buildx build --platform linux/arm64 -f regression/Dockerfile -t regression-node-arm64 --load . # arm64 bootstrap node -docker buildx build --platform linux/arm64 -f Dockerfile --build-arg NODE_BINARY=bootstrap -t regression-bootstrap-arm64 --load . +docker buildx build --platform linux/arm64 -f regression/Dockerfile --build-arg NODE_BINARY=bootstrap -t regression-bootstrap-arm64 --load . ``` The container entrypoint is always `/node/main`, even for the bootstrap image. @@ -67,13 +69,13 @@ For a registry push, replace `--load` with `--push` and use the full registry image name: ```bash -docker buildx build --platform linux/amd64 -f Dockerfile -t /regression-node-amd64: --push . +docker buildx build --platform linux/amd64 -f regression/Dockerfile -t /regression-node-amd64: --push . ``` Example: ```bash -docker buildx build --platform linux/amd64 -f Dockerfile -t ghcr.io/vacp2p/dst-libp2p-test-node/regression-node:v0.1.0 --push . +docker buildx build --platform linux/amd64 -f regression/Dockerfile -t ghcr.io/vacp2p/dst-libp2p-test-node/regression-node:v0.1.0 --push . ``` ## Runtime knobs @@ -148,4 +150,4 @@ The build asserts it patched something and greps the binary for - `albertodst/regression-node-arm64:v2.4.0` - Bootstrap: - `albertodst/regression-bootstrap-amd64:v2.4.0` - - `albertodst/regression-bootstrap-arm64:v2.4.0` \ No newline at end of file + - `albertodst/regression-bootstrap-arm64:v2.4.0` diff --git a/nim-test-node/regression/bootstrap/main.nim b/nim-test-node/regression/bootstrap/main.nim index 7895a3c4..d4d099f6 100644 --- a/nim-test-node/regression/bootstrap/main.nim +++ b/nim-test-node/regression/bootstrap/main.nim @@ -7,7 +7,7 @@ import libp2p import ../env import ../node_setup -import ../shutdown_utils +import ../../common/shutdown logScope: topics = "dst" diff --git a/nim-test-node/regression/node/main.nim b/nim-test-node/regression/node/main.nim index 4cc1a72e..c7059ab9 100644 --- a/nim-test-node/regression/node/main.nim +++ b/nim-test-node/regression/node/main.nim @@ -14,7 +14,7 @@ import ../env import ../ping_utils import ../kad_utils import ../node_setup -import ../shutdown_utils +import ../../common/shutdown logScope: topics = "dst" diff --git a/nim-test-node/service-discovery/Dockerfile b/nim-test-node/service-discovery/Dockerfile index 5641a246..edac8ff9 100644 --- a/nim-test-node/service-discovery/Dockerfile +++ b/nim-test-node/service-discovery/Dockerfile @@ -14,12 +14,13 @@ RUN curl https://nim-lang.org/choosenim/init.sh -sSf | sh -s -- -y ENV PATH="/root/.nimble/bin:${PATH}" RUN git config --global http.sslVerify false -WORKDIR /node -COPY test_node.nimble . +WORKDIR /node/service-discovery +COPY service-discovery/test_node.nimble . RUN nimble install -dy -COPY *.nim . +COPY common /node/common +COPY service-discovery/*.nim . RUN nimble c \ -d:chronicles_colors=None --threads:on --mm:refc \ diff --git a/nim-test-node/service-discovery/helpers.nim b/nim-test-node/service-discovery/helpers.nim index 7790e772..15f80444 100644 --- a/nim-test-node/service-discovery/helpers.nim +++ b/nim-test-node/service-discovery/helpers.nim @@ -1,5 +1,5 @@ import strutils, sequtils -import chronos, chronos/apps/http/httpserver +import chronos import chronicles import libp2p, libp2p/[multiaddress] import libp2p/protocols/[kademlia, service_discovery] @@ -137,28 +137,3 @@ proc mountServiceDiscovery*( switch.mount(disco) disco - -proc startHealthServer*(port: Port): Future[HttpServerRef] {.async.} = - proc handler(request: RequestFence): Future[HttpResponseRef] {.async.} = - if request.isErr(): - return defaultResponse() - - let req = request.get() - - if req.meth == MethodGet and (req.uri.path == "/health" or req.uri.path == "/ready"): - return await req.respond( - Http200, "ok", HttpTable.init([("Content-Type", "text/plain")]) - ) - - return await req.respond(Http404, "Not Found") - - let addrs = initTAddress("0.0.0.0:" & $port) - let serverRes = HttpServerRef.new(addrs, handler) - if serverRes.isErr(): - raise newException( - CatchableError, "Failed to create health HTTP server: " & $serverRes.error - ) - - let server = serverRes.get() - server.start() - server diff --git a/nim-test-node/service-discovery/main.nim b/nim-test-node/service-discovery/main.nim index 00f98629..1572d591 100644 --- a/nim-test-node/service-discovery/main.nim +++ b/nim-test-node/service-discovery/main.nim @@ -4,6 +4,8 @@ import libp2p, libp2p/[multiaddress] import libp2p/extended_peer_record import libp2p/protocols/kademlia import env, helpers, core +import ../common/health_server +import ../common/shutdown logScope: topics = "dst" @@ -48,12 +50,10 @@ proc main() {.async.} = case cfg.role of RoleBootstrap: info "Bootstrap role active" - while true: - await sleepAsync(1.hours) + await waitShutdownSignal() of RoleAdvertiser: disco.startAdvertisingServices(advertisedServices) - while true: - await sleepAsync(1.hours) + await waitShutdownSignal() of RoleDiscoverer: disco.startDiscoveringServicesLog(cfg.discoverServices) await disco.runLookupLoop(cfg.discoverServices, cfg.lookupInterval) diff --git a/nim-test-node/service-discovery/run.sh b/nim-test-node/service-discovery/run.sh index 1fd7978a..ef498cef 100755 --- a/nim-test-node/service-discovery/run.sh +++ b/nim-test-node/service-discovery/run.sh @@ -4,13 +4,14 @@ set -euo pipefail IMAGE_NAME="soutullostatus/dst-test-node-service-discovery" NETWORK_NAME="service-discovery-network" +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" echo "Cleaning previous environment..." docker rm -f sd-bootstrap sd-advertiser sd-discoverer 2>/dev/null || true docker network rm "${NETWORK_NAME}" 2>/dev/null || true echo "Building image..." -docker build -t "${IMAGE_NAME}" . +docker build -f "${SCRIPT_DIR}/Dockerfile" -t "${IMAGE_NAME}" "${SCRIPT_DIR}/.." echo "Creating network..." docker network create "${NETWORK_NAME}" diff --git a/shadow/Dockerfile b/shadow/Dockerfile index 38a0c27c..f2bb2b67 100644 --- a/shadow/Dockerfile +++ b/shadow/Dockerfile @@ -3,7 +3,7 @@ # Ubuntu 22.04 + Shadow built from source + the pod-api-requester (the in-Shadow # traffic publisher, run by the `publisher` host in batch mode). # No nim test-node binary baked in: per-experiment dynamic test-node images -# (built from nim-test-node/Dockerfile_amd64_shadow) ship the `main` binary +# (built from nim-test-node/regression/Dockerfile_shadow) ship the `main` binary # separately. A Job spec uses an init container to copy `main` from the # per-experiment image into an emptyDir, then runs Shadow from this image. # diff --git a/shadow/kaniko-build-test-node-job.yaml b/shadow/kaniko-build-test-node-job.yaml index a2ce7ce6..e4e2c355 100644 --- a/shadow/kaniko-build-test-node-job.yaml +++ b/shadow/kaniko-build-test-node-job.yaml @@ -37,8 +37,8 @@ spec: image: gcr.io/kaniko-project/executor:v1.23.2 args: - "--context=git://github.com/vacp2p/dst-libp2p-test-node.git#refs/heads/master" - - "--context-sub-path=nim-test-node/regression" - - "--dockerfile=Dockerfile_amd64_shadow" + - "--context-sub-path=nim-test-node" + - "--dockerfile=regression/Dockerfile_shadow" - "--destination=radiken/dst-test-node-shadow:latest" - "--cache=true" - "--cache-repo=radiken/dst-test-node-shadow-cache"