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
$ fig 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. If you're running linux natively then just install Docker and Fig natively.
Follow the instructions to install Boot2Docker and then install Fig
If you're on Windows, or can't get docker installed on your platform, we've provided a Vagrant setup that you can use. Install Virtualbox >= 4.3.20 as well as Vagrant >= 1.6.5 for your platform. Then get up and running:
$ vagrant up
$ vagrant provision
Once up and running, you'll run the fig commands from inside the vagrant image:
$ vagrant ssh
vagrant@vagrant:~$ cd docker-bdd
vagrant@vagrant:~/docker-bdd$ fig build
vagrant@vagrant:~/docker-bdd$ fig up -d
vagrant@vagrant:~/docker-bdd$ cucumber
On subsequent runs, since there won't be huge downloads, you can just run:
$ vagrant ssh
vagrant@vagrant:~$ cd docker-bdd
vagrant@vagrant:~/docker-bdd$ cucumber
In addition to installing docker and fig, 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 fig 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 coffeen 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:
$ fig run -d
Again, running the tests accomplishes this, but if you want to do it manually:
$ fig build
We've set up the dev
service to also serve as a development
environment, wher eyou 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.
$ fig run dev
This is a really nice feature of fig, providing a combined output from all the running services.
$ fig logs
This will show logs as they come in. Use Ctrl+C to quit.
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 fig
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
fig_steps.rb to just
sleep for 10 seconds after running
fig 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
fig_steps.rb to just
sleep for 10 seconds after running
- Thanks to the great work being done on Docker and Fig!