How do you run the test suite with docker-compose in a Dockerized Rails app?

26 views
Skip to first unread message

Jason Hsu

unread,
Oct 30, 2019, 2:17:59 AM10/30/19
to Ruby on Rails: Talk
I've contributed to the Octobox app (https://github.com/octobox/octobox).  I've been using a weird system of using Docker.  Instead of using it the normal way, I create my own custom Docker image for each Rails project that I'm on.  When I log into my custom Docker container, I basically follow the same procedure that the people who rely on their host environments do.

I'm trying to learn the more conventional way of using Docker with docker-compose, but I'm having difficulty finding out how you're supposed to run the test suite.

I've followed the instructions at https://github.com/octobox/octobox/blob/master/docs/INSTALLATION.md#using-docker-and-docker-compose .  While I've been able to get the development environment working, I have not been able to figure out how I'm supposed to run the test suite with the docker-compose command.  Exactly what is the command for running the test suite?

San Ji

unread,
Oct 30, 2019, 8:25:06 AM10/30/19
to Ruby on Rails: Talk

Jason Hsu

unread,
Oct 30, 2019, 9:59:24 AM10/30/19
to Ruby on Rails: Talk
What's the full command for running the test suite?  Sadly, but this isn't a CS class that one can BS through with partial credit.

On Wednesday, October 30, 2019 at 7:25:06 AM UTC-5, San Ji wrote:
docker-compose run?

https://docs.docker.com/compose/reference/run/

San Ji

unread,
Oct 30, 2019, 10:53:03 AM10/30/19
to Ruby on Rails: Talk
Sad, indeed

Brandon McClelland

unread,
Oct 30, 2019, 11:53:06 AM10/30/19
to rubyonra...@googlegroups.com
You would do something like this (found at https://blog.codeship.com/testing-rails-application-docker/ after googling "running rails test with docker-compose run"):

docker-compose run -e "RAILS_ENV=test" app rake test

On Wed, Oct 30, 2019 at 9:53 AM San Ji <saru...@gmail.com> wrote:
Sad, indeed

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/66aab950-9d5c-41a5-bec0-e88407b73675%40googlegroups.com.


--
Brandon McClelland
User Support Technician
Steve Jackson Games

Jason Hsu

unread,
Oct 30, 2019, 11:57:46 AM10/30/19
to Ruby on Rails: Talk
I thought that would work, but simplecov isn't loading.

Brandon McClelland

unread,
Oct 30, 2019, 12:07:06 PM10/30/19
to rubyonra...@googlegroups.com
You said "When I log into my custom Docker container, I basically follow the same procedure that the people who rely on their host environments do." Can you run the tests successfully that way?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.

Stewart Mckinney

unread,
Oct 30, 2019, 12:15:07 PM10/30/19
to rubyonra...@googlegroups.com
Basically the command after `docker-compose run {{container_name}}` is the exact same command you would enter right after logging into the container.

So if you would log into the container and run "bundle exec rake test", and assuming your container is `app`, you would run:

`docker-compose run web bundle exec rake test`

This is, of course, assuming that you can run tests in the container already.



Jason Hsu

unread,
Oct 30, 2019, 1:08:03 PM10/30/19
to Ruby on Rails: Talk
Yes.  However, I use just one Docker container that contains everything I need, including Ruby, Rails, Node.js, PostgreSQL, Redis, etc.  I know that my way is crude, but it works.  I can't move on to the docker-compose way of doing things until I figure out all the issues that are stopping me.

Walther Diechmann

unread,
Oct 31, 2019, 7:13:23 AM10/31/19
to Ruby
IMHO “.., I use just one Docker container” is the first order of (your) business to get straighten out :)

Using containers with Rails is quite a feast - and an added bonus is that once set up you have next to zero footprint on your ‘own’ computer (that is a blatant lye ‘cause your code base needs to sit somewhere, and the docker images has to be in place too - but even that could be ‘clouded’)

Docker containers doesn’t really start to shining until you let them ;)

That is - delegate delegate delegate - or: one container per “task” 

You’ll have at least three containers spinning - again IMHO. An app container with the Puma webserver serving the Rails stuff, a database container for the Rails models to persist their data, and a container for a reversed NgINX proxy serving clients on 80/443 and forwarding the necessary requests to the ‘animal’ (Puma). Other container candidates are: Redis, Sidekiq, and memcached. Here are the observations by Cloud66 - https://blog.cloud66.com/containers-for-rails-developers-use-containers-while-staying-true-to-your-ror-roots/

Use hub.docker.com to load the necessary images, then use github.com to load the codebase, then 

docker-compose build
docker-compose up (-d if you’d like it to sit in the background=daemonized)

That’s it - more or less

Getting there will take you through one/two hoops I know for sure but it’s worth the journey!


Chris Blunt did an excellent demonstration job!


Cheers,
Walther

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.

Jason Hsu

unread,
Oct 31, 2019, 11:11:33 AM10/31/19
to Ruby on Rails: Talk
Thanks, Walther, on the suggestion of adding a docker container specifically dedicated to running tests.  (I personally don't agree with the use of Guard, so I'd just run the shell and then enter the test commands when necessary.)  Why isn't this normally done?

But exactly what is the docker-compose command for running the test suite on Octobox?  Every time I've tried to run the test suite with a docker-compose command, I get stopped in my tracks by an error message telling me that simplecov isn't loading.  For reasons I haven't been able to figure out, the simplecov gem doesn't get installed when I enter "bundle install" even though it's in the Gemfile and Gemfile.lock.  I even tried starting a Docker container to run an sh shell, and running "bundle install" didn't install the simplecov gem.

Walther Diechmann

unread,
Oct 31, 2019, 11:56:17 AM10/31/19
to Ruby
On the ‘running of shells and entering information manually’ - I guess that defeats the purpose of Docker (which basically is to allow automation and optimise CPUsage :)

On simplecov - tried to do “gem install simplecov” from that docker shell of yours?

Den 31. okt. 2019 kl. 16.11 skrev Jason Hsu <jhsu8...@gmail.com>:

Thanks, Walther, on the suggestion of adding a docker container specifically dedicated to running tests.  (I personally don't agree with the use of Guard, so I'd just run the shell and then enter the test commands when necessary.)  Why isn't this normally done?

But exactly what is the docker-compose command for running the test suite on Octobox?  Every time I've tried to run the test suite with a docker-compose command, I get stopped in my tracks by an error message telling me that simplecov isn't loading.  For reasons I haven't been able to figure out, the simplecov gem doesn't get installed when I enter "bundle install" even though it's in the Gemfile and Gemfile.lock.  I even tried starting a Docker container to run an sh shell, and running "bundle install" didn't install the simplecov gem.

On Thursday, October 31, 2019 at 6:13:23 AM UTC-5, walt wrote:
IMHO “.., I use just one Docker container” is the first order of (your) business to get straighten out :)

Using containers with Rails is quite a feast - and an added bonus is that once set up you have next to zero footprint on your ‘own’ computer (that is a blatant lye ‘cause your code base needs to sit somewhere, and the docker images has to be in place too - but even that could be ‘clouded’)

Docker containers doesn’t really start to shining until you let them ;)

That is - delegate delegate delegate - or: one container per “task” 

You’ll have at least three containers spinning - again IMHO. An app container with the Puma webserver serving the Rails stuff, a database container for the Rails models to persist their data, and a container for a reversed NgINX proxy serving clients on 80/443 and forwarding the necessary requests to the ‘animal’ (Puma). Other container candidates are: Redis, Sidekiq, and memcached. Here are the observations by Cloud66 - ALCO Spamstop har genkendt svig på hjemmesiden "www.google.com". Du gør klogt i ikke at have tiltro til denne hjemmeside: https://blog.cloud66.com/containers-for-rails-developers-use-containers-while-staying-true-to-your-ror-roots/

Use hub.docker.com to load the necessary images, then use github.com to load the codebase, then 

docker-compose build
docker-compose up (-d if you’d like it to sit in the background=daemonized)

That’s it - more or less

Getting there will take you through one/two hoops I know for sure but it’s worth the journey!


Chris Blunt did an excellent demonstration job!

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.

Stewart Mckinney

unread,
Oct 31, 2019, 12:42:57 PM10/31/19
to rubyonra...@googlegroups.com
You also might be running into issues regarding transient layers in Docker; it's *really* not expecting you to log in and run a few scripts to install dependencies.

It's expecting you to do that in your Dockerfile. It's entirely possible simplecov or whatever other gem you are using is simply being discarded when the container shuts down. When a container is started, docker creates a transient layer for the container for things like logs, etc. Anything that isn't in a volume will be erased once the container stops running - it doesn't save that transient layer on container exit.

For a first start, what I might try is this: setup everything in one box like you were before, but this time, do it all from the Dockerfile.

I think you might find that you will have a lot more success that way.

Reply all
Reply to author
Forward
0 new messages