Skip to content

Commit 1e93c14

Browse files
committed
Run MongoDB Docker container as part of Gradle build.
1 parent 6daa18b commit 1e93c14

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

build.gradle

+23
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import com.bmuschko.gradle.docker.tasks.container.*
2+
13
plugins {
24
id "java"
35
id "scala"
46
id "application"
57
id "cz.alenkacz.gradle.scalafmt" version "1.16.2"
8+
id 'com.bmuschko.docker-remote-api' version '9.0.1'
69
}
710

811
version = '1.0.2'
@@ -24,3 +27,23 @@ dependencies {
2427
}
2528

2629
compileScala.dependsOn("checkScalafmt")
30+
31+
task createMongoContainer(type: DockerCreateContainer) {
32+
targetImageId 'mongo:3.2'
33+
containerName = 'mongo'
34+
hostConfig.portBindings = ['27017:27017']
35+
hostConfig.autoRemove = true
36+
}
37+
38+
task startMongoContainer(type: DockerStartContainer) {
39+
dependsOn createMongoContainer
40+
targetContainerId createMongoContainer.containerId
41+
}
42+
43+
task stopMongoContainer(type: DockerStopContainer) {
44+
targetContainerId createMongoContainer.containerId
45+
}
46+
47+
run.dependsOn(startMongoContainer)
48+
49+
run.finalizedBy(stopMongoContainer)

0 commit comments

Comments
 (0)