This repository demonstrates how to use cucumber and behavior-driven development to orchestrate docker containers into a running 3-tiered application. It also can be used to quickly get a rails development environment running for a specific project.
Once you have all the pre-requisites installed, starting up a rails app is as simple as
$ docker-compose up -d
or
$ vagrant up --provision
And then you can visit http://localhost:8080
or
http://localhost:3000
on your host machine to access the website.
But the real power of this setup is that we can develop new docker containers in a test-driven manner.
This is the preferred approach, and supports Linux, Mac, and Windows machines. Install Docker and Docker-Compose.
Previous versions supported using a docker-enabled virtual machine through Vagrant, but now that Docker runs on Mac and Windows, it's no longer necessary and has been removed.
In addition to installing docker and docker-compose, you'll need to have Cucumber installed in order to run the tests.
$ sudo apt-get install cucumber
Or,
-
install ruby (e.g. via rvm or a system package)
-
install cucumber
$ gem install cucumber
The tests ensure that the docker-compose cluster is running, so running them is
as simple as running cucumber
. You can also just run a specific
test:
$ cucumber features/web.feature
If this is your first time running this, then grab a cup of coffee and enjoy a nice 10-15 minute wait, as the base docker images are downloaded, and then custom images are built and run. Subsequent executions will be much faster.
Running the tests also accomplishes this, but if you're too lazy to run the tests:
$ docker-compose run -d
Again, running the tests accomplishes this, but if you want to do it manually:
$ docker-compose build
We've set up the dev
service to also serve as a development
environment, where you can issue commands like rails g scaffold
. Since the files in this environment are the same files that
you have locally, you can edit in your native environment, and use
this environment for doing things like running tests, generating
files, testing out dependencies, etc.
$ docker-compose run dev
This is a really nice feature of docker-compose, providing a combined output from all the running services.
$ docker-compose logs -f
This will show logs as they come in. Use Ctrl+C to quit.
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
- currently ignoring this message
- adding gems to the rails Gemfile is currently convoluted
docker-compose run dev
- add the gem to Gemfile
bundle install
- copy the new
Gemfile
andGemfile.lock
todockerfiles/rails/
- re-build the
rails
container viadocker-compose up -d
or runningcucumber
- the android tests take a long time downloading the gradle dependencies each time
Couldn't connect to Docker daemon at http+unix://var/run/docker.sock - is it running?
- Either add your user to the
docker
group (preferred), or usesudo docker-compose
andsudo cucumber
for the commands.
- Either add your user to the
vagrant up
hangs for me- Try launching the virtual machine via VirtualBox directly to see if there are any errors.
- I'm on a 32-bit system but the virtualbox/docker images are 64-bit
- We tried getting this to work with a 32-bit vagrant image, but ran
into
exec format error
issues. A 32-bit fork of this project would be nice.
- We tried getting this to work with a 32-bit vagrant image, but ran
into
- I see a bunch of errors in the output saying
stdin: is not a tty
- These can safely be ignored, but if you can resolve the issue, please submit a pull request
- I get failures when I run
cucumber
, but when I run the failing commands manually, they pass.- This may be due to the tests running before the server is fully
started. Currently, there's a hack in
docker-compose_steps.rb to just
sleep for 10 seconds after running
docker-compose up
, but this may not be suitable for all environments.
- This may be due to the tests running before the server is fully
started. Currently, there's a hack in
docker-compose_steps.rb to just
sleep for 10 seconds after running
- Thanks to the great work being done on Docker and Docker-Compose!