Search code examples
karate

Error deploying Karate into container using karatelabs/karate-chrome


I am trying to deploy my Karate project into container using karatelabs/karate-chrome image:

In my POM.XML, I have: Java 21, Karate 1.4.1, Maven 3.6.0

My Dockerfile (which invokes karate_runner.sh)

FROM karatelabs/karate-chrome
# maven:3.9.6-eclipse-temurin-21-alpine

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

#COPY settings.xml /usr/share/maven/ref/
COPY pom.xml /tmp/pom.xml
COPY . /usr/src/app

RUN ["chmod", "+x", "/usr/src/app/maven_runner.sh"]
RUN ulimit -c -l
RUN mvn -B -f /tmp/pom.xml -s /usr/share/maven/ref/settings-docker.xml prepare-package -DskipTests

#Execute shell script from the docker file! This shell script will invoke karate parallel runner class
CMD ["sh","/usr/src/app/karate_runner.sh"]

Karate_runner.sh file

As per https://github.com/karatelabs/karate/blob/master/build-docker.sh

I encountered below issue.

Issue

Would be great if you could guide me how to troubleshoot these issues.


Solution

  • After few cups of tea, I have realised that I can actually use plain JDK 21 image and manually install Maven of the same version used locally on my laptop. Using this image, I can now run my parallel runner class successfully!

    Dockerfile

    # FROM syntax indicates type of docker image we will use. 
    
    FROM openjdk:21-jdk 
    
     
    # Install maven 
    
    ARG MAVEN_VERSION=3.9.8 
    
    ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries 
    
    
    RUN mkdir -p /usr/share/maven /usr/share/maven/ref \ 
    
    && curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \ 
    
    && tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \ 
    
    && rm -f /tmp/apache-maven.tar.gz \ 
    
    && ln -s /usr/share/maven/bin/mvn /usr/bin/mvn 
    
    ENV MAVEN_HOME=/usr/share/maven 
    
     
    RUN mkdir -p /usr/src/app 
    
    WORKDIR /usr/src/app 
    
     
    COPY pom.xml /tmp/pom.xml 
    
    # Copy an entire project into /usr/src/app 
    
    COPY . /usr/src/app 
    
     
    #This is to provide maven_runner.sh with executable permission 
    
    RUN ["chmod", "+x", "/usr/src/app/maven_runner.sh"] 
    
    RUN ulimit -c -l 
    
     
    # Instruct Maven to download all dependencies in advance 
    
    RUN mvn -B -f /tmp/pom.xml prepare-package -DskipTests 
    
     
    # This CMD - command part will be executed upon Docker Run command 
    
    CMD ["sh","/usr/src/app/maven_runner.sh"] 
    
    

    maven_runner.sh file

    #!/usr/bin/env bash
    echo "START: Running tests..."
    
    # Invoke ParallelTestRunner class
    mvn test -Dtest=ParallelTestRunner
    
    if [[ $? -ne 0 ]] ; then
      echo "FINISH: There are test failures, failing build..."
      echo "Exiting with code 1."
      exit 1
    else
      echo "FINISH: All tests passed!"
      echo "Exiting with code 0."
      exit 0
    fi