From 80101f83aa88b1e32466ecb276d83b5cafef4280 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Fri, 5 Apr 2024 14:48:40 +0100 Subject: [PATCH] fix: fix dns lookup for dnsrr --- docker-compose.yml | 6 +++--- package-lock.json | 1 + package.json | 1 + src/core/AnonymizedFile.ts | 13 +++++++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index d2ba3ad..5691041 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,7 +24,7 @@ services: interval: 10s timeout: 10s retries: 5 - links: + depends_on: - mongodb - redis - streamer @@ -34,9 +34,9 @@ services: restart: always image: tdurieux/anonymous_github:v2 deploy: - mode: replicated + qmode: replicated replicas: 4 - endpoint_mode: vip + endpoint_mode: dnsrr entrypoint: ["node", "./build/streamer/index.js"] env_file: - ./.env diff --git a/package-lock.json b/package-lock.json index a68806d..a3d8bfa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,6 +25,7 @@ "@smithy/node-http-handler": "^2.5.0", "archiver": "^5.3.2", "bullmq": "^2.4.0", + "cacheable-lookup": "^5.0.3", "compression": "^1.7.4", "connect-redis": "^7.0.1", "crypto-js": "^4.2.0", diff --git a/package.json b/package.json index 9d55361..fd29d1e 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "@smithy/node-http-handler": "^2.5.0", "archiver": "^5.3.2", "bullmq": "^2.4.0", + "cacheable-lookup": "^5.0.3", "compression": "^1.7.4", "connect-redis": "^7.0.1", "crypto-js": "^4.2.0", diff --git a/src/core/AnonymizedFile.ts b/src/core/AnonymizedFile.ts index 1f9233c..a0e3eb9 100644 --- a/src/core/AnonymizedFile.ts +++ b/src/core/AnonymizedFile.ts @@ -3,6 +3,7 @@ import { Response } from "express"; import { Readable } from "stream"; import { trace } from "@opentelemetry/api"; import { lookup } from "mime-types"; +import CacheableLookup from "cacheable-lookup"; import Repository from "./Repository"; import { RepositoryStatus, Tree, TreeElement, TreeFile } from "./types"; @@ -227,9 +228,16 @@ export default class AnonymizedFile { span.end(); }); } + + const cacheableLookup = new CacheableLookup(); + const ipHost = await cacheableLookup.lookupAsync("streamer"); + // use the streamer service return got.stream(join(config.STREAMER_ENTRYPOINT, "api"), { method: "POST", + lookup: cacheableLookup.lookup, + host: ipHost.address, + dnsCache: cacheableLookup, json: { token: await this.repository.getToken(), repoFullName: this.repository.model.source.repositoryName, @@ -274,9 +282,14 @@ export default class AnonymizedFile { this.sha(), this.repository.getToken(), ]); + const cacheableLookup = new CacheableLookup(); + const ipHost = await cacheableLookup.lookupAsync("streamer"); got .stream(join(config.STREAMER_ENTRYPOINT, "api"), { method: "POST", + lookup: cacheableLookup.lookup, + host: ipHost.address, + dnsCache: cacheableLookup, json: { sha, token,