skip to Main Content

I would like to build a Docker image with a GitLab CI Pipeline from a Maven project but the build fails and I don’t know what to do.

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

Problem is that the stage docker-build does not find the artifcats from the previous maven-build stage which were build under $CI_PROJECT_DIR/target:

#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

As you can see the docker-build stage is not in the $CI_PROJECT_DIR directory – how can I tell the docker-build stage to take the artifacts from that directory?

2

Answers


  1. Chosen as BEST ANSWER

    Ok,I found the solution - I had to add artifacts under the maven-build-stage in .gitlab-ci.yml:

    # 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"
    artifacts:
      paths:
        - $CI_PROJECT_DIR/target/*-exec.jar
    

  2. the error message suggests that during the Docker build process, a reference with a specific ID was being processed, and Docker attempted to calculate a checksum for it. However, the process failed because Docker was unable to find a directory or file at the given path (/var/lib/docker/tmp/buildkit-mount881123238/target). This can happen due to various reasons, such as incorrect paths specified in your Dockerfile, missing files, or iemphasized textssues with the Docker build context.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search