启动HttpFileServer后,Gradle任务挂起

时间:2017-08-31 22:59:18

标签: docker gradle

我正在尝试构建一个Docker镜像,在Dockerfile中我想使用文件服务器而不是使用ADD指令(不创建图层)来拉取文件。所以在我的Gradle脚本本身中,我运行了这样的服务器:

SimpleHttpFileServerFactory factory = new SimpleHttpFileServerFactory()
server = factory.start(new File(location), port)

我正在使用'se.transmode.gradle'Gradle插件来构建图像。我面临的问题是,在运行文件服务器之后,buildDocker任务挂起,而--debug arg只显示常规检查消息,如下所示:

19:28:59.110 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Waiting to acquire shared lock on daemon addresses registry.
19:28:59.110 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Lock acquired.
19:28:59.110 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on daemon addresses registry.

如果我直接在容器中读取要复制的文件,那么一切正常。

如果我使用生成的Dockerfile,它从文件服务器中提取文件...使用'docker build'命令,同时在gradle中运行文件服务器...那么一切正常。

我的buildDocker任务如下:

task buildDocker(type: Docker, dependsOn: [buildRpm, generateDockerfile, startHttpFileServer]) {
push = false
applicationName = 'test-app'
tagVersion = "$rootProject.appVersion"
dockerfile = file("${buildDir}/docker/tmp/Dockerfile")

doFirst {
    copy {
        from("${buildDir}/distributions/${applicationName}-${tagVersion}.noarch.rpm")
        into("${stageDir}/target")
    }
    copy {
        from("${rootDir}/Packaging/src/docker/entrypoint.sh")
        into("${stageDir}/target")
    }
    exec {
        commandLine "docker", "login", "-u", "${username}", "-p", "${password}", "${registryUrl}"
    }
}

doLast {
   exec {
        commandLine "docker", "logout", "${registryUrl}"
   }
}
  }
  buildDocker.finalizedBy stopHttpFileServer

0 个答案:

没有答案