-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
67 lines (61 loc) · 1.72 KB
/
app.js
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
const yargs = require('yargs')
const log = require('./lib/logger/logger')('Main')
const stacks = require('./lib/stacks/stacks.utils')
const argv = yargs
.command('backup', 'Back up stacks from portainer')
.command('update', 'Update the backed up stacks')
.command('create', 'Remove then create the backed up stacks')
.options({
'u': {
demand: false,
alias: 'url',
describe: 'Portainer\'s URL',
string: true
},
'l': {
demand: false,
alias: 'login',
describe: 'User\'s login to use',
string: true
},
'p': {
demand: false,
alias: 'password',
describe: 'User\'s password',
string: true
}
})
.implies('url', 'login')
.implies('login', 'password')
.implies('login', 'url')
.implies('password', 'login')
.implies('password', 'url')
.help()
.alias('help', 'h')
.locale('en')
.argv
async function main () {
log.debug('Starting app')
// Log in and get JWT token from portainer
let jwt = await stacks.login(argv.url, argv.login, argv.password)
if (argv._[0] === 'backup') {
// Get all stacks from portainer and save them to a json file
await stacks.backupStacks(jwt, argv.url)
} else if (argv._[0] === 'update') {
// Read the backup file then update all the stacks
await stacks.updateStacks(jwt, argv.url)
} else if (argv._[0] === 'create') {
// Read the backup file then re-create all the stacks
await stacks.removeAndCreateStacks(jwt, argv.url)
} else {
log.warn(`Unknown command`)
}
}
main()
.catch((err) => {
if (err.response && err.response.data) {
log.error({err: err}, `Http error: ${err.response.data.err}`)
} else {
log.error({err: err}, `Application error.`)
}
})