在springboot里,我们的task任务可以添加docker构建的功能,在gradle集成环境里,直接可以实现编译,测试,打包镜像的流水线作业,很是方便!
下面分享给大家,在gradle里添加docker镜像的构建功能。添加依赖
apply plugin: 'docker'buildscript { repositories { dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") classpath('se.transmode.gradle:gradle-docker:1.2') } } }
添加Dockerfile
//建立目录:/src/main/docker/FROM fabric8/java-jboss-openjdk8-jdk:1.4ENV JAVA_APP_JAR="app.jar"ENV JAVA_MAX_MEM_RATIO=100ENV AB_OFF ""ADD --chown=jboss:jboss lindone-0.0.1.jar /deployments/app.jar
添加部署脚本
// 打包镜像task buildDocker(type: Docker, dependsOn: build) { push = false applicationName = jar.baseName dockerfile = file('src/main/docker/Dockerfile') doFirst { copy { from jar into stageDir } }}// 复制jar文件task copyJar(type: Copy) { dependsOn 'jar' from "build/libs/lindone-0.0.1.jar" into 'build/docker'}buildDocker.dependsOn copyJar