首页 > 解决方案 > GitHub Action COPY 失败:未指定源文件

问题描述

配置 GitHub 操作以构建此项目的图像我收到此错误:

Step 5/7 : COPY /target/*.jar app.jar
COPY failed: no source files were specified

这是项目 Dockerfile,我从构建上下文路径引用文件,而不是从相对路径。

FROM openjdk:8-jdk-alpine as build
COPY . /usr/app
WORKDIR /usr/app
RUN chmod +x mvnw \
    && ./mvnw --version \
    && ./mvnw clean package
COPY /usr/app/target/*.jar app.jar
EXPOSE 8080

ENTRYPOINT ["java","-jar","app.jar"]

我已经验证了文件是否存在并使用ls -l /target命令读取权限:

drwxr-xr-x    3 root     root          4096 Oct 18 15:35 classes
drwxr-xr-x    3 root     root          4096 Oct 18 15:35 generated-sources
drwxr-xr-x    3 root     root          4096 Oct 18 15:35 generated-test-sources
-rw-r--r--    1 root     root      48625321 Oct 18 15:35 learning-spring-boot-0.0.1.jar
-rw-r--r--    1 root     root         33089 Oct 18 15:35 learning-spring-boot-0.0.1.jar.original
drwxr-xr-x    2 root     root          4096 Oct 18 15:35 maven-archiver
drwxr-xr-x    3 root     root          4096 Oct 18 15:35 maven-status
drwxr-xr-x    2 root     root          4096 Oct 18 15:35 surefire-reports
drwxr-xr-x    3 root     root          4096 Oct 18 15:35 test-classes

这是命令find .后的输出./mvnw clean package

./target/learning-spring-boot-0.0.1.jar
./target/maven-archiver
./target/maven-archiver/pom.properties
./target/generated-sources
./target/generated-sources/annotations
./target/surefire-reports

使用相对路径在本地运行,但使用来自构建上下文的路径失败。

COPY /target/*.jar app.jar

是项目网址。

我错过了什么?

标签: dockerdockerfilegithub-actions

解决方案


在我看来,您想使用多阶段 docker 构建,但您没有开始第二阶段。第二步COPY不起作用,因为它仍处于同一阶段。就像 BMitch 提到的,在同一阶段,您只能使用 COPY 从构建上下文中复制。我对您进行了一些更改(从第二阶段开始,--from在 COPY 中使用),Dockerfile现在构建良好。Dockerfile 内容如下:

FROM openjdk:8-jdk-alpine as build
COPY . /usr/app
WORKDIR /usr/app
RUN chmod +x mvnw \
    && ./mvnw --version \
    && ./mvnw clean package

FROM openjdk:8-jre-alpine
COPY --from=build /usr/app/target/*.jar app.jar
EXPOSE 8080

ENTRYPOINT ["java","-jar","app.jar"]

推荐阅读