我想从Maven项目中使用GitLab CI Pipeline构建Docker镜像,但构建失败,我不知道该怎么办。
Dockerfile:
FROM maven:3.6.3-jdk-8
ENV EXECUTABLE_APP_JAR=hello-spring-boot-exec.jar
COPY /target/${EXECUTABLE_APP_JAR} /app.jar
ENTRYPOINT ["java", "-jar", "/app.jar"]
EXPOSE 7001
.gitlab-ci.yml:
image: docker:stable
# Define the stages that will be executed in the pipeline
stages:
- build
- package
# Define global variables
variables:
MAVEN_CLI_OPTS: >
-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository
--global-settings $MAVEN_SETTINGS_XML_GITLAB_PACKAGE_REGISTRY
cache:
key: global-maven-repository-cache
paths:
- .m2/repository
# Define the job that will build the Maven project
maven-build:
image: maven:3.6.3-jdk-8
stage: build
script: "mvn $MAVEN_CLI_OPTS clean deploy -e"
docker-build:
stage: package
script:
- docker info
- docker build -t gitlab.my-domain.local:5000/spring-boot-hello-world:latest .
- docker push gitlab.my-domain.local:5000/spring-boot-hello-world:latest
问题是stage docker-build没有找到在$CI_PROJECT_PROJECT/target下构建的来自上一个maven-build stage的artifcat:
#4 ERROR: failed to calculate checksum of ref 93b345e2-1ada-4609-9021-058007df7967::r3cqfb3qtqoee8maxyaqmtsnv: failed to walk /var/lib/docker/tmp/buildkit-mount881123238/target: lstat /var/lib/docker/tmp/buildkit-mount881123238/target: no such file or directory
正如你所看到的,docker-build stage不在$CI_PROJECT_PROJECT目录中-我如何告诉docker-build stage从该目录中获取工件?
2条答案
按热度按时间mbjcgjjk1#
好了,我找到了解决方案-我必须在.gitlab-ci.yml中的maven-build-stage下添加工件:
jogvjijk2#
错误消息表明,在Docker构建过程中,正在处理具有特定ID的引用,并且Docker尝试为其计算校验和。然而,这个过程失败了,因为Docker无法找到给定路径(
/var/lib/docker/tmp/buildkit-mount881123238/target
)的目录或文件。这可能是由于各种原因造成的,例如Dockerfile中指定的路径不正确,文件丢失或Docker构建上下文的问题。