在Gradle构建期间,Google Cloud Container Build触发器崩溃

时间:2018-02-24 19:05:53

标签: google-cloud-platform

我正在尝试为使用gradle构建的kotlin应用程序设置构建触发器。为此,我将以下Dockerfile放在一起:

FROM gradle:jdk8 as builder

WORKDIR /home/gradle/project

COPY . .

WORKDIR ./Kuroji-Eventrouter-Server

RUN gradle shadowJar

FROM openjdk:8-jre-alpine

WORKDIR /app

COPY --from=builder /home/gradle/project/Kuroji-Eventrouter-Server/build/libs/kuroji-eventrouter-server-*-all.jar kuroji-eventrouter-server.jar

ENTRYPOINT ["java", "-jar", "kuroji-eventrouter-server.jar"]

该文件在我的机器上使用docker build并且在Google容器注册表中正常启动但是在RUN gradle shadowJar任务期间它崩溃了一些gradle错误:

Step 5/9 : RUN gradle shadowJar
 ---> Running in ddd190fc2323
Starting a Gradle Daemon (subsequent builds will be faster)
[91m
[0m[91mFAILURE: [0m[91mBuild failed with an exception.[0m[91m
[0m[91m
[0m[91m* What went wrong:
[0m[91mCould not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().
[0m[91m> [0m[91mCould not create service of type CrossBuildFileHashCache using BuildSessionScopeServices.createCrossBuildFileHashCache().
[0m[91m
[0m[91m* Try:
[0m[91mRun with [0m[91m--stacktrace[0m[91m option to get the stack trace. Run with --info[0m[91m or --debug[0m[91m option to get more log output. Run with [0m[91m--scan[0m[91m to get full insights.[0m[91m
[0m[91m
[0m[91m* Get more help at https://help.gradle.org
[0m[91m
[0m[91mBUILD FAILED in 3s
The command '/bin/sh -c gradle shadowJar' returned a non-zero code: 1
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: exit status 1
[0m

我尝试在docker HUB上构建Image并发生同样的事情:https://hub.docker.com/r/usbpc/kuroji-eventrouter-server/builds/bnknnpqowwabdy82ydxiypc/

这让我非常困惑,因为我认为容器应该可以在任何地方运行而不依赖于环境。我该怎么做才能让google构建我的容器?

1 个答案:

答案 0 :(得分:1)

问题是文件权限问题。使用--stacktrace选项,我发现gradle进程没有权限在源代码中创建文件夹。

我想要做的解决方案是在COPY指令上使用--chown=gradle:gradle选项,不幸的是谷歌云尚未支持它。

因此解决方案是在执行gradle构建之前添加USER root