Gitlab-cli using docker and maven for springboot project

I have a project in spring boot with dockerfile. I have the repo on gitlab. I would like to use gitlab pipeline for building docker images. So I followed the tutorial to create .gitlab-cli.yml

build_image:
  image: docker:git
  services:
  - docker:dind
  script:
    - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN registry.example.com
    - docker build -t registry.example.com/my-group/my-project .
    - docker run registry.example.com/my-group/my-project /script/to/run/tests
    - docker push registry.example.com/my-group/my-project:latest
  only:
    - master

But my dockerfile has the following:

FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD target/talianet-invoice.jar app.jar
ENV JAVA_OPTS="-Dspring.profiles.active=prod"
ENV LANG en_US.UTF-8
ENV TZ=America/New_York
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

When I push my code CI is showing me build failure.

Step 3/8 : ADD target/talianet-invoice.jar app.jar
ADD failed: stat /var/lib/docker/tmp/docker-builder253676886/target/talianet-invoice.jar: no such file or directory
ERROR: Job failed: exit code 1

I usually run this on my server to create the docker image:

mvn clean install dockerfile:build -Pprod -Dspring.profiles.active=prod

How to use this with gitlab-ci? to build using maven and publish docker images to the registry?

1 Like

UP! I have the same problem, created issue on gitlab runner and stackoverflow