Giter Club home page Giter Club logo

autochecker's Introduction

autochecker

autochecker tests your libraries in many different versions of NodeJS, Ruby, Java and many other languages.

Created to make it easier and effortless to make sure your library works in many versions of a language runtime.

Works well with CI as well! (See some example output)

(Works out of the box with NodeJS projects right now, more in the future!)

Demonstration of functionality

Requirements

  • Docker -> install here
  • package.json scripts.test setup correctly (for NodeJS projects)
  • Two environment variables, DOCKER_HOST and DOCKER_CERT_PATH (comes by default with docker-machine)

DOCKER_HOST should look similar to this: tcp://192.168.99.100:2376

DOCKER_CERT_PATH should look similar to this: /Users/victor/.docker/machine/machines/default

Installation

As always, one step:

  • For one project > npm install autochecker

  • Globally on your computer OR to use with other languages > npm install -g autochecker

For extra style points, make sure autochecker is run before publishing your modules:

In package.json:

"scripts": {
	"prepublish": "autochecker 0.10 0.12 4.0 5.0"
}

Running NodeJS project out of the box

By default, executing autochecker will run the tests on all available versions.

You can specify which versions you want to test by adding them in the end of the command:

autochecker 0.10 0.11 4 5.10.1

Versions comes from the mhart/alpine-node docker image tags

Running with other languages

To see how you can run autochecker with a Ruby project + CI integration, please take a look at this repository: https://github.com/VictorBjelkholm/ruby-autochecker-example/

Otherwise, there is a couple of examples of other languages in the /examples directory

Setting max running tests

By default, autochecker starts as many testing sessions as os.cpu().length would return.

However, you can overwrite this by providing the TEST_LIMIT environment variable.

Example: TEST_LIMIT=10 autochecker to run 10 test sessions at a time

Custom Dockerfile template

You can specify custom Dockerfile template if you need additional tools installed, for example if you need git, create a file in the project DockerTemplate with the following

FROM mhart/alpine-node:$VERSION
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json .
# Adding extra tools
RUN apk add --update git
RUN npm install
COPY . .
CMD npm test

Variable $VERSION will be replaced by autochecker. More information about alpine images and additional tools at docker-alpine and alpine-node.

Aside from adding libraries to the container, the custom template can be useful to avoid running postinstall hooks. Just use RUN npm install --ignore-scripts instead.

Programmatic API

You can use autochecker in your own projects from NodeJS directly.

var autochecker = require('autochecker')
const Docker = require('dockerode')
var dockerode_instance = new Docker({socketPath: '/var/run/docker.sock'});
autochecker.runTestForVersion({
  logger: (msg) => { console.log(msg) },
  docker: dockerode_instance,
  version: '1.1.1', // version of project
  name: 'myproject', // name of project
  test_cmd: ['npm', 'test'], // command to run tests with
  image_name: 'app/image:commit', // What the built application image will be called
  path: join(__dirname, 'path_to_project'), // Path to project to build
  dockerfile: 'FROM nodejs:$VERSION', // Dockerfile
  base_image: 'base/image', // Base image, will add :$VERSION to the end
  verbose: false // To show full output or not
})((err, results) => {
  console.log(results)
  // => {version: '1.1.1', success: true || false, output: 'output from test_cmd'}
})

See cli.js for usage with testing multiple versions at once.

Changelog

You can find a list of all versions and changes in the CHANGELOG.md file

License

MIT License 2016 - Victor Bjelkholm

autochecker's People

Contributors

bahmutov avatar dawsbot avatar divan avatar maximization avatar victorb avatar zhuangya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autochecker's Issues

Cannot read property 'StatusCode' of null

Tried running autochecker on an older node project to see if tests pass on newer versions. Ran into this problem:

autochecker Running tests in 32 different NodeJS versions
0.10.41 - building image
0.10.42 - building image
0.10.43 - building image
0.10.44 - running container
0.12.9  - building image
0.12.10 - building image
0.12.11 - building image
0.12.12 - building image

/usr/local/lib/node_modules/autochecker/index.js:122
      var to_resolve = {success: data.StatusCode === 0}
                                     ^

TypeError: Cannot read property 'StatusCode' of null
    at /usr/local/lib/node_modules/autochecker/index.js:122:38
    at handler (/usr/local/lib/node_modules/autochecker/node_modules/dockerode/lib/docker.js:541:21)
    at /usr/local/lib/node_modules/autochecker/node_modules/dockerode/lib/docker.js:37:21
    at /usr/local/lib/node_modules/autochecker/node_modules/docker-modem/lib/modem.js:235:7
    at getCause (/usr/local/lib/node_modules/autochecker/node_modules/docker-modem/lib/modem.js:257:7)
    at Modem.buildPayload (/usr/local/lib/node_modules/autochecker/node_modules/docker-modem/lib/modem.js:228:5)
    at IncomingMessage.<anonymous> (/usr/local/lib/node_modules/autochecker/node_modules/docker-modem/lib/modem.js:204:14)
    at emitNone (events.js:72:20)
    at IncomingMessage.emit (events.js:166:7)
    at endReadableNT (_stream_readable.js:905:12)
$ docker version 
Client:
 Version:      1.10.3
 API version:  1.22
 Go version:   go1.6
 Git commit:   20f81dd
 Built:        Sat Mar 12 04:07:44 UTC 2016
 OS/Arch:      darwin/amd64

Server:
 Version:      1.10.3
 API version:  1.22
 Go version:   go1.5.3
 Git commit:   20f81dd
 Built:        Thu Mar 10 21:49:11 2016
 OS/Arch:      linux/amd64

Separate CLI and testing utilities

Everything is in one big file currently, index.js. Let's split them into at least two different modules, one for CLI and one for the library functions, so it can be included elsewhere

Troubleshooting: 404 no such container - No such image

I ran $ autochecker 0.10.41 4.4.2 but the error message is somewhat misleading.

What does that mean? How to fix?

[1;1H[0Jautochecker Running tests in 2 different sessions
[2;1H[0J[2;1H0.10.41    - copying files
[2;1H[0J[2;1H0.10.41    - writing dockerfile
[2;1H[0J[2;1H0.10.41    - pulling image
[2;1H[0J[2;1H0.10.41    - building image
[2;1H[0J[2;1H0.10.41    - running container
Something went wrong when running the tests...
Error: HTTP code is 404 which indicates error: no such container - No such image: myprojectname_0.10.41:442f40bcf41634bc2479da52c42debc70ae3b12a

UPD: also, looks like the exit code was 0 (success).

Feature request: specify your own docker base-image

I love Alpine, but if anything in node_modules needs rebuilt, you will have to figure out what apk to add. Would be awesome to be able to specify your own base image (and repo) pull in package.json:

...
"autochecker": {
  "repo-host": "https://quay.io",
  "base-image": "someuser/nodejs"
}
...

awesome project btw!

Build Docker image from current directory

I have a rather large project directory due to lots of build products, which means all of those are copied into the temporary directory by copyApplicationToTempLocation(). At first glance it appears this only exists such that it excludes .git and node_modules directories by default. There's a TODO in there for this to be more language independent, so I think the best path forward is to encourage users to create their own .dockerignore file, perhaps suggesting to generate one by default if one does not yet exist.

The Dockerfile built from the template could be put into a temp file since Docker supports specifying alternative files to build from.

Proper cleanup

Right now, autochecker doesn't clean up after itself when it finishes running all the tests.

  • os.tmpdir() contains one copy per nodejs version and commit version of the project.
  • Docker containers are also not cleaned up.

Make it language agnostic

If there is a easy way of detecting which language a project is using, try to detect it and then running the common commands.

Otherwise, use the Dockerfile and the declared CMD.

Fallback to being a NodeJS project.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.