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: move to docker compose v2 #626

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/commands/d2-cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Which will output something like this:

```sh
Commands:
d2 cluster compose <name> Run arbitrary docker-compose commands
d2 cluster compose <name> Run arbitrary docker compose commands
against a DHIS2 cluster.
NOTE: pass -- after <name> [aliases: c]
d2 cluster db Manage the database in a DHIS2 Docker
Expand Down
11 changes: 6 additions & 5 deletions packages/cluster/src/commands/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const run = async function (argv) {
const cfg = await resolveConfiguration(argv)

const args = _.slice(_.findIndex(x => x === 'compose') + 1)
reporter.debug('Passing arguments to docker-compose', args)
reporter.debug('Passing arguments to docker compose', args)

const cacheLocation = await initDockerComposeCache({
composeProjectName: name,
Expand All @@ -27,10 +27,11 @@ const run = async function (argv) {
process.exit(1)
}
const res = await tryCatchAsync(
'exec(docker-compose)',
'exec(docker compose)',
spawn(
'docker-compose',
'docker',
[
'compose',
'-p',
makeComposeProject(name),
'-f',
Expand All @@ -47,14 +48,14 @@ const run = async function (argv) {
)
)
if (res.err) {
reporter.error('Failed to run docker-compose command')
reporter.error('Failed to run docker compose command')
process.exit(1)
}
}

module.exports = {
command: 'compose <name>',
desc: 'Run arbitrary docker-compose commands against a DHIS2 cluster.\nNOTE: pass -- after <name>',
desc: 'Run arbitrary docker compose commands against a DHIS2 cluster.\nNOTE: pass -- after <name>',
aliases: 'c',
handler: run,
}
5 changes: 3 additions & 2 deletions packages/cluster/src/commands/down.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ const run = async function (argv) {
reporter.info(`Winding down cluster ${chalk.cyan(name)}`)
try {
await exec({
cmd: 'docker-compose',
cmd: 'docker',
args: [
'compose',
'-p',
makeComposeProject(name),
'-f',
Expand All @@ -46,7 +47,7 @@ const run = async function (argv) {
})
}
} catch (e) {
reporter.error('Failed to execute docker-compose', e)
reporter.error('Failed to execute docker compose', e)
process.exit(1)
}
}
Expand Down
5 changes: 3 additions & 2 deletions packages/cluster/src/commands/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ const run = async function (argv) {
)

const res = await tryCatchAsync(
'exec(docker-compose)',
'exec(docker compose)',
exec({
cmd: 'docker-compose',
cmd: 'docker',
args: [
'compose',
'-p',
makeComposeProject(name),
'-f',
Expand Down
5 changes: 3 additions & 2 deletions packages/cluster/src/commands/restart.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ const run = async function (argv) {
}
reporter.info(`Spinning up cluster version ${chalk.cyan(name)}`)
const res = await tryCatchAsync(
'exec(docker-compose)',
'exec(docker compose)',
exec({
cmd: 'docker-compose',
cmd: 'docker',
args: [
'compose',
'-p',
makeComposeProject(name),
'-f',
Expand Down
12 changes: 7 additions & 5 deletions packages/cluster/src/commands/up.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ const run = async function (argv) {
if (update) {
reporter.info('Pulling latest Docker images...')
const res = await tryCatchAsync(
'exec(docker-compose)::pull',
'exec(docker compose)::pull',
exec({
env: makeEnvironment(cfg),
cmd: 'docker-compose',
cmd: 'docker',
args: [
'compose',
'-p',
makeComposeProject(name),
'-f',
Expand Down Expand Up @@ -70,11 +71,12 @@ const run = async function (argv) {
reporter.info(`Spinning up cluster ${chalk.cyan(name)}`)

const res = await tryCatchAsync(
'exec(docker-compose)',
'exec(docker compose)',
exec({
env: makeEnvironment(cfg),
cmd: 'docker-compose',
cmd: 'docker',
args: [
'compose',
'-p',
makeComposeProject(name),
'-f',
Expand All @@ -86,7 +88,7 @@ const run = async function (argv) {
})
)
if (res.err) {
reporter.error('Failed to spin up cluster docker-compose cluster')
reporter.error('Failed to spin up cluster docker compose cluster')
process.exit(1)
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cluster/src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ module.exports.makeEnvironment = cfg => {
return env
}

// This has to match the normalization done by docker-compose to reliably get container statuses
// This has to match the normalization done by docker compose to reliably get container statuses
// from https://github.com/docker/compose/blob/c8279bc4db56f49cf2e2b80c8734ced1c418b856/compose/cli/command.py#L154
const normalizeName = name => name.replace(/[^-_a-z0-9]/g, '')

Expand Down
2 changes: 1 addition & 1 deletion packages/cluster/src/helpers/db/backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = async ({ cacheLocation, name, path: dbPath, fat }) => {
args: [destinationFile, fat ? 'full' : ''],
pipe: false,
env: {
DOCKER_COMPOSE: `docker-compose -p ${composeProject}`,
DOCKER_COMPOSE: `docker compose -p ${composeProject}`,
},
})
}
2 changes: 1 addition & 1 deletion packages/cluster/src/helpers/db/restore.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const restoreFromFile = async ({ cacheLocation, dbFile, name }) => {
args: [dbFile],
pipe: false,
env: {
DOCKER_COMPOSE: `docker-compose -p ${makeComposeProject(name)}`,
DOCKER_COMPOSE: `docker compose -p ${makeComposeProject(name)}`,
},
})
}
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/commands/debug/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const run = async () => {
const info = await envInfo.run(
{
System: ['OS', 'CPU', 'Memory', 'Shell'],
Binaries: ['Node', 'Yarn', 'npm', 'docker-compose', 'docker'],
Binaries: ['Node', 'Yarn', 'npm', 'docker'],
Utilities: ['Git'],
Virtualization: ['Docker', 'Docker Compose'],
IDEs: ['VSCode', 'Sublime Text'],
Expand Down
Loading