Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Docker resources check on Windows #808

Merged
17 changes: 11 additions & 6 deletions src/services/DockerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,19 @@ export class DockerService implements IService{

public async checkDockerResources(isMultiNodeMode: boolean) {
this.logger.info(`${LOADING} Checking docker resources...`, this.serviceName);
const resultDockerInfoCommand = await shell.exec(
"docker system info --format='{{json .}}'",
{ silent: true }

const ncpu = await shell.exec(
"docker info --format='{{.NCPU}}'",
{ silent: true }
);

const memTotal = await shell.exec(
"docker info --format='{{.MemTotal}}'",
{ silent: true }
);

const systemInfoJson = JSON.parse(resultDockerInfoCommand.stdout);
const dockerMemory = Math.round(systemInfoJson['MemTotal'] / Math.pow(1024, 3));
const dockerCPUs = systemInfoJson['NCPU'];
const dockerMemory = Math.round(parseInt(memTotal) / Math.pow(1024, 3));
const dockerCPUs = parseInt(ncpu);

return this.checkMemoryResources(dockerMemory, isMultiNodeMode) &&
this.checkCPUResources(dockerCPUs);
Expand Down
25 changes: 13 additions & 12 deletions test/unit/states/StopState.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ import { expect } from 'chai';
import sinon from 'sinon';
import { StopState } from '../../../src/state/StopState';
import {
DOCKER_CLEANING_VALUMES_MESSAGE,
DOCKER_STOPPING_CONTAINERS_MESSAGE,
NETWORK_PREFIX,
STOP_STATE_INIT_MESSAGE,
STOP_STATE_ON_START_MESSAGE,
STOP_STATE_STOPPED_MESSAGE,
STOP_STATE_STOPPING_MESSAGE
} from '../../../src/constants';
DOCKER_CLEANING_VALUMES_MESSAGE,
DOCKER_STOPPING_CONTAINERS_MESSAGE,
IS_WINDOWS,
NETWORK_PREFIX,
STOP_STATE_INIT_MESSAGE,
STOP_STATE_ON_START_MESSAGE,
STOP_STATE_STOPPED_MESSAGE,
STOP_STATE_STOPPING_MESSAGE,
} from "../../../src/constants";
import path from 'path';
import { getTestBed } from '../testBed';
import { LoggerService } from '../../../src/services/LoggerService';
Expand Down Expand Up @@ -102,10 +103,10 @@ describe('StopState tests', () => {
testSandbox.assert.calledThrice(shellCDStub);

// shell commands: 'exec'
testSandbox.assert.calledWith(shellExecStub, 'docker compose kill --remove-orphans 2>/dev/null');
testSandbox.assert.calledWith(shellExecStub, 'docker compose down -v --remove-orphans 2>/dev/null');
testSandbox.assert.calledWith(shellExecStub, 'rm -rf network-logs/* >/dev/null 2>&1');
testSandbox.assert.calledWith(shellExecStub, 'rm -rf "testDir/network-logs" >/dev/null 2>&1');
testSandbox.assert.calledWith(shellExecStub, `docker compose kill --remove-orphans 2>${IS_WINDOWS ? 'null' : '/dev/null'}`);
testSandbox.assert.calledWith(shellExecStub, `docker compose down -v --remove-orphans 2>${IS_WINDOWS ? 'null' : '/dev/null'}`);
testSandbox.assert.calledWith(shellExecStub, `rm -rf network-logs/* >${IS_WINDOWS ? 'null' : '/dev/null'} 2>&1`);
testSandbox.assert.calledWith(shellExecStub, `rm -rf "testDir/network-logs" >${IS_WINDOWS ? 'null' : '/dev/null'} 2>&1`);
testSandbox.assert.calledWith(shellExecStub, `docker network ls --filter name=${NETWORK_PREFIX} --format "{{.ID}}"`);

expect(processTest.processCWDStub.calledOnce).to.be.true;
Expand Down
Loading