Cloud Build无法使用Maven构建简单的构建步骤

时间:2018-12-30 04:05:00

标签: maven docker dockerfile google-cloud-build

测试cloud-build

我的 cloudbuild.yaml

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

dockerfile:build在bitbucket管道中完美运行,没问题。我用

 <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>

但是通过这一步的云构建,我得到了错误:

[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

(JAR_FILE是从maven dockerfile插件传递的

没有此类文件或目录

为什么?..最后,我要调用dockerfile:build,并希望它与从另一个管道中构建时的一样。

我的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脚本是(即日志中第15/15步中提到的脚本):

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

((我确实尝试过将硬编码的值传递给$ SERVCE_FOLDER_NAME,$ ACTIVE_PROFILES-相同[它在bitbucket管道中起作用)

1 个答案:

答案 0 :(得分:0)

我想到了一些事情