Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
169 lines (139 sloc) 4.97 KB
buildscript {
ext {
springBootVersion = '2.0.4.RELEASE'
}
repositories {
jcenter()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("gradle.plugin.org.unbroken-dome.gradle-plugins:gradle-testsets-plugin:1.5.1")
}
}
plugins {
id 'pl.allegro.tech.build.axion-release' version '1.9.3'
id "com.bmuschko.docker-remote-api" version "3.6.1"
}
project.version = scmVersion.version
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'eclipse'
apply plugin: 'org.unbroken-dome.test-sets'
apply plugin: "com.bmuschko.docker-remote-api"
group = 'ch.so.agi.ilivalidator'
description = """ilivalidator web service"""
bootJar {
launchScript()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
testSets {
dockerTest
}
sourceSets {
dockerTestRuntime {
runtimeClasspath += sourceSets.test.runtimeClasspath
}
}
repositories {
jcenter()
maven { url "http://jars.interlis.ch/" }
maven { url "http://repo.maven.apache.org/maven2" }
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
compile("org.springframework.boot:spring-boot-starter-thymeleaf:${springBootVersion}")
compile("org.springframework.boot:spring-boot-devtools:${springBootVersion}")
compile("commons-io:commons-io:2.5")
compile("ch.interlis:ilivalidator:1.8.1")
compile("org.webjars:materializecss:0.100.1")
compile("org.webjars:jquery:2.2.4")
testCompile("io.rest-assured:rest-assured:3.0.6")
testCompile("org.springframework.boot:spring-boot-starter-test:${springBootVersion}") {
exclude(module: 'commons-logging')
}
dockerTestCompile("io.rest-assured:rest-assured:3.0.6")
dockerTestCompile sourceSets.test.output
}
test {
testLogging {
showStandardStreams = true
}
}
import com.bmuschko.gradle.docker.tasks.image.Dockerfile
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import com.bmuschko.gradle.docker.tasks.image.DockerPushImage
import com.bmuschko.gradle.docker.tasks.container.DockerCreateContainer
import com.bmuschko.gradle.docker.tasks.container.DockerStartContainer
import com.bmuschko.gradle.docker.tasks.container.DockerLogsContainer
import com.bmuschko.gradle.docker.tasks.container.DockerStopContainer
import com.bmuschko.gradle.docker.tasks.container.DockerCreateContainer.ExposedPort
docker {
registryCredentials {
username = System.env.dockerRegistryUser
password = System.env.dockerRegistryPass
}
}
task buildDockerImage(type: DockerBuildImage) {
description = "Build docker image."
inputDir = project.rootDir
//tag = "sogis/ilivalidator-web-service:${version}"
tags = ["sogis/ilivalidator-web-service:"+version, "sogis/ilivalidator-web-service:latest"]
}
task createDockerContainer(dependsOn: 'buildDockerImage', type: DockerCreateContainer) {
description = "Create docker container."
targetImageId { buildDockerImage.getImageId() }
portBindings = ['8888:8888']
exposedPorts = [new ExposedPort("tcp", [8888])]
}
task startDockerContainer(dependsOn: 'createDockerContainer', type: DockerStartContainer) {
description = "Start docker container."
targetContainerId { createDockerContainer.getContainerId() }
// Starting container != web service is ready.
doLast {
sleep(10*1000)
}
}
task logDockerContainer(type: DockerLogsContainer) {
description = "Show docker container logs on standard out."
targetContainerId { startDockerContainer.getContainerId() }
follow = true
tailAll = true
}
task stopDockerContainer(type: DockerStopContainer) {
description = "Stop running docker container."
targetContainerId { createDockerContainer.getContainerId() }
}
task pushDockerImage_One(type: DockerPushImage) {
description = "Push docker image to hub.docker.com (only if docker tests were successful)."
onlyIf {
dockerTest.state.failure == null
}
imageName = buildDockerImage.tags[0]
}
task pushDockerImage_Two(type: DockerPushImage) {
description = "Push docker image to hub.docker.com (only if docker tests were successful)."
onlyIf {
dockerTest.state.failure == null
}
imageName = buildDockerImage.tags[1]
}
task pushDockerImages() {
doFirst{
println "Push Docker Images"
}
}
pushDockerImages.dependsOn {
tasks.findAll { task -> task.name.startsWith('pushDockerImage_') }
}
// TODO: How to show docker log. Seems to stall b/c of finalizedBy?
// At least standard out is in gradle docker test reports.
//startDockerContainer.finalizedBy('logDockerContainer')
dockerTest.dependsOn('startDockerContainer')
dockerTest.finalizedBy('stopDockerContainer')//, 'pushDockerImage_One', 'pushDockerImage_Two')