Skip to content

Commit 39fc0c7

Browse files
varlamcgee
authored andcommitted
fix: resolve dockerComposeRepository from defaults if cluster undefined (#55)
1 parent 115985b commit 39fc0c7

7 files changed

Lines changed: 43 additions & 35 deletions

File tree

packages/cluster/src/commands/down.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
const chalk = require('chalk')
22
const path = require('path')
33
const { exec, reporter } = require('@dhis2/cli-helpers-engine')
4-
const { initDockerComposeCache, makeComposeProject } = require('../common')
4+
const {
5+
initDockerComposeCache,
6+
makeComposeProject,
7+
resolveConfiguration,
8+
} = require('../common')
59

610
const defaults = require('../defaults')
711

8-
const run = async function({ name, clean, getCache, ...argv }) {
12+
const run = async function({ name, clean, getCache, cluster, ...argv }) {
13+
const { dockerComposeRepository } = resolveConfiguration(argv, {}, cluster)
914
const cacheLocation = await initDockerComposeCache({
1015
cache: getCache(),
11-
dockerComposeRepository:
12-
argv.cluster.dockerComposeRepository ||
13-
defaults.dockerComposeRepository,
16+
dockerComposeRepository,
1417
force: false,
1518
})
1619

packages/cluster/src/commands/logs.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
const chalk = require('chalk')
22
const path = require('path')
33
const { reporter, exec, tryCatchAsync } = require('@dhis2/cli-helpers-engine')
4-
const { initDockerComposeCache, makeComposeProject } = require('../common')
4+
const {
5+
initDockerComposeCache,
6+
makeComposeProject,
7+
resolveConfiguration,
8+
} = require('../common')
59
const defaults = require('../defaults')
610

7-
const run = async function({ service, name, ...argv }) {
11+
const run = async function({ service, name, cluster, ...argv }) {
12+
const { dockerComposeRepository } = resolveConfiguration(argv, {}, cluster)
813
const cacheLocation = await initDockerComposeCache({
914
cache: argv.getCache(),
10-
dockerComposeRepository:
11-
argv.cluster.dockerComposeRepository ||
12-
defaults.dockerComposeRepository,
15+
dockerComposeRepository,
1316
force: false,
1417
})
1518
if (!cacheLocation) {

packages/cluster/src/commands/restart.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
const chalk = require('chalk')
22
const path = require('path')
33
const { reporter, exec, tryCatchAsync } = require('@dhis2/cli-helpers-engine')
4-
const { initDockerComposeCache, makeComposeProject } = require('../common')
4+
const {
5+
initDockerComposeCache,
6+
makeComposeProject,
7+
resolveConfiguration,
8+
} = require('../common')
59

610
const defaults = require('../defaults')
711

8-
const run = async function({ service, name, port, ...argv }) {
12+
const run = async function({ service, name, port, cluster, ...argv }) {
13+
const { dockerComposeRepository } = resolveConfiguration(argv, {}, cluster)
914
const cacheLocation = await initDockerComposeCache({
1015
cache: argv.getCache(),
11-
dockerComposeRepository:
12-
argv.cluster.dockerComposeRepository ||
13-
defaults.dockerComposeRepository,
16+
dockerComposeRepository,
1417
force: false,
1518
})
1619
if (!cacheLocation) {

packages/cluster/src/commands/seed.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
const { reporter } = require('@dhis2/cli-helpers-engine')
2-
const { initDockerComposeCache } = require('../common')
2+
const { initDockerComposeCache, resolveConfiguration } = require('../common')
33
const { seed } = require('../db')
44

55
const defaults = require('../defaults')
66

77
const run = async function({ dhis2Version, ...argv }) {
88
const { cluster } = argv
9+
const { dockerComposeRepository, dbVersion } = resolveConfiguration(
10+
argv,
11+
{},
12+
cluster
13+
)
914

1015
const cacheLocation = await initDockerComposeCache({
1116
cache: argv.getCache(),
12-
dockerComposeRepository:
13-
cluster.dockerComposeRepository || defaults.dockerComposeRepository,
17+
dockerComposeRepository,
1418
force: false,
1519
})
1620

@@ -19,11 +23,9 @@ const run = async function({ dhis2Version, ...argv }) {
1923
process.exit(1)
2024
}
2125

22-
const resolvedVersion = dhis2Version || name
23-
2426
return await seed({
2527
cacheLocation,
26-
dbVersion: resolvedVersion,
28+
dbVersion,
2729
...argv,
2830
})
2931
}

packages/cluster/src/commands/up.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@ const {
55
initDockerComposeCache,
66
makeComposeProject,
77
makeEnvironment,
8+
resolveConfiguration,
89
} = require('../common')
910

1011
const defaults = require('../defaults')
1112
const { seed: doSeed } = require('../db')
1213

1314
const run = async function(argv) {
1415
const { cluster, name, seed, seedFile, update } = argv
15-
16-
const runtime = makeEnvironment(argv, {}, cluster)
16+
const cfg = resolveConfiguration(argv, {}, cluster)
1717

1818
const cacheLocation = await initDockerComposeCache({
1919
cache: argv.getCache(),
20-
dockerComposeRepository:
21-
cluster.dockerComposeRepository || defaults.dockerComposeRepository,
20+
dockerComposeRepository: cfg.dockerComposeRepository,
2221
force: update,
2322
})
2423

@@ -30,7 +29,7 @@ const run = async function(argv) {
3029
if (seed || seedFile) {
3130
await doSeed({
3231
cacheLocation,
33-
dbVersion: runtime.DHIS2_CORE_DB_VERSION,
32+
dbVersion: cfg.dbVersion,
3433
name,
3534
path: seedFile,
3635
update,
@@ -43,7 +42,7 @@ const run = async function(argv) {
4342
const res = await tryCatchAsync(
4443
'exec(docker-compose)',
4544
exec({
46-
env: runtime,
45+
env: makeEnvironment(cfg),
4746
cmd: 'docker-compose',
4847
args: [
4948
'-p',

packages/cluster/src/common.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ function resolveConfiguration(argv = {}, cache = {}, config = {}) {
9191
return resolved
9292
}
9393

94-
module.exports.makeEnvironment = (argv = {}, cache = {}, config = {}) => {
95-
const cfg = resolveConfiguration(argv, cache, config)
96-
94+
module.exports.makeEnvironment = cfg => {
9795
const env = {
9896
DHIS2_CORE_NAME: cfg.name,
9997
DHIS2_CORE_IMAGE: cfg.dockerImage,

packages/cluster/tests/setup-environment.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const test = require('tape')
22

3-
const { makeEnvironment } = require('../src/common.js')
3+
const { makeEnvironment, resolveConfiguration } = require('../src/common.js')
44

55
const defaults = require('../src/defaults.js')
66

@@ -13,7 +13,7 @@ test('build runtime environment based on defaults', function(t) {
1313
const cache = {}
1414
const config = {}
1515

16-
const actual = makeEnvironment(argv, cache, config)
16+
const actual = makeEnvironment(resolveConfiguration(argv, cache, config))
1717

1818
const expected = {
1919
DHIS2_CORE_NAME: 'dev',
@@ -42,7 +42,7 @@ test('build runtime environment based on args', function(t) {
4242
const cache = {}
4343
const config = {}
4444

45-
const actual = makeEnvironment(argv, cache, config)
45+
const actual = makeEnvironment(resolveConfiguration(argv, cache, config))
4646

4747
const expected = {
4848
DHIS2_CORE_NAME: 'dev',
@@ -73,7 +73,7 @@ test('build runtime environment based on mixed args and config', function(t) {
7373
dbVersion: 'dev',
7474
}
7575

76-
const actual = makeEnvironment(argv, cache, config)
76+
const actual = makeEnvironment(resolveConfiguration(argv, cache, config))
7777

7878
const expected = {
7979
DHIS2_CORE_NAME: 'mydev',
@@ -104,7 +104,7 @@ test('build runtime environment based on mixed args, cache, config and defaults'
104104
dhis2Version: 'dev',
105105
}
106106

107-
const actual = makeEnvironment(argv, cache, config)
107+
const actual = makeEnvironment(resolveConfiguration(argv, cache, config))
108108

109109
const expected = {
110110
DHIS2_CORE_NAME: 'mydev',

0 commit comments

Comments
 (0)