You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
4.2 KiB

  1. plugins {
  2. id 'com.bmuschko.docker-remote-api' version '3.6.1'
  3. id 'war'
  4. }
  5. sourceCompatibility = JavaVersion.VERSION_1_8
  6. targetCompatibility = JavaVersion.VERSION_1_8
  7. compileJava.options.encoding = "UTF-8"
  8. import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
  9. import com.bmuschko.gradle.docker.tasks.image.DockerPushImage
  10. import com.bmuschko.gradle.docker.tasks.image.Dockerfile
  11. group 'com.wanhai.tml'
  12. version '1.0.1'
  13. ext{
  14. baseImgName="${docker_rep_url}/jboss/wildfly-base"
  15. baseImgTag="latest"
  16. targetImgName="${docker_rep_url}/wanhai/demo/${project.name.replaceAll("_","-").toLowerCase()}"
  17. targetImgTag="${project.version}"
  18. }
  19. /***************Gardle Docker plugin setting***************************/
  20. docker{
  21. registryCredentials {
  22. url = "http://${docker_rep_url}"
  23. username = docker_rep_user
  24. password = docker_rep_password
  25. }
  26. }
  27. task prepareDockerBuild(type: Copy, dependsOn:build){
  28. from "${buildDir}/libs/${war.archiveName}"
  29. into "${buildDir}/docker"
  30. }
  31. task createDockerFile(type: Dockerfile,dependsOn: prepareDockerBuild){
  32. destFile=project.file("${buildDir}/docker/Dockerfile")
  33. from "${baseImgName}:${baseImgTag}"
  34. label(['Maintainer':'richard_shih@wanhai.com'])
  35. environmentVariable('JAVA_OPTS','-Xms64m -Xmx384m -XX:MetaspaceSize=64M -XX:MaxMetaspaceSize=128m -XX:MaxDirectMemorySize=512m -XX:+UseParallelGC -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=$JBOSS_MODULES_SYSTEM_PKGS -Djava.awt.headless=true')
  36. copyFile "$war.archiveName",'${JBOSS_HOME}/standalone/deployments'
  37. }
  38. task buildImage(type: DockerBuildImage, dependsOn: createDockerFile){
  39. inputDir = createDockerFile.destFile.parentFile
  40. tags=["${targetImgName}:${targetImgTag}","${targetImgName}:latest"]
  41. }
  42. task pushImage(type: DockerPushImage, dependsOn: buildImage){
  43. imageName=buildImage.tags[0]
  44. }
  45. /**********************************************************************/
  46. /****************************Pipleline Tasks***************************/
  47. /**
  48. * build & deploy to server
  49. */
  50. task deploy(type: Exec,dependsOn: 'release'){
  51. def stackName="DEMOS"
  52. def serviceName = "${project.name.replaceAll('_', '-')}"
  53. def scriptPath = "${buildDir}/deploy.sh"
  54. doFirst{
  55. //carete upgrade script before task start
  56. if(project.hasProperty('isCI') && Boolean.valueOf(project.isCI)){
  57. File f = new File(scriptPath);
  58. f.delete()
  59. f.withWriter('utf-8') {writer ->
  60. writer.writeLine "rancher export ${stackName} && cd ${stackName}"
  61. writer.writeLine "rancher up -d --pull --upgrade --force-upgrade ${serviceName}"
  62. writer.writeLine "cd .. && rm -rf ${stackName}"
  63. }
  64. f.setExecutable(true)
  65. }
  66. }
  67. if(project.hasProperty('isCI') && Boolean.valueOf(project.isCI)){
  68. commandLine scriptPath
  69. }
  70. }
  71. /**
  72. * build & push to repository
  73. */
  74. task release(dependsOn: build){
  75. if(project.hasProperty('isCI') && Boolean.valueOf(project.isCI)){
  76. dependsOn pushImage
  77. }
  78. }
  79. /**
  80. * Entry point of pipleline
  81. */
  82. task pipeline(dependsOn: build){
  83. if(project.hasProperty('isCI') && Boolean.valueOf(project.isCI)){
  84. if(project.hasProperty('isRelease') && Boolean.valueOf(project.isRelease)){
  85. dependsOn release
  86. }
  87. if(project.hasProperty('isDeploy') && Boolean.valueOf(project.isDeploy)){
  88. dependsOn deploy
  89. }
  90. }
  91. }
  92. /**********************************************************************/
  93. war{
  94. manifest {
  95. attributes("Implementation-Title": project.name,
  96. "Implementation-Version": project.version,
  97. "Implementation-Vendor":"WANHAI LINES LTD.",
  98. "Built-By":"IT Division",
  99. "Greated-By":"Gradle $gradle.gradleVersion",
  100. "Java-Version": System.getProperty("java.version") + " " + "(" + System.getProperty("java.vm.vendor") + ")")
  101. }
  102. }
  103. repositories {
  104. maven {
  105. url "http://${maven_rep_url}/repository/maven-public/"
  106. }
  107. }
  108. dependencies {
  109. providedCompile 'org.zkoss.zk:zkbind:8.0.2.2',
  110. 'org.zkoss.zk:zhtml:8.0.2.2',
  111. 'org.zkoss.zk:zkplus:8.0.2.2',
  112. 'org.zkoss.zk:zul:8.0.2.2'
  113. providedCompile 'javax:javaee-api:7.0'
  114. }