Cloud Build fails to build the the simple build step with maven

天大地大妈咪最大 提交于 2019-12-12 01:25:33

问题


Testing the cloud-build

Part of my cloudbuild.yaml

  - name: 'gcr.io/cloud-builders/mvn'
    args: ['dockerfile:build']

dockerfile:build perfectly works in bitbucket pipeline, no problem. I use

 <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>dockerfile-maven-plugin</artifactId>
                <version>${dockerfile-maven-version}</version>
                <executions>
                    <execution>
                        <id>default</id>
                        <goals>
                            <goal>build</goal>
                            <goal>push</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <repository>gcr.io/my-project-id/${project.artifactId}</repository>
                    <tag>${project.version}</tag>
                    <buildArgs>
                        <JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
                    </buildArgs>
                </configuration>
            </plugin>

But with the cloud-build for this single step I get the error:

[INFO] Step 14/15 : ARG JAR_FILE
[INFO] 
[INFO] ---> Using cache
[INFO] ---> 55793de4bb9f
[INFO] [INFO] Step 15/15 : ADD target/${JAR_FILE} /usr/share/$SERVCE_FOLDER_NAME/app.jar
[INFO] 
[ERROR] ADD failed: stat /mnt/cache/docker/tmp/docker-builder589658449/target/myappname-0.0.1-SNAPSHOT.jar: no such file or directory

(the JAR_FILE is passed from the maven dockerfile plugin

no such file or directory

Why?.. In the end of the day I juse call dockerfile:build and expect it to be the same as it is when I build it from another pipeline.

My Dockerfile:

FROM openjdk:8-jdk

ENV GOOGLE_APPLICATION_CREDENTIALS=/app/credentials.json

ARG ACTIVE_PROFILES=dev
ENV ACTIVE_PROFILES=$ACTIVE_PROFILES
ARG CREDENTIALS
ARG SERVCE_FOLDER_NAME=myappname-service
ENV SERVCE_FOLDER_NAME=$SERVCE_FOLDER_NAME

#ENTRYPOINT ["/usr/bin/java", "-jar", "/usr/share/$SERVCE_FOLDER_NAME/app.jar"]

ENTRYPOINT ["./entrypoint.sh" ]

WORKDIR /app

EXPOSE 8080

COPY ./.gcloud/credentials.json credentials.json
COPY entrypoint.sh .

#Add Maven dependencies (not shaded into the artifact; Docker-cached)
#ADD target/lib           /usr/share/$SERVCE_FOLDER_NAME/lib

ARG JAR_FILE
ADD target/${JAR_FILE} /usr/share/$SERVCE_FOLDER_NAME/app.jar

EntryPoint script is (that is what is mentioned on step 15/15 in the log):

java -Djava.security.egd=file:/dev/./urandom -jar /usr/share/$SERVCE_FOLDER_NAME/app.jar --spring.profiles.active=$ACTIVE_PROFILES

(I did try to pass hard-coded values to $SERVCE_FOLDER_NAME, $ACTIVE_PROFILES - same [it works in bitbucket pipeline])


回答1:


A few things come to mind,

  • how are you triggering the builds?
    • manually with gcloud or api? or automatically with build triggers or the github app?
  • it seems that the target/ directory might not be present in the remote workspace-- are you ignoring target/ or .jar files anywhere?
    • the remote workspace might not be getting the target/ directory or .jar files if they are in your .gitignore or .gcloudignore
    • try making an empty .gcloudignore or temporarily removing target/ and .jar files from .gitignore
    • relevant links: https://cloud.google.com/sdk/gcloud/reference/topic/gcloudignore, https://github.com/GoogleCloudPlatform/cloud-builders/issues/40
  • have you tried debugging with cloud-build-local? it allows you to write and explore the workspace locally
    • https://cloud.google.com/cloud-build/docs/build-debug-locally
    • https://github.com/GoogleCloudPlatform/cloud-build-local


来源:https://stackoverflow.com/questions/53975196/cloud-build-fails-to-build-the-the-simple-build-step-with-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!