Gradle-如何在构建时生成dockerfile

时间:2019-07-25 02:17:44

标签: docker gradle dockerfile build.gradle gradle-plugin

我有一个Java Sprint Boot应用程序,我想为其创建一个dockerfile,以用于创建Docker映像。我已经使用maven使它工作,但是不能使用gradle使它工作(这是我真正想要的)。我尝试使用gradle init将pom.xml转换为gradle.build,然后使用等级构建使用dockerfile构建工作罐,但未生成dockerfile。

我想要做的就是创建dockerfile而不将其推送到存储库中。

有关我的build.gradle的副本,请参见下文

/*
 * This file was generated by the Gradle 'init' task.
 */

plugins {
    id 'org.springframework.boot' version '2.1.6.RELEASE'
    id 'maven'
}

apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'io.spring.dependency-management'

repositories {
    mavenLocal()
    maven {
        url = 'https://repo.spring.io/snapshot'
    }

    maven {
        url = 'https://repo.spring.io/milestone'
    }

    maven {
        url = 'http://repo.maven.apache.org/maven2'
    }
}



buildDir = 'gradle_build'

sourceSets {
  main {
     java {
          srcDir 'src/main/java'
     }
     resources {
        srcDir 'src/main/resources'
     }
  } 
}

jar {
  manifest { 
    attributes "Main-Class": "com.in28minutes.rest.webservices.restfulwebservices.RestfulWebServicesApplication"
  }  

  from {
    configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
  }
}




dependencies {
    compile 'org.springframework.boot:spring-boot-starter-data-jpa:2.1.0.RELEASE'
    compile 'org.springframework.boot:spring-boot-starter-web:2.1.0.RELEASE'
    compile 'javax.xml.bind:jaxb-api:2.3.0'
    compile 'com.sun.xml.bind:jaxb-impl:2.3.0'
    compile 'org.glassfish.jaxb:jaxb-runtime:2.3.0'
    compile 'javax.activation:activation:1.1.1'
    runtime 'org.springframework.boot:spring-boot-devtools:2.1.0.RELEASE'
    runtime 'com.h2database:h2:1.4.197'
    testCompile 'org.springframework.boot:spring-boot-starter-test:2.1.0.RELEASE'
}


docker {
    baseImage = 'myTestImage'
    maintainer = 'xyz@gmail.com"'
}



group = 'com.in28minutes.rest.webservices'
version = '1.0.0.RELEASE'
sourceCompatibility = '1.8'

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

我想念其他东西吗?

我正在运行“ gradle build”命令

0 个答案:

没有答案