Executing Rake tests within Docker

Answered

Our existing Rails application is being ported to run inside of Docker. On TeamCity, we see the following message coming out of the Command Line build step where we invoke `docker run [...] rake test`:

"RubyMine reporter works only if it test was launched using RubyMine IDE or TeamCity CI server"

This message appears in the build log immediately before the default reporter kicks in. While the tests do execute, the results are opaque to TeamCity - it doesn't understand how many tests ran, passed, etc. Looking at the source of MiniTest's RubyMineReporter, it seems like the LoadErrors that are causing this could be addressed if we were to expose the contents of plugins/rake-runner/rb to Docker, but it isn't clear that would be sufficient - it looks like sm_factory_provider_loader.rb might need to be sourced for example.

Is there an existing reference implementation that yields the benefits conveyed by the TeamCity RakeRunner (as we experience it from traditional Rake build steps) when the Ruby environment itself is within a Docker container? If not, what's required to get the RubyMineReporter to act like it normally would from a Rake build step?

2 comments
Official comment

Hi Jason,

Sorry for late answer.

AFAIK, You only need to patch RUBYLIB with path to 'plugins/rake-runner/rb/patch/common'. That would be enough for MiniTest reporter.

> Is there an existing reference implementation that yields the benefits conveyed by the TeamCity RakeRunner (as we experience it from traditional Rake build steps) when the Ruby environment itself is within a Docker container? 

I'm unaware about such implementations.

>If not, what's required to get the RubyMineReporter to act like it normally would from a Rake build step?

Rake-runner wraps rake call with special rb file (runner/rakerunner.rb) to ensure rake steps would be presented hierarchically in build log. Also it patches RUBYLIB a bit. 

 

Could you please provide simple example of project and Dockerfile? I'd try to test that with rake runner.

Also have you tried https://github.com/jonnyzzz/TeamCity.Virtual plugin?

I was aware of the plugin but hadn't tried it yet. I'll take a look.

Before we saw your post, we tried exposing the plugin directory into docker in a directory relative to the application and got what we think we wanted without manipulating the RUBYLIB environment variable:

run --rm --net=host -v %system.agent.work.dir%/log:/var/app/current/log -v %system.agent.home.dir%/plugins/rake-runner/rb/patch/common/teamcity:/var/app/current/lib/teamcity -e TESTOPTS=-v -e RAILS_ENV=test xyz/app:%teamcity.build.branch% rake test:units
0

Please sign in to leave a comment.