Skip to content

Commit

Permalink
feat: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Apr 12, 2024
1 parent 7bc5680 commit 922fec8
Showing 1 changed file with 5 additions and 28 deletions.
33 changes: 5 additions & 28 deletions test/e2e/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,11 @@ class DockerManager {
}

public async createApiContainer () {
let networkMode = 'host';
let redisUrl = config.get<string>('redis.url');
let dbConnectionHost = config.get<string>('db.connection.host');
const networkMode = 'bridge';
const redisUrl = config.get<string>('redis.url').replace('localhost', 'host.docker.internal');
const dbConnectionHost = config.get<string>('db.connection.host').replace('localhost', 'host.docker.internal');
const processes = config.get<string>('server.processes');

const isLinux = await this.isLinuxHost();

if (!isLinux) {
networkMode = 'bridge';
redisUrl = redisUrl.replace('localhost', 'host.docker.internal');
dbConnectionHost = dbConnectionHost.replace('localhost', 'host.docker.internal');
}

// docker run -e NODE_ENV=test -e TEST_MODE=e2e -e NEW_RELIC_ENABLED=false -e REDIS_URL=redis://host.docker.internal:6379 -e DB_CONNECTION_HOST=host.docker.internal --name globalping-api-e2e globalping-api-e2e
const container = await this.docker.createContainer({
Image: 'globalping-api-e2e',
Expand All @@ -52,15 +44,8 @@ class DockerManager {
}

public async createProbeContainer () {
let networkMode = 'host';
let apiHost = 'ws://localhost:80';

const isLinux = await this.isLinuxHost();

if (!isLinux) {
networkMode = 'bridge';
apiHost = apiHost.replace('localhost', 'host.docker.internal');
}
const networkMode = 'bridge';
const apiHost = 'ws://localhost:80'.replace('localhost', 'host.docker.internal');

// docker run -e API_HOST=ws://host.docker.internal:80 --name globalping-probe-e2e globalping-probe-e2e
console.log({
Expand Down Expand Up @@ -131,14 +116,6 @@ class DockerManager {
await container.start({});
}

private async isLinuxHost (): Promise<boolean> {
const versionInfo = await this.docker.version();
const platformName = versionInfo.Platform.Name.toLowerCase();
console.log('versionInfo.Platform');
console.log(versionInfo.Platform);
return platformName.includes('engine');
}

private async attachLogs (container: Docker.Container) {
const stream = await container.logs({
follow: true,
Expand Down

0 comments on commit 922fec8

Please sign in to comment.