- Install ruby (if you don't already have it)
- Install bundler and rspec
$gem install bundle
$gem install rspec
- create a Gemfile in the root of the directory with the following dependencies: 'serverspec', 'docker-api'
- set up a basic npm repository
$npm init
You can just agree to all the defaults - install express as a dependency
$npm install --save express
- write up a trivial node server that responds to get requests
- you can run this server locally now
$ node server.js
- create a new spec folder and add set up building the docker image and run a test that should normally pass
- run your tests with
$rspec spec/
... - and watch it fail
- since we're deploying a node server, lets use an ubuntu image from dockerhub, but honestly almost any linux distribution would work.
- re-run the tests and notice that our original test is GREEN!!!!
- Lets test that we have our node dependency by adding a test that expects node to be installed
- Now that we have a failing test we need to figure out how to install node onto this box. There are thousands of resources online, but we can actually drive this ourself =>
First build the image
$ docker build . -t tdd
Then exec into itdocker run -it --entrypoint=/bin/bash tdd
- First of all, lets make a test that will check if something is listening on a certain port. For resources available to serverspec, check out the documentation on resource types: http://serverspec.org/resource_types.html
- Now that we have a failing test, lets make it pass by installing our dependencies and running our app.
- That Ubuntu image is TOO heavy, it has a whole bunch of things we dont need, and it takes a long time to download. I want to use a new docker base image to run this correctly.