Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker images for maven and gradle #396

Closed
ptrthomas opened this issue May 17, 2018 · 16 comments
Closed

docker images for maven and gradle #396

ptrthomas opened this issue May 17, 2018 · 16 comments

Comments

@ptrthomas
Copy link
Member

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

@ptrthomas ptrthomas self-assigned this May 17, 2018
@avyasbms
Copy link

avyasbms commented Jun 6, 2018

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

@ptrthomas
Copy link
Member Author

@avyasbms yes please !

@avyasbms
Copy link

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.

@ptrthomas
Copy link
Member Author

ptrthomas commented Jun 22, 2018

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

@ptrthomas
Copy link
Member Author

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

@sauravkumar05
Copy link

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

@ptrthomas
Copy link
Member Author

@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

@ptrthomas
Copy link
Member Author

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"]

@jawadkalia
Copy link

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
}

@76creates
Copy link

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?

@ptrthomas
Copy link
Member Author

@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.

@jawadkalia
Copy link

jawadkalia commented Jan 3, 2019

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
#396 (comment)

@amazingankur
Copy link

amazingankur commented Mar 4, 2019

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?

@amazingankur
Copy link

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

@ptrthomas
Copy link
Member Author

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

@ptrthomas
Copy link
Member Author

for anyone landing here, a sample minimalistic Docker file and instructions can be found here: https://github.com/karatelabs/karate/wiki/Get-Started:-Other-Runtime-Options#docker-and-the-standalone-jar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants