1+ import com.bmuschko.gradle.docker.tasks.DockerInfo
2+ import com.bmuschko.gradle.docker.tasks.DockerVersion
3+ import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
4+ import com.bmuschko.gradle.docker.tasks.image.Dockerfile
5+
16buildscript {
27 ext {
3- springBootVersion = ' 2.0.1.RELEASE'
4- springIntegrationVersion = ' 5.0.4.RELEASE'
5- junitVersion = ' 5.0.2'
8+ springBootVersion = ' 2.1.0.M1'
9+ junitVersion = ' 5.1.0'
610 }
711 repositories {
812 mavenCentral()
@@ -11,6 +15,7 @@ buildscript {
1115 dependencies {
1216 classpath group : ' org.springframework.boot' , name : ' spring-boot-gradle-plugin' , version : " ${ springBootVersion} "
1317 classpath ' org.junit.platform:junit-platform-gradle-plugin:1.0.1'
18+ classpath group : ' com.bmuschko' , name : ' gradle-docker-plugin' , version : ' 3.5.0'
1419 }
1520}
1621
@@ -19,9 +24,13 @@ apply plugin: 'org.springframework.boot'
1924apply plugin : ' io.spring.dependency-management'
2025apply plugin : ' org.junit.platform.gradle.plugin'
2126apply plugin : ' application'
27+ apply plugin : ' com.bmuschko.docker-remote-api'
28+
29+ version = ' 0.10.1'
30+ sourceCompatibility = 1.9
31+ targetCompatibility = 1.9
2232
23- jar {
24- version = ' 0.10'
33+ bootJar {
2534 archiveName = ' analog.jar'
2635 manifest {
2736 attributes(
3140 )
3241 }
3342}
34- sourceCompatibility = 1.9
35- targetCompatibility = 1.9
43+
44+ // <editor-fold desc="Задачи по работе с Docker-образами">
45+ docker {
46+ url = project[' docker.url' ]
47+ registryCredentials {
48+ url = project[' docker.registry.url' ]
49+ username = project[' docker.registry.username' ]
50+ password = project[' docker.registry.password' ]
51+ email = project[' docker.registry.email' ]
52+ }
53+ }
54+ task createDockerfile (type : Dockerfile ) {
55+ description ' Генерирует Dockerfile для сборки образа микросервиса'
56+ group ' docker'
57+
58+ from ' openjdk:10-jdk-slim'
59+ // все дальнейшие команды будут разрешать пути внутри контейнера относительно этой:
60+ workingDir " /analog"
61+ // копируем исполняемый файл микросервиса:
62+ copyFile bootJar. archiveName, bootJar. archiveName
63+ // копируем файлы конфигурации:
64+ copyFile ' config/' , ' config/'
65+ // монтируем директории для сохранения данных мониторинга и Tomcat'а между перезапусками:
66+ // volume "/microservice/work", "/microservice/log"
67+ environmentVariable ' APP_NAME' , project. name
68+ // формируем команду на запуск:
69+ entryPoint ' java'
70+ // вся команда на запуск будет выглядеть 'java -X... -jar restorun.jar'
71+ defaultCommand ' -Xmx256M' , ' -XX:MaxMetaspaceSize=256M' , ' -XX:+HeapDumpOnOutOfMemoryError' ,
72+ ' -jar' , " ${ bootJar.archiveName} "
73+ }
74+
75+ task syncImageFiles (type : Sync ) {
76+ description ' Копирует в директорию build/docker файлы микросервиса для сборки образа'
77+ group ' docker'
78+
79+ dependsOn assemble
80+ from bootJar. archivePath
81+ into createDockerfile. destFile. parentFile
82+ // отдельно указываем, что файлы конфигурации нужно положить в директорию config
83+ into ' config/' , {
84+ from ' config/'
85+ }
86+ }
87+ createDockerfile. dependsOn syncImageFiles
88+
89+ task buildImage (type : DockerBuildImage ) {
90+ description ' Собирает и загружает в Docker образ микросервиса'
91+
92+ dependsOn createDockerfile
93+ inputDir = createDockerfile. destFile. parentFile
94+ tag = " ${ project.name} :${ project.version} "
95+ }
96+
97+ task dockerVersion (type : DockerVersion ) {
98+ description ' Выводит информацию о версии Docker'
99+ }
100+ task dockerInfo (type : DockerInfo ) {
101+ description ' Выводит общие сведения об используемом экземпляре Docker'
102+ }
103+ // </editor-fold>
104+
105+ test {
106+ useJUnitPlatform()
107+ }
36108
37109repositories {
38110 // mavenLocal()
@@ -44,14 +116,13 @@ repositories {
44116dependencies {
45117 // Backend compile deps
46118// compile("org.springframework.boot:spring-boot-devtools:${springBootVersion}")
47- compile group : ' org.springframework.boot' , name : ' spring-boot-starter-web' , version : " ${ springBootVersion } "
48- compile group : ' org.springframework.boot' , name : ' spring-boot-starter-actuator' , version : " ${ springBootVersion } "
49- compile group : ' org.springframework.boot' , name : ' spring-boot-starter-websocket' , version : " ${ springBootVersion } "
50- compile group : ' net.bull.javamelody' , name : ' javamelody-spring-boot-starter' , version : ' 1.71 .0'
119+ compile group : ' org.springframework.boot' , name : ' spring-boot-starter-web'
120+ compile group : ' org.springframework.boot' , name : ' spring-boot-starter-actuator'
121+ compile group : ' org.springframework.boot' , name : ' spring-boot-starter-websocket'
122+ compile group : ' net.bull.javamelody' , name : ' javamelody-spring-boot-starter' , version : ' 1.72 .0'
51123
52- compile group : ' org.springframework.integration' , name : ' spring-integration-core' , version : " ${ springIntegrationVersion} "
53- compile group : ' org.springframework.integration' , name : ' spring-integration-file' , version : " ${ springIntegrationVersion} "
54- compile group : ' org.springframework.integration' , name : ' spring-integration-rmi' , version : " ${ springIntegrationVersion} "
124+ compile group : ' org.springframework.integration' , name : ' spring-integration-file'
125+ compile group : ' org.springframework.integration' , name : ' spring-integration-rmi'
55126
56127 compile group : ' com.google.code.findbugs' , name : ' jsr305' , version : ' 3.0.2'
57128 compile group : ' net.sf.jtidy' , name : ' jtidy' , version : ' r938'
@@ -68,17 +139,24 @@ dependencies {
68139 compile group : ' org.webjars' , name : ' angular-ui-select' , version : ' 0.19.6'
69140 compile group : ' org.webjars.npm' , name : ' balloon-css' , version : ' 0.5.0'
70141
142+ compileOnly(' org.springframework.boot:spring-boot-configuration-processor' )
143+
71144 runtime group : ' commons-logging' , name : ' commons-logging' , version : ' 1.2'
72- runtime(" org.springframework.boot:spring-boot-properties-migrator" ) // TODO remove after migration
73145
74146 // Test deps
75- testCompile group : ' org.springframework.boot' , name : ' spring-boot-starter-test' , version : " ${ springBootVersion} "
76- testCompile group : ' org.junit.jupiter' , name : ' junit-jupiter-api' , version : " ${ junitVersion} "
147+ testCompile group : ' org.springframework.boot' , name : ' spring-boot-starter-test'
77148 testCompile group : ' org.apache.commons' , name : ' commons-math3' , version : ' 3.6.1'
78-
79- testRuntime group : ' org.junit.jupiter' , name : ' junit-jupiter-engine' , version : " ${ junitVersion} "
149+ // JUnit family
150+ testCompileOnly ' junit:junit:4.12'
151+ testImplementation ' org.junit.jupiter:junit-jupiter-api:5.1.0'
152+ testRuntimeOnly ' org.junit.jupiter:junit-jupiter-engine:5.1.0'
153+ testRuntimeOnly ' org.junit.vintage:junit-vintage-engine:5.1.0'
80154}
81155
82156junitPlatform {
83157 enableStandardTestTask = true
84158}
159+
160+ startScripts {
161+ enabled = false
162+ }
0 commit comments