Skip to content

Commit

Permalink
chore: reduce the amont of DNS reloads
Browse files Browse the repository at this point in the history
  • Loading branch information
darlanalves authored Jan 15, 2024
1 parent c69f214 commit 8f3a5fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
17 changes: 9 additions & 8 deletions src/containers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import { exec } from '@cloud-cli/exec';
import { ServerParams } from '@cloud-cli/cli';
import { findContainer, listContainers } from './store.js';
import { getConfig } from './config.js';
import { EnvList, addExecFlag, getEnvVars, getListFromString, getPorts } from './utils.js';
import {
EnvList,
addExecFlag,
getEnvVars,
getListFromString,
getPorts,
} from './utils.js';

export async function getRunningContainers(): Promise<string[]> {
const ps = await exec('docker', ['ps', '--format', '{{.Names}}']);
Expand Down Expand Up @@ -36,11 +42,7 @@ export async function getLogs({ name, lines }: GetLogsOptions): Promise<string>

const sh = await exec('docker', args);

if (sh.ok) {
return [sh.stdout, sh.stderr].join('\n');
}

return '';
return [sh.stderr, sh.stdout].join('\n---\n');
}

export async function startAll(_: any, cli: any) {
Expand Down Expand Up @@ -139,14 +141,13 @@ export async function stopContainer(options: ContainerName, { run }: ServerParam
throw new Error('Name is required');
}

await exec('docker', ['stop', '-t', '5', name]);
await exec('docker', ['stop', '-t', '1', name]);
await exec('docker', ['rm', name]);

const containers = [await findContainer(name)].filter(Boolean);

for (const container of containers) {
await run('dns.remove', { domain: container.host });
await run('dns.reload', {});
}

return true;
Expand Down
11 changes: 0 additions & 11 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,6 @@ describe('running containers', () => {
});

describe('logs', () => {
it('should return an empty string if failed', async () => {
execMocks.exec.mockResolvedValueOnce({
ok: false,
stdout: 'Running...',
});

const output = dx.logs({ name: 'test' });

await expect(output).resolves.toEqual('');
});

it('should throw an error', async () => {
const output = dx.logs({ name: '' });

Expand Down

0 comments on commit 8f3a5fb

Please sign in to comment.