-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathup.js
More file actions
150 lines (141 loc) · 4.05 KB
/
up.js
File metadata and controls
150 lines (141 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
const path = require('path')
const {
reporter,
exec,
tryCatchAsync,
chalk,
} = require('@dhis2/cli-helpers-engine')
const {
initDockerComposeCache,
makeEnvironment,
makeComposeProject,
resolveConfiguration,
} = require('../common')
const defaults = require('../defaults')
const { restore } = require('../helpers/db')
const run = async function (argv) {
const { name, seed, seedFile, update, getCache } = argv
const cfg = await resolveConfiguration(argv)
const cacheLocation = await initDockerComposeCache({
composeProjectName: name,
cache: getCache(),
dockerComposeRepository: cfg.dockerComposeRepository,
dockerComposeDirectory: cfg.dockerComposeDirectory,
force: update,
})
if (!cacheLocation) {
reporter.error('Failed to initialize cache...')
process.exit(1)
}
if (update) {
reporter.info('Pulling latest Docker images...')
const res = await tryCatchAsync(
'exec(docker-compose)::pull',
exec({
env: makeEnvironment(cfg),
cmd: 'docker-compose',
args: [
'-p',
makeComposeProject(name),
'-f',
path.join(cacheLocation, 'docker-compose.yml'),
'pull',
],
pipe: false,
})
)
if (res.err) {
reporter.error('Failed to pull latest Docker images')
process.exit(1)
}
}
if (seed || seedFile) {
await restore({
name,
cacheLocation,
dbVersion: cfg.dbVersion,
url: cfg.demoDatabaseURL,
path: seedFile,
update,
...argv,
})
}
reporter.info(`Spinning up cluster ${chalk.cyan(name)}`)
const res = await tryCatchAsync(
'exec(docker-compose)',
exec({
env: makeEnvironment(cfg),
cmd: 'docker-compose',
args: [
'-p',
makeComposeProject(name),
'-f',
path.join(cacheLocation, 'docker-compose.yml'),
'up',
'-d',
],
pipe: true,
})
)
if (res.err) {
reporter.error('Failed to spin up cluster docker-compose cluster')
process.exit(1)
}
}
module.exports = {
command: 'up <name>',
desc: 'Spin up a new cluster',
aliases: 'u',
builder: {
port: {
alias: 'p',
desc: `Specify the port on which to expose the DHIS2 instance (default: ${defaults.port})`,
type: 'integer',
},
seed: {
alias: 's',
desc: 'Seed the database from a sql dump',
type: 'boolean',
},
seedFile: {
desc: 'The location of the sql dump to use when seeding that database',
type: 'string',
},
update: {
alias: 'u',
desc: 'Indicate that d2 cluster should re-download cached files',
type: 'boolean',
},
image: {
alias: 'i',
desc: 'Specify the Docker image to use',
type: 'string',
},
dhis2Version: {
desc: 'Set the DHIS2 version',
type: 'string',
},
dhis2Config: {
desc: 'Path to a custom DHIS2 configuration file to use (dhis.conf)',
type: 'string',
},
dbVersion: {
desc: 'Set the database version',
type: 'string',
},
channel: {
desc: `Set the release channel to use (default: ${defaults.channel})`,
type: 'string',
},
customContext: {
alias: 'c',
desc: 'Serve on a custom context path. If used as a flag, the name of the cluster will be used.',
type: 'string',
},
variant: {
desc: 'Append variant options to the image',
type: 'string',
},
},
handler: run,
}