diff --git a/src/cli.ts b/src/cli.ts index 679b2cb..5b05972 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,9 +1,9 @@ import { Command } from 'commander' import { existsSync, mkdirSync } from 'fs' import { capture, run } from '~/shell' -import { exit, parseAndRemoveWildcardOptions, pp } from '~/utils' -import icons from '~/icons' +import { exit, parseAndRemoveWildcardOptions, pp, requireDockerVersion } from '~/utils' import { StaxConfig } from '~/types' +import icons from '~/icons' import Stax from '~/stax' import * as path from 'path' import tmp from 'tmp' @@ -217,6 +217,8 @@ program.command('setup') .option('--progress ', 'Set type of progress output') .description('Setup an application') .action(async (location, options) => { + requireDockerVersion(27.0, 2.29) + if (location) { const app = await stax.setup({ source: location, ...options }, { ...options, overrides: overrides }) console.log('\n' + app.installedMessage()) diff --git a/src/utils.ts b/src/utils.ts index c233968..fecde52 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,5 @@ import { existsSync, statSync } from 'fs' +import { capture } from '~/shell' import tmp from 'tmp' import icons from './icons' import yaml from 'js-yaml' @@ -442,3 +443,19 @@ export function deepMapWithKeys( return Object.fromEntries(entries) } + +export function requireDockerVersion(minDockerVersion: number, minComposeVersion: number) { + const dockerVersion = capture('docker version --format "{{.Server.Version}}"').trim() + const [dockerMajor, dockerMinor] = (dockerVersion || '').split('.') + + if (!dockerVersion || parseFloat(`${dockerMajor}.${dockerMinor}`) < minDockerVersion) + return exit(1, { message: `Docker version >= ${minDockerVersion} required. Found: ${dockerVersion || 'not installed'}` }) + + const composeVersion = capture('docker compose version --short').trim() + const [composeMajor, composeMinor] = (composeVersion || '').split('.') + + if (!composeVersion || + parseFloat(`${composeMajor}.${composeMinor}`) < minComposeVersion) + + return exit(1, { message: `Docker Compose version >=${minComposeVersion}.0 required. Found: ${composeVersion || 'not installed'}` }) +}