diff --git a/docker/docker-compose-ci.yml b/docker/docker-compose-ci.yml index 5a852e492..c1415e0f7 100644 --- a/docker/docker-compose-ci.yml +++ b/docker/docker-compose-ci.yml @@ -11,6 +11,8 @@ services: - '8081:8081' depends_on: - mongo + extra_hosts: + - 'host.docker.internal:host-gateway' mongo: image: 'mongo:latest' container_name: 'mongo' diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index c03eda524..1837e17ed 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -9,3 +9,5 @@ services: ports: - '8080:8080' - '8081:8081' + extra_hosts: + - 'host.docker.internal:host-gateway' diff --git a/packages/sdk/test/integration/integration_helper.ts b/packages/sdk/test/integration/integration_helper.ts index 0b2b74701..5c35a37d7 100644 --- a/packages/sdk/test/integration/integration_helper.ts +++ b/packages/sdk/test/integration/integration_helper.ts @@ -3,10 +3,29 @@ import yorkie, { SyncMode } from '@yorkie-js-sdk/src/yorkie'; import { Client } from '@yorkie-js-sdk/src/client/client'; import { Document } from '@yorkie-js-sdk/src/document/document'; import { Indexable } from '@yorkie-js-sdk/test/helper/helper'; +import { execSync } from 'child_process'; export const testRPCAddr = process.env.TEST_RPC_ADDR || 'http://127.0.0.1:8080'; export const testAPIID = process.env.TEST_API_ID || 'admin'; export const testAPIPW = process.env.TEST_API_PW || 'admin'; +function isRunningInDocker() { + if (process.env.CI === 'true') { + return true; + } + + try { + const result = execSync( + 'docker ps --filter "name=^/yorkie$" --format "{{.Names}}"', + { + stdio: 'pipe', + }, + ); + return result && result.toString().trim() !== ''; + } catch (error) { + return false; + } +} +export const webhookAddr = isRunningInDocker() && 'host.docker.internal'; export function toDocKey(title: string): string { return title diff --git a/packages/sdk/test/integration/webhook_test.ts b/packages/sdk/test/integration/webhook_test.ts index c86d69685..21979facb 100644 --- a/packages/sdk/test/integration/webhook_test.ts +++ b/packages/sdk/test/integration/webhook_test.ts @@ -30,6 +30,7 @@ import { testRPCAddr, testAPIID, testAPIPW, + webhookAddr, } from '@yorkie-js-sdk/test/integration/integration_helper'; import { ConnectError } from '@connectrpc/connect'; import axios from 'axios'; @@ -84,10 +85,7 @@ describe('Auth Webhook', () => { // Start webhook server webhookServerInstance = webhookServer.listen(webhookServerPort, () => { const addr = webhookServerInstance.address(); - webhookServerAddress = - addr.address === '::' || addr.address === '0.0.0.0' - ? 'localhost' - : addr.address; + webhookServerAddress = webhookAddr || addr.address; }); // Login to yorkie