-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle
86 lines (77 loc) · 1.81 KB
/
build.gradle
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
defaultTasks 'build-dev'
ext {
CONTAINER_NAME = "docker-dns-server"
TAG = getTheTag()
IMAGE_NAME = "${CONTAINER_NAME}:$TAG"
WORKDIR = "/opt/${CONTAINER_NAME}"
}
/**
* roda o sistema em modo dev
* este método já chama o build e up necessário
*/
task 'build-dev' (dependsOn: [
'docker-server-dev-build', 'docker-server-dev-up'
]) << {
}
/**
* roda o sistema em modo test (com a base de dados do src)
* este método já chama o build e up necessário
*/
task 'build-test' (dependsOn: [
]) << {
}
/**
* roda o servidor em modo dev
* este método já chama o build e up necessário
*/
task 'docker-server-dev-build' (type:Exec) {
commandLine = ['docker', 'build', '--rm', '--tag',
IMAGE_NAME, '.'
]
}
/**
* roda o sistema de mock
*/
task 'docker-server-dev-up' (type:Exec) {
def pwd = new File(".").absolutePath
removeContainer(CONTAINER_NAME)
commandLine = [
'docker', 'run', '-d', '--hostname', CONTAINER_NAME,
'--expose', "53",
'--workdir', "${WORKDIR}",
'--volume',
"${pwd}/:${WORKDIR}",
'--name', CONTAINER_NAME, IMAGE_NAME,
'node', 'app.js'
]
}
/**
* apaga todas as imagens e containers
* gerados por este projeto
*/
task 'docker-clear' << {
removeImage(CONTAINER_NAME)
}
def removeLast(String str) {
str.substring(0, str.length()-1);
}
def getTheTag(){
def tag = ['git', 'describe', '--abbrev=0', '--tags'].execute().text;
if(tag.length() == 1)
return removeLast(tag)
return '1.0.0'
}
def removeContainer(String image){
def buff = new StringBuffer();
def proc = ['docker', 'rm', '-f', image].execute();
proc.consumeProcessOutput(buff, buff)
proc.waitForOrKill(10000);
//println buff
}
def removeImage(String image){
def buff = new StringBuffer();
def proc = ['docker', 'rmi', '-f', image].execute();
proc.consumeProcessOutput(buff, buff)
proc.waitForOrKill(10000);
//println buff
}