skip to Main Content

I want to build and deploy the container of the project to Docker Hub. I have a problem when I look through its build process in GitHub Actions.

I use mr-smithers-excellent/docker-build-push@v5 for docker

Here is the repo : Link

It throws the issue shown below:

#14 ERROR: process "/bin/sh -c mvn package" did not complete successfully: exit code: 1
------
 > [build 5/5] RUN mvn package:
Error: ERROR] 
Error: ERROR] Please refer to /target/surefire-reports for the individual test results.
Error: ERROR] Please refer to dump files (if any exist) September 19, 2023.dump, September 19, 2023-jvmRun[N].dump and September 19, 2023.dumpstream.
Error: ERROR] -> [Help 1]
Error: ERROR] 
Error: ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
Error: ERROR] Re-run Maven using the -X switch to enable full debug logging.
Error: ERROR] 
Error: ERROR] For more information about the errors and possible solutions, please read the following articles:
Error: ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
------
Dockerfile:12
--------------------
  10 |     
  11 |     # Build the project and create the executable JAR
  12 | >>> RUN mvn package
  13 |     
  14 |     # Stage 2: Run stage
--------------------
ERROR: failed to solve: process "/bin/sh -c mvn package" did not complete successfully: exit code: 1
Error: Command failed: docker build -f Dockerfile -t docker.io/***/bookdelivery:latest .

Edited

I also got this error message .

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

How can I fix it?

Here is the Dockerfile:

# Stage 1: Build stage
FROM maven:3.8.4-openjdk-17-slim AS build

# Copy Maven files for dependency resolution
COPY pom.xml ./
COPY .mvn .mvn

# Copy application source code
COPY src src

# Build the project and create the executable JAR
RUN mvn package

# Stage 2: Run stage
FROM openjdk:17-jdk-slim

# Set working directory
WORKDIR bookdelivery

# Copy the JAR file from the build stage
COPY --from=build target/*.jar bookdelivery.jar

# Expose port 1221
EXPOSE 1221

# Set the entrypoint command for running the application
ENTRYPOINT ["java", "-jar", "bookdelivery.jar"]

Here is the workflow file:

name: CI/CD Pipeline

## The following codes trigger the pipeline when the code is pushed on the main branch.

on:
  push:
    branches: [main]

jobs:
  test:
    name: Unit Test
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up JDK 17
        uses: actions/setup-java@v3
        with:
          java-version: '17'
          distribution: 'temurin'
          cache: 'maven'

      - name: Build with Maven
        run: mvn -B package --file pom.xml

      - name: Cache Maven packages
        uses: actions/cache@v3
        with:
          path: ~/.m2
          key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
          restore-keys: ${{ runner.os }}-m2

      - name: Run Tests
        run: mvn -B test

  build-and-push:
    name: Build and Push
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v3

      - name: Set up JDK 17
        uses: actions/setup-java@v3
        with:
          java-version: '17'
          distribution: 'temurin'
          cache: 'maven'

      - name: Build with Maven
        run: mvn -B package --file pom.xml

      - name: Dockerize & Push Docker Image
        uses: mr-smithers-excellent/docker-build-push@v5
        with:
          image: noyandocker/bookdelivery
          tags: latest
          registry: docker.io
          dockerfile: Dockerfile
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

Here is the repo : Link

2

Answers


  1. Unfortunately with the current information no one will be able to help here. There are at least two problems here, only one of which can be directly resolved.

    First of all you aren’t using the standard docker package publish action. You can see a working example of the docker/build-push-action we have in this authress local build pipeline.

    The relevant parts are:

    - name: DockerHub - Container registry login
      uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
      with:
        registry: ${{ env.DOCKER_HUB_REGISTRY }}
        username: ${{ secrets.DOCKER_HUB_USERNAME }}
        password: ${{ secrets.DOCKER_HUB_PASSWORD }}
    
    - name: Build and push Docker image
      uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
    

    But the real issue has nothing to do with docker at all, the and error you get tells you that:

    ------
     > [build 5/5] RUN mvn package:
    Error: ERROR] 
    Error: ERROR] Please refer to /target/surefire-reports for the individual test results.
    Error: ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
    Error: ERROR] -> [Help 1]
    Error: ERROR] 
    Error: ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    Error: ERROR] Re-run Maven using the -X switch to enable full debug logging.
    Error: ERROR] 
    Error: ERROR] For more information about the errors and possible solutions, please read the following articles:
    Error: ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
    ------
    

    Specifically, you can see the recommendation in that error message:

    Re-run Maven using the -X switch to enable full debug logging.
    

    So update your dockerfile, and change RUN mvn package to RUN mvn package -Xe. And then update your post with the included error details.

    Login or Signup to reply.
  2. please take a look at this PR.

    Noteworthy:

    1 – don’t package your project twice. the github action already packages your project so it’s just a waste of image layers to make packaging responsibility of docker to do so. use a smaller, thinner, docker build file that expects the jar file to be built already:

    FROM eclipse-temurin:17-jre-alpine
    
    ARG SERVICE=bookdelivery
    ARG VERSION=0.0.1-SNAPSHOT
    
    ENV SERVICE=$SERVICE
    ENV VERSION=$VERSION
    
    ADD ./target/$SERVICE-$VERSION.jar /$SERVICE-$VERSION.jar
    
    ENTRYPOINT java -jar /$SERVICE-$VERSION.jar
    

    2 – tag your images properly. one thing is to always use the latest version on your tests and development images, another one completely different is to put those dangling pointers in production. pin a specific version on the images you’ll put in production.

    Even more important, if you are authoring an image, don’t just tag it as latest. use proper tag versions, so if anyone needs t rollback a deployment the latest running, stable version will be known. the action i first sent as example to you had this approach, the one in the PR has it too.

    If you want to know more about this action, read the action logs in my fork, i ran it a couple of times so you can see both failure logs and success logs.

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