Skip to content

Commit

Permalink
fix: add support for docker compose without minus
Browse files Browse the repository at this point in the history
  • Loading branch information
thepiwo committed Jul 25, 2022
1 parent 92fec89 commit 6e44339
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/env/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ const { spawn, exec } = require('promisify-child-process');
const { print, printError, awaitNodeAvailable } = require('../utils/utils');
const { nodeConfiguration, compilerConfiguration, proxyConfiguration } = require('../config/node-config.json');

let dockerComposeCmd = 'docker compose';

async function getDockerCompose() {
const dockerSpaceCompose = await spawn('docker compose').catch(() => ({ code: 1 }));
if (dockerSpaceCompose.code === 0) return;
const dockerMinusCompose = await spawn('docker-compose').catch(() => ({ code: 1 }));
if (dockerMinusCompose.code === 0) {
dockerComposeCmd = 'docker-compose';
return;
}

throw new Error('===== docker compose is not installed! =====');
}

async function isEnvRunning(cwd = './') {
const info = await getInfo(cwd);

Expand Down Expand Up @@ -48,7 +62,8 @@ async function stopEnv(running) {

print('===== stopping env =====');

await spawn('docker-compose', [
await getDockerCompose();
await spawn(dockerComposeCmd, [
'down',
'-v',
]);
Expand All @@ -59,8 +74,9 @@ async function stopEnv(running) {
async function startEnv(nodeVersion, compilerVersion) {
print('===== starting env =====');

await exec(`NODE_TAG=${nodeVersion} COMPILER_TAG=${compilerVersion} docker-compose pull`);
await exec(`NODE_TAG=${nodeVersion} COMPILER_TAG=${compilerVersion} docker-compose up -d`);
await getDockerCompose();
await exec(`NODE_TAG=${nodeVersion} COMPILER_TAG=${compilerVersion} ${dockerComposeCmd} pull`);
await exec(`NODE_TAG=${nodeVersion} COMPILER_TAG=${compilerVersion} ${dockerComposeCmd} up -d`);

await awaitNodeAvailable();

Expand All @@ -77,7 +93,8 @@ async function printInfo(running) {
}

async function getInfo(cwd) {
const info = await exec('docker-compose ps', { cwd });
await getDockerCompose();
const info = await exec(`${dockerComposeCmd} ps`, { cwd });

if (info && info.stdout) {
return info.stdout;
Expand Down

0 comments on commit 6e44339

Please sign in to comment.