Skip to content

Commit

Permalink
Update webhook address for Docker container access
Browse files Browse the repository at this point in the history
  • Loading branch information
chacha912 committed Nov 5, 2024
1 parent dcc6d47 commit 9454843
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docker/docker-compose-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ services:
- '8081:8081'
depends_on:
- mongo
extra_hosts:
- 'host.docker.internal:host-gateway'
mongo:
image: 'mongo:latest'
container_name: 'mongo'
Expand Down
2 changes: 2 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ services:
ports:
- '8080:8080'
- '8081:8081'
extra_hosts:
- 'host.docker.internal:host-gateway'
19 changes: 19 additions & 0 deletions packages/sdk/test/integration/integration_helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 isYorkieContainerRunning() {
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 = isYorkieContainerRunning() && 'host.docker.internal';

export function toDocKey(title: string): string {
return title
Expand Down
6 changes: 2 additions & 4 deletions packages/sdk/test/integration/webhook_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9454843

Please sign in to comment.