build.gradle示例代碼
buildscript {
ext {
springBootVersion = '1.5.4.RELEASE'
}
repositories {
mavenLocal()
maven { url = "http://maven.aliyun.com/nexus/content/groups/public" }
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath 'se.transmode.gradle:gradle-docker:1.2'
}
}
apply plugin: 'java'
apply plugin: 'idea'
//apply plugin: 'war'
apply plugin: 'org.springframework.boot'
//docker所需插件
apply plugin: 'docker'
version = '1.0.0'
sourceCompatibility = 1.8
repositories {
mavenLocal()
maven { url = "http://maven.aliyun.com/nexus/content/groups/public" }
mavenCentral()
}
dependencies {
compile('org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.0')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-aop')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('com.github.pagehelper:pagehelper-spring-boot-starter:1.1.1')
compile('com.alibaba:druid:1.0.31')
runtime('mysql:mysql-connector-java')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
//以下為jar配置
jar {
baseName = "coupon"
manifest {
attributes 'Main-Class': 'net.mrpotato.CouponApplication'
}
}
build.doLast {
copy{
from('build/libs')
into('build/libs')
include('coupon-'+version+'.jar')
rename{'coupon.jar'}
}
}
//以下為docker配置
group = 'coupon'
//mainClassName = 'net.mrpotato.CouponApplication'
task buildDocker(type: Docker, dependsOn: build, group: "coupon") {
push = false
applicationName = jar.baseName
dockerfile = file('src/main/docker/Dockerfile')
doFirst {
copy {
from jar
into stageDir
}
}
}
build.gradle簡要說明
- 新增buildscript下的dependencies新增依賴
classpath 'se.transmode.gradle:gradle-docker:1.2'
- 新增插件"docker"
- 設(shè)置group,用于docker鏡像區(qū)分
- 設(shè)置docker構(gòu)建配置,主要是Dockerfile文件位置
Dockerfile內(nèi)容
FROM java:8u111-jre
VOLUME /tmp
ADD coupon-1.0.0.jar coupon.jar
RUN sh -c 'touch /coupon.jar'
ENV JAVA_OPTS=""
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /coupon.jar" ]
Dockerfile簡要說明
- 由于工程使用java8,故使用鏡像java:8u111-jre(根據(jù)開發(fā)環(huán)境可選擇其他版本)
- VOLUME 容器掛載卷
- ADD 拷貝jar到容器中
- RUN 運行
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。