Skip to content

nanliu/docker-serverspec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

docker-serverspec

Build Status Image Layers

Docker container to run serverspec via Docker-in-Docker.

Usage

Docker-ception in action:

$ docker pull nanliu/serverspec:alpine
$ docker run -v /var/run/docker.sock:/var/run/docker.sock \
  -it nanliu/serverspec:alpine /bin/sh

You should see all running containers in the serverspec container and all your docker images

# docker ps
CONTAINER ID        IMAGE                             COMMAND                  CREATED             STATUS              PORTS               NAMES
405492d2c3fa        nanliu/serverspec:alpine   "docker-entrypoint.sh"   8 seconds ago       Up 7 seconds                            vibrant_wright
# docker images
...
# exit

Run a serverspec test:

$ git clone https://github.com/nanliu/docker-serverspec.git
$ cd docker-serverspec
$ docker run -v /var/run/docker.sock:/var/run/docker.sock \
  -v "$(pwd)":/serverspec \
  -it nanliu/serverspec:alpine /bin/sh -c "cd /serverspec && rspec snap_spec.rb"

Run a serverspec test with pry rescue:

$ cd docker-serverspec
$ docker run -v /var/run/docker.sock:/var/run/docker.sock \
  -v "$(pwd)":/serverspec \
  -it nanliu/serverspec:alpine /bin/sh -c "cd /serverspec && rescue rspec snap_spec.rb"

Writing the Test

Docker Metadata

MAINTAINER your name <your@email.com>

Serverspec

COPY snapteld.conf /etc/snapteld.conf

this will cause the symlink tests to fail

[ -f /etc/snap/snapd.conf ] || ln -s /etc/snapteld.conf /etc/snap/snapd.conf

Run containers

  • Change the 'snap_spec.rb' to run the snap container directly instead of building it first.

hint:

describe docker_run('intelsdi/snap:alpine')
  #test
end

Custom Test

  • Create mysql_spec.rb to test the dockerfile in mysql directory.

hint:

  • create mysql_spec.rb
$ vim mysql_spec.rb
describe docker_build('/serverspec/mysql/.')
  describe docker_run(described_image) do
    #test
  end
end
  • Test your spec:
$ cd docker-serverspec
$ docker run -v /var/run/docker.sock:/var/run/docker.sock \
  -v "$(pwd)":/serverspec \
  -it nanliu/serverspec:alpine /bin/sh -c "cd /serverspec && rspec mysql_spec.rb"

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published