Skip to content

Commit

Permalink
require docker 27 and compose 2.29
Browse files Browse the repository at this point in the history
  • Loading branch information
kla committed Nov 19, 2024
1 parent da62bab commit f213ab2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -217,6 +217,8 @@ program.command('setup')
.option('--progress <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())
Expand Down
17 changes: 17 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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'}` })
}

0 comments on commit f213ab2

Please sign in to comment.