-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
73 lines (59 loc) · 2.19 KB
/
index.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
68
69
70
71
72
73
const shell = require('shelljs');
module.exports = (api, options) => {
api.registerCommand(
'docker:build',
{
description: 'Build a new docker container',
usage: 'vue-cli-service docker:build [options]',
options: {
'--tag': "Name and optionally a tag in the 'name:tag' format"
}
},
answers => {
console.log(`🐳 Building a new docker container`)
const args = []
if (answers.tag) args.push(`--tag ${answers.tag}`)
const params = args.join(' ')
if (!shell.which('docker')) {
shell.echo(`Sorry, this script requires 'docker' cli.`);
shell.exit(1);
return
}
if (shell.exec(`docker build . ${params}`).code !== 0) {
shell.echo('Error: Docker build failed');
shell.exit(1);
}
}
)
api.registerCommand(
'docker:run',
{
description: 'Run application in docker',
usage: 'vue-cli-service docker:run [options]',
options: {
'-i': 'Keep STDIN open even if not attached',
'-t': 'Allocate a pseudo-TTY',
'--rm': 'Automatically remove the container when it exits',
'--publish [host:container]': "Publish a container's port(s) to the host"
}
},
answers => {
console.log(`🐳 Running application in docker container`)
const args = []
if (answers.publish) args.push(`--publish ${answers.publish}`)
if (answers.interactive) args.push(`--interactive`)
if (answers.tty) args.push(`--tty`)
if (answers.rm) args.push(`--rm`)
const params = args.join(' ')
if (!shell.which('docker')) {
shell.echo(`Sorry, this script requires 'docker' cli.`);
shell.exit(1);
return
}
if (shell.exec(`docker run ${params}`).code !== 0) {
shell.echo('Error: Docker build failed');
shell.exit(1);
}
}
)
};