EvoSuite / evosuite

EvoSuite - automated generation of JUnit test suites for Java classes
http://www.evosuite.org
GNU Lesser General Public License v3.0
832 stars 341 forks source link

Add Dockerfile to evosuite project #294

Closed mitchellolsthoorn closed 4 years ago

mitchellolsthoorn commented 4 years ago

By adding a dockerfile it makes running evosuite easier on all different kinds of platforms by handling the dependencies and Java versions for you.

jose commented 4 years ago

Hi @mitchellolsthoorn,

Thanks for your contribution to the EvoSuite project. Could you please provide some documentation, example, etc., on how to use this?

-- Best, Jose

mitchellolsthoorn commented 4 years ago

Dear Jose,

This Dockerfile can either by manually built on someones local computer by doing:

git clone https://github.com/EvoSuite/evosuite.git
cd evosuite
docker build . --tag evosuite:latest

Or it can be automatically built by Docker Hub if this GitHub repo is connected to their service. When this method is chosen, users can download the image by doing:

docker pull evosuite

To use the image:

mkdir -p test-project
<copy project-under-test to test-project>
docker run -d --rm -v <absolute path to test-project directory>:/home/evosuite/results evosuite:latest <evosuite arguments>

Evosuite will put the results in the test-project directory.

Do you want me to add this to the README?

Mitchell

gofraser commented 4 years ago

Thanks for adding the dockerfile, Mitchell. Since you already summarised it so nicely, you might as well add it to the README please?

Two questions: 1) Will we have to update the Dockerfile with each release, or is there some way to encode the current version in there? 2) We've recently added support for Java > 8. While this is recent and I think sticking to Java 8 in the Dockerfile makes sense I was wondering what the recommended way is to deal with differing Java versions. Would there be multiple different dockerfiles, or do we always have to specify one "officially recommended" Java version?

mitchellolsthoorn commented 4 years ago

@gofraser Sorry for the slow response. Last week was quite hectic.

I have updated my branch to make the container more optimized and more user friendly. I have also added some information to the README.md. What do you think?

Regarding your questions:

  1. I have added some extra logic to the container to make the build process version-independent. So it shouldn't require changes for a version update.
  2. For each different version of Java, you would need a separate Dockerfile. Projects with many different build configurations will often move their Dockerfiles in a separate repo, but I wouldn't recommend that for this project. I have updated the branch to now have two Dockerfiles: one for java8 and one for java11

I would recommend creating a Docker Hub organization account that connects to GitHub with a service account (GitHub account specific for this purpose). This is the recommended way to set up automated builds for organizations.

When this is done, you would be able to configure automated builds to create versions based on git tags and branches for each java version. With rules, you could configure the following images:

Version Description
latest latest version of the master with either java8 or java11. This is the default version when none is specified.
x-java-y latest version of the major version x with java version y
x.x-java-y latest version of the major and minor version x.x with java version y
x.x.x-java-y specific version of EvoSuite with version x.x.x with java version y
The rules would look like follows: Type Name Dockerfile Location Docker Tag Name
Branch master /Dockerfile.java8 latest
Tag /^v([0-9]+).([0-9]+).([0-9]+)$/ /Dockerfile.java8 {\1}-java-8
Tag /^v([0-9]+).([0-9]+).([0-9]+)$/ /Dockerfile.java8 {\1}.{\2}-java-8
Tag /^v([0-9]+).([0-9]+).([0-9]+)$/ /Dockerfile.java8 {\1}.{\2}.{\3}-java-8
Tag /^v([0-9]+).([0-9]+).([0-9]+)$/ /Dockerfile.java11 {\1}-java-11
Tag /^v([0-9]+).([0-9]+).([0-9]+)$/ /Dockerfile.java11 {\1}.{\2}-java-11
Tag /^v([0-9]+).([0-9]+).([0-9]+)$/ /Dockerfile.java11 {\1}.{\2}.{\3}-java-11

You can, of course, change the naming structure

mitchellolsthoorn commented 4 years ago

What do you think of the version naming and the Docker Hub organization naming? Should these be changed or are they fine?

gofraser commented 4 years ago

The naming is perfectly fine. Does that mean I should create a Docker Hub organization with that name? (Sorry, haven't got much clue about Docker)

apanichella commented 4 years ago

@gofraser yes, that would be the case. I can take care of DockerHub if you prefer.

mitchellolsthoorn commented 4 years ago

The Docker Hub organization name is only linked in the README.md so it is easy to change if you want to use something else. Docker Hub is the registry where all publicly hosted container images are located. The account structure is very similar to GitHub. To create an organization you first need to have a normal Docker Hub account then you can add that account to an organization so multiple people can have edit rights. One thing to note is that the free version only allows 3 people to have edit rights.

gofraser commented 4 years ago

Thanks - sure, the less I have to do, the better for me, @apanichella :-)

apanichella commented 4 years ago

The docker images are online in DockerHub: https://hub.docker.com/r/evosuite/evosuite @mitchellolsthoorn helped me out setting it up. @gofraser I think all looks in order for the pull request

mitchellolsthoorn commented 4 years ago

There is also a badge if you want to add this to the readme: docker-hub-badge

![docker-hub-badge](https://img.shields.io/docker/pulls/evosuite/evosuite.svg)

gofraser commented 4 years ago

Great, thanks!