Skip to content

Commit

Permalink
fix: resolve dockerComposeRepository from defaults if cluster undefin…
Browse files Browse the repository at this point in the history
…ed (#55)
  • Loading branch information
varl authored and amcgee committed May 27, 2019
1 parent 115985b commit 39fc0c7
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 35 deletions.
13 changes: 8 additions & 5 deletions packages/cluster/src/commands/down.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
const chalk = require('chalk')
const path = require('path')
const { exec, reporter } = require('@dhis2/cli-helpers-engine')
const { initDockerComposeCache, makeComposeProject } = require('../common')
const {
initDockerComposeCache,
makeComposeProject,
resolveConfiguration,
} = require('../common')

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

const run = async function({ name, clean, getCache, ...argv }) {
const run = async function({ name, clean, getCache, cluster, ...argv }) {
const { dockerComposeRepository } = resolveConfiguration(argv, {}, cluster)
const cacheLocation = await initDockerComposeCache({
cache: getCache(),
dockerComposeRepository:
argv.cluster.dockerComposeRepository ||
defaults.dockerComposeRepository,
dockerComposeRepository,
force: false,
})

Expand Down
13 changes: 8 additions & 5 deletions packages/cluster/src/commands/logs.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
const chalk = require('chalk')
const path = require('path')
const { reporter, exec, tryCatchAsync } = require('@dhis2/cli-helpers-engine')
const { initDockerComposeCache, makeComposeProject } = require('../common')
const {
initDockerComposeCache,
makeComposeProject,
resolveConfiguration,
} = require('../common')
const defaults = require('../defaults')

const run = async function({ service, name, ...argv }) {
const run = async function({ service, name, cluster, ...argv }) {
const { dockerComposeRepository } = resolveConfiguration(argv, {}, cluster)
const cacheLocation = await initDockerComposeCache({
cache: argv.getCache(),
dockerComposeRepository:
argv.cluster.dockerComposeRepository ||
defaults.dockerComposeRepository,
dockerComposeRepository,
force: false,
})
if (!cacheLocation) {
Expand Down
13 changes: 8 additions & 5 deletions packages/cluster/src/commands/restart.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
const chalk = require('chalk')
const path = require('path')
const { reporter, exec, tryCatchAsync } = require('@dhis2/cli-helpers-engine')
const { initDockerComposeCache, makeComposeProject } = require('../common')
const {
initDockerComposeCache,
makeComposeProject,
resolveConfiguration,
} = require('../common')

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

const run = async function({ service, name, port, ...argv }) {
const run = async function({ service, name, port, cluster, ...argv }) {
const { dockerComposeRepository } = resolveConfiguration(argv, {}, cluster)
const cacheLocation = await initDockerComposeCache({
cache: argv.getCache(),
dockerComposeRepository:
argv.cluster.dockerComposeRepository ||
defaults.dockerComposeRepository,
dockerComposeRepository,
force: false,
})
if (!cacheLocation) {
Expand Down
14 changes: 8 additions & 6 deletions packages/cluster/src/commands/seed.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
const { reporter } = require('@dhis2/cli-helpers-engine')
const { initDockerComposeCache } = require('../common')
const { initDockerComposeCache, resolveConfiguration } = require('../common')
const { seed } = require('../db')

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

const run = async function({ dhis2Version, ...argv }) {
const { cluster } = argv
const { dockerComposeRepository, dbVersion } = resolveConfiguration(
argv,
{},
cluster
)

const cacheLocation = await initDockerComposeCache({
cache: argv.getCache(),
dockerComposeRepository:
cluster.dockerComposeRepository || defaults.dockerComposeRepository,
dockerComposeRepository,
force: false,
})

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

const resolvedVersion = dhis2Version || name

return await seed({
cacheLocation,
dbVersion: resolvedVersion,
dbVersion,
...argv,
})
}
Expand Down
11 changes: 5 additions & 6 deletions packages/cluster/src/commands/up.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@ const {
initDockerComposeCache,
makeComposeProject,
makeEnvironment,
resolveConfiguration,
} = require('../common')

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

const run = async function(argv) {
const { cluster, name, seed, seedFile, update } = argv

const runtime = makeEnvironment(argv, {}, cluster)
const cfg = resolveConfiguration(argv, {}, cluster)

const cacheLocation = await initDockerComposeCache({
cache: argv.getCache(),
dockerComposeRepository:
cluster.dockerComposeRepository || defaults.dockerComposeRepository,
dockerComposeRepository: cfg.dockerComposeRepository,
force: update,
})

Expand All @@ -30,7 +29,7 @@ const run = async function(argv) {
if (seed || seedFile) {
await doSeed({
cacheLocation,
dbVersion: runtime.DHIS2_CORE_DB_VERSION,
dbVersion: cfg.dbVersion,
name,
path: seedFile,
update,
Expand All @@ -43,7 +42,7 @@ const run = async function(argv) {
const res = await tryCatchAsync(
'exec(docker-compose)',
exec({
env: runtime,
env: makeEnvironment(cfg),
cmd: 'docker-compose',
args: [
'-p',
Expand Down
4 changes: 1 addition & 3 deletions packages/cluster/src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ function resolveConfiguration(argv = {}, cache = {}, config = {}) {
return resolved
}

module.exports.makeEnvironment = (argv = {}, cache = {}, config = {}) => {
const cfg = resolveConfiguration(argv, cache, config)

module.exports.makeEnvironment = cfg => {
const env = {
DHIS2_CORE_NAME: cfg.name,
DHIS2_CORE_IMAGE: cfg.dockerImage,
Expand Down
10 changes: 5 additions & 5 deletions packages/cluster/tests/setup-environment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const test = require('tape')

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

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

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

const actual = makeEnvironment(argv, cache, config)
const actual = makeEnvironment(resolveConfiguration(argv, cache, config))

const expected = {
DHIS2_CORE_NAME: 'dev',
Expand Down Expand Up @@ -42,7 +42,7 @@ test('build runtime environment based on args', function(t) {
const cache = {}
const config = {}

const actual = makeEnvironment(argv, cache, config)
const actual = makeEnvironment(resolveConfiguration(argv, cache, config))

const expected = {
DHIS2_CORE_NAME: 'dev',
Expand Down Expand Up @@ -73,7 +73,7 @@ test('build runtime environment based on mixed args and config', function(t) {
dbVersion: 'dev',
}

const actual = makeEnvironment(argv, cache, config)
const actual = makeEnvironment(resolveConfiguration(argv, cache, config))

const expected = {
DHIS2_CORE_NAME: 'mydev',
Expand Down Expand Up @@ -104,7 +104,7 @@ test('build runtime environment based on mixed args, cache, config and defaults'
dhis2Version: 'dev',
}

const actual = makeEnvironment(argv, cache, config)
const actual = makeEnvironment(resolveConfiguration(argv, cache, config))

const expected = {
DHIS2_CORE_NAME: 'mydev',
Expand Down

0 comments on commit 39fc0c7

Please sign in to comment.