Karate: docker images for maven and gradle

Created on 17 May 2018  路  15Comments  路  Source: intuit/karate

yes this has come up before, but more requests are coming in for this and apparently makes integration with some CI tools easier

enhancement help wanted

All 15 comments

I am already using docker image build from this, trying to integrate with CI.
can try sending PR may be it is helpful.

@avyasbms yes please !

Hi @ptrthomas

We integrated the project in CI(bamboo) using dockers
I'll be looking at Docker again but here is what I have done

  1. Created docker image with all dependencies
  2. Pushed to registry
  3. Executed Docker image in CI (Individual projects can choose to execute their specific tests via Tags)

Dockerfile :

FROM maven:3-jdk-8-alpine

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


# selectively add the POM file
ADD pom.xml /usr/src/app/
# get all the downloads out of the way
RUN mvn verify clean --fail-never


ADD . /usr/src/app
ADD ./src/test/java/karate-config.js.example /usr/src/app/src/test/java/karate-config.js

Execution of Tests in CI


docker run --volume ${bamboo.working.directory}/reports:/usr/src/app/target --workdir /usr/src/app --rm mypersonal-Registry/bdd-api:latest mvn test -Dcucumber.options="--tags @MyTags"

Reports available in path ${bamboo.working.directory}/reports after execution.

Let me know if this is something in lines of your thoughts.

request those watching this repo to weigh in please cc @avyasbms

A message for all looking for Docker support - there is hardly any need for this because of the standalone JAR / binary - which only needs the JRE as a pre-requisite: https://github.com/intuit/karate/tree/master/karate-netty#standalone-jar

@ptrthomas unable to download jar from the link mention in document (dl.bintray.com/ptrthomas/karate/)

@sauravkumar05 you probably tried to "right-click" anyway use the binary with the release-notes: https://github.com/intuit/karate/releases/tag/v0.8.0

Was having a need to docker-ize the stand-alone JAR at work, and this can be a reference for others:

FROM openjdk:8-jdk-alpine

COPY src/test/java/mock/_mock.feature /opt/karate/
RUN wget -O karate.jar https://bintray.com/ptrthomas/karate/download_file?file_path=karate-0.9.0.RC1.jar
RUN mv karate.jar /opt/karate/karate.jar
EXPOSE 443
WORKDIR /opt/karate

CMD ["java", "-jar", "karate.jar", "-m", "_mock.feature", "-p", "443", "-s"]

I have something also, i custom made an image which has the v0.8.0.1 jar in it. Then using a docker-compose to get it up

version: "2.0"
services:
  cleanup:
    image: jawadkalia/karate:latest
    volumes:
        - ./:/APIAutomation
    command: rm -rf APIAutomation/target 
  karate:
    image: jawadkalia/karate:latest
    volumes:
        - ./:/Automation
    command: java -jar karate.jar -T 2 -t ~@ignore -t ~@autogen -t @f -e qa -o APIAutomation/target ./Automation/src/test/java/
    depends_on: 
      - cleanup

Also the following jenkinsfile can also help with setting up a jenkins to run docker image containing karate

node('docker') {
    try{
        stage('Updating to Latest Code') {
            git branch: 'master'

        }
        stage('Build') {
            sh 'docker-compose -f docker-composeQA.yml up'
            }
        stage('Generating Reports') {
            generateCucumberReports()
        }
            }
    finally{
        stage('Destroying containers') {
            sh 'docker-compose -f docker-composeQA.yml down'
        }
    }
}

def generateCucumberReports() {
    cucumber fileIncludePattern: '**/TEST-*.json', sortingMethod: 'ALPHABETICAL', buildStatus: 'FAILURE', parallelTesting: true
}

When I run it like docker run -it -u 1000 -w /opt/api-test --mount type=bind,source=/path/to/api-test,target=/opt/api-test openjdk:8-jdk-alpine java -jar /opt/api-test/karate.jar src/features it totally ignores my karate-config.js, when I run it in centos container with jdk installed it runs just fin. Any tips?

@76creates nope :| btw IMO there should not be a need to docker-ize the JAR if you have a JRE installed - because of how self-contained it is. I needed to do it (in thread above) because the deployment pipeline was based on docker.

My solutions for maven

docker-compose

version: "2.0"
services:
  karate:
    image: jawadkalia/karate-maven
    volumes: 
      - ./:/AVB
    working_dir: /AVB/AVB
    command: mvn clean test -DargLine="-Dkarate.env=qa"

dockerfile

FROM maven:latest
COPY /AVB/pom.xml /pom.xml
RUN mvn dependency:resolve
RUN mvn clean test

I build the above dockerfile and pushed it to the image being used in the docker-compose

But the best solution here is
https://github.com/intuit/karate/issues/396#issuecomment-399399126

Hi @ptrthomas

We integrated the project in CI(bamboo) using dockers
I'll be looking at Docker again but here is what I have done

  1. Created docker image with all dependencies
  2. Pushed to registry
  3. Executed Docker image in CI (Individual projects can choose to execute their specific tests via Tags)

Dockerfile :

FROM maven:3-jdk-8-alpine

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


# selectively add the POM file
ADD pom.xml /usr/src/app/
# get all the downloads out of the way
RUN mvn verify clean --fail-never


ADD . /usr/src/app
ADD ./src/test/java/karate-config.js.example /usr/src/app/src/test/java/karate-config.js

Execution of Tests in CI


docker run --volume ${bamboo.working.directory}/reports:/usr/src/app/target --workdir /usr/src/app --rm mypersonal-Registry/bdd-api:latest mvn test -Dcucumber.options="--tags @MyTags"

Reports available in path ${bamboo.working.directory}/reports after execution.

Let me know if this is something in lines of your thoughts.

I tried building a docker image using this suggestion and when I try to run it, it downloads all the dependencies again.
Here is my docker file:
FROM maven AS base
ADD pom.xml ./
ADD ./src ./
RUN mvn verify clean --fail-never

and then I run docker run mvn test.
Am I missing something?

Seems, it is downloading plugins only. Got rid of unnecessary plugins and it is running well now.

moving to project roadmap board: https://github.com/intuit/karate/projects/3#card-22529343

Was this page helpful?
0 / 5 - 0 ratings