-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.gradle
135 lines (122 loc) · 3.57 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
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
group 'com.test'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
buildscript {
repositories {
jcenter()
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath "com.avast.gradle:gradle-docker-compose-plugin:0.8.4"
classpath 'com.bmuschko:gradle-docker-plugin:3.5.0'
}
}
//
//apply plugin: 'docker-compose'
//apply plugin: 'com.bmuschko.docker-remote-api'
//import com.bmuschko.gradle.docker.tasks.container.*
//import com.bmuschko.gradle.docker.tasks.image.*
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
//
//// STEP 1 : bring up the docker compose only for the applications under test EXCLUDING cypress
//
//dockerCompose {
// useComposeFiles = ['docker-compose.yml']
// forceRecreate = true
// upAdditionalArgs = ['--exit-code-from', 'cypress']
// waitForTcpPorts = true
// captureContainersOutput = true
//}
//
//// STEP 2 : bring up cypress and connect it to the above network from STEP1
//
//task buildCypress (type: DockerBuildImage){
// dependsOn composeUp
// inputDir = project.file('cypress')
//}
//
//task createCypressContainer(type: DockerCreateContainer) {
// dependsOn buildCypress
// targetImageId { buildCypress.getImageId() }
//}
//
//task startCypressContainer(type: DockerStartContainer) {
// dependsOn createCypressContainer
// targetContainerId { createCypressContainer.getContainerId() }
//}
//
//task isContainerRunning (type: DockerLogsContainer) {
// follow = true
// tailAll = true
// onNext { message ->
// def foundMessage = message.toString()
// if (foundMessage.matches('Some string that says we are live')) {
// throw new RuntimeException('SHORT-CIRCUIT-POLLING')
// }
// }
// onError { exception ->
// // Ignore exception if container does not exist otherwise throw it
// if (!exception.message.contains('No such container'))
// throw exception
// }
// targetContainerId { createCypressContainer.getContainerId() }
//}
//
//task runCypressCommand(type : DockerExecContainer) {
// dependsOn startCypressContainer
// commands ["./node_modules/.bin/cypress run"]
// attachStdout = true
// attachStderr = true
// targetContainerId { createCypressContainer.getContainerId() }
// finalizedBy isContainerRunning
//}
//
//task stopCypressContainer(type: DockerStopContainer) {
// onError { exception ->
// if (exception.message != null && exception.message.contains('No such container')) {
// println 'Container not running'
// } else {
// throw exception
// }
// }
// targetContainerId { createCypressContainer.getContainerId() }
//}
//
//task functionalTestMyApp(type: DefaultTask) {
// dependsOn runCypressCommand
// finalizedBy stopCypressContainer
//}
//
//
//// More general way without plugins
task dockerComposeBuild(type: DockerComposeTask) {
command = "build"
}
task dockerComposeUp(type: DockerComposeTask, dependsOn: [dockerComposeBuild]) {
command = 'up --exit-code-from cypress'
}
task dockerComposeDown(type: DockerComposeTask) {
command = 'down'
}
task runTest{
dependsOn dockerComposeUp
finalizedBy dockerComposeDown
}
class DockerComposeTask extends DefaultTask {
def command
@TaskAction
def dockerCompose() {
project.exec({
executable = "docker-compose"
this.command.split().each { args it }
if (this.command == 'build') {
args "--force-rm"
}
})
}
}