{"id":21745185,"url":"https://github.com/zuazo/docker-in-travis","last_synced_at":"2025-04-13T05:12:31.762Z","repository":{"id":34729027,"uuid":"38706943","full_name":"zuazo/docker-in-travis","owner":"zuazo","description":"Docker image example using TDD with Serverspec and Travis CI.","archived":false,"fork":false,"pushed_at":"2015-12-12T10:36:30.000Z","size":22,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T22:05:26.703Z","etag":null,"topics":["devops","docker","example","serverspec","spec","tdd","testing","travis-ci"],"latest_commit_sha":null,"homepage":"https://hub.docker.com/r/zuazo/docker-in-travis/","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zuazo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-07T18:29:56.000Z","updated_at":"2019-03-15T05:47:03.000Z","dependencies_parsed_at":"2022-09-14T18:20:26.261Z","dependency_job_id":null,"html_url":"https://github.com/zuazo/docker-in-travis","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zuazo%2Fdocker-in-travis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zuazo%2Fdocker-in-travis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zuazo%2Fdocker-in-travis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zuazo%2Fdocker-in-travis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zuazo","download_url":"https://codeload.github.com/zuazo/docker-in-travis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248665744,"owners_count":21142123,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["devops","docker","example","serverspec","spec","tdd","testing","travis-ci"],"created_at":"2024-11-26T07:13:52.712Z","updated_at":"2025-04-13T05:12:31.737Z","avatar_url":"https://github.com/zuazo.png","language":"Ruby","readme":"### Important Note\n\nThe procedure described below is considered outdated. From now on, I recommend using the [`dockerspec`](https://github.com/zuazo/dockerspec) gem for testing docker images.\n\n---\n\n### Docker Tests Example\n[![Source Code](https://img.shields.io/badge/source-GitHub-blue.svg?style=flat)](https://github.com/zuazo/docker-in-travis) [![Docker Repository on Quay.io](https://quay.io/repository/zuazo/docker-in-travis/status \"Docker Repository on Quay.io\")](https://quay.io/repository/zuazo/tests-example) [![Build Status](http://img.shields.io/travis/zuazo/docker-in-travis.svg?style=flat)](https://travis-ci.org/zuazo/docker-in-travis)\n\nDocker image example using [TDD](https://en.wikipedia.org/wiki/Test-driven_development).\n\nThe tests are implemented in **Ruby**, using the [`docker-api`](https://github.com/swipely/docker-api) and [`serverspec`](http://serverspec.org/) gems.\n\nThe following features are currently implemented:\n\n* [Test the built image](https://github.com/zuazo/docker-in-travis/tree/master/spec/build/dockerfile_spec.rb) using [`docker-api`](https://github.com/swipely/docker-api).\n* [Test the image running](https://github.com/zuazo/docker-in-travis/tree/master/spec/run/dockerfile_spec.rb) using [Serverspec](http://serverspec.org/).\n* Run the tests inside [Travis CI](https://travis-ci.org). See the [.travis.yml](https://github.com/zuazo/docker-in-travis/blob/master/.travis.yml) file.\n* Check the tests with [`should_not`](https://github.com/should-not/should_not) gem to avoid redundant test descriptions.\n* Run the tests in random order.\n\n**Note:** This example installs a simple Apache \u0026 PHP application, but could be anything else.\n\n#### Run the Tests\n\nYou can use the [`bundler`](http://bundler.io/) Ruby gem to install all the requirements to run the tests:\n\n    $ gem install bundler\n    $ bundle install\n\nYou can now run the tests running RSpec:\n\n    $ rspec\n\nOutput example:\n\n```\nRandomized with seed 52614\n\nDocker image run\n  installs PHP version 5.6\n  returns my web page\n  Process \"apache2\"\n    should be running\n  File \"/var/www/html/index.php\"\n    should be file\n  Package \"apache2\"\n    should be installed\n\nDockerfile build\n  has the website path as workdir\n  has PHP installed\n  creates image\n  runs apache in foreground\n  exposes the port 80\n\nFinished in 1.26 seconds (files took 0.20144 seconds to load)\n10 examples, 0 failures\n\nRandomized with seed 52614\n```\n\nSee also the [Travis CI output](https://travis-ci.org/zuazo/docker-in-travis) as an example.\n\n#### Directory Structure\n\n```\n├── Dockerfile\n├── .dockerignore: Files to be ignored by docker copy instructions.\n├── Gemfile: File to install the gems required to run the tests.\n├── .gitignore: Intentionally untracked files to be ignored by git.\n├── LICENSE: Software license.\n├── README.md\n├── spec/\n│   ├── build/: Tests to verify the built image.\n│   ├── run/: Tests to verify the image running (Serverspec).\n│   ├── serverspec_helper.rb: Helper file to setup Serverspec.\n│   └── spec_helper.rb: Helper file to setup all the tests.\n├── .travis.yml: Travis CI configuration file.\n└── webapp/: Example application to install.\n```\n\n#### How to Run Docker in Travis CI\n\nYou can use a *.travis.yml* similar to the following:\n\n```yaml\nlanguage: ruby\n\nsudo: true\n\nbefore_script:\n- source \u003c(curl -sL https://raw.githubusercontent.com/zuazo/docker-in-travis/0.2.0/scripts/start_docker.sh)\n\nscript:\n- bundle exec rspec\n\nafter_failure: cat docker_daemon.log\n```\n\n##### Using the Official Travis CI Docker Stacks\n\n[Since August 2015](http://blog.travis-ci.com/2015-08-19-using-docker-on-travis-ci/) you can try to use the official Docker service provided by Travis CI workers using the following *.travis.yml*:\n\n```yaml\nlanguage: ruby\n\nsudo: required\n\nservices:\n- docker\n\nscript:\n- bundle exec rspec\n```\n\nPlease, [let me know](https://github.com/zuazo/docker-in-travis/issues/new?title=Travis%20Docker%20worked%20for%20me) if this has worked for you.\n\n#### Change *Dockerfile* Location\n\nYou can set the `DOCKERFILE_LOCATION` environment variable to change the *Dockerfile* subdirectory (defaults to `.`).\n\nFor example, to run multiple tests:\n\n```yaml\nlanguage: ruby\n\nsudo: true\n\nenv:\n- DOCKERFILE_LOCATION=directory1\n- DOCKERFILE_LOCATION=directory2\n\nbefore_script:\n- source \u003c(curl -sL https://raw.githubusercontent.com/zuazo/docker-in-travis/0.2.0/scripts/start_docker.sh)\n\nscript:\n- bundle exec rspec\n\nafter_failure: cat docker_daemon.log\n```\n\n#### Real-world Examples\n\n* [chef-local](https://github.com/zuazo/chef-local-docker/tree/ff79f619f76a5a50052db76132ea16b39915caa7) image ([*.travis.yml*](https://github.com/zuazo/chef-local-docker/tree/ff79f619f76a5a50052db76132ea16b39915caa7/.travis.yml), [*spec/*](https://github.com/zuazo/chef-local-docker/tree/ff79f619f76a5a50052db76132ea16b39915caa7/spec), [*Gemfile*](https://github.com/zuazo/chef-local-docker/tree/ff79f619f76a5a50052db76132ea16b39915caa7/Gemfile)): Runs a Travis CI build for each image tag.\n\n* [keywhiz](https://github.com/zuazo/keywhiz-docker/tree/a15def5e83de765e6881bd4305f06fc0a9d4f9c1) image ([*.travis.yml*](https://github.com/zuazo/keywhiz-docker/tree/a15def5e83de765e6881bd4305f06fc0a9d4f9c1/.travis.yml), [*spec/*](https://github.com/zuazo/keywhiz-docker/tree/a15def5e83de765e6881bd4305f06fc0a9d4f9c1/spec), [*Gemfile*](https://github.com/zuazo/keywhiz-docker/tree/a15def5e83de765e6881bd4305f06fc0a9d4f9c1/Gemfile)): Runs one Travis CI build.\n\n#### Questions and Improvements\n\nThis is proof of concept used by myself in my projects. If you encounter any problems or have ideas for improvements, please [open an issue](https://github.com/zuazo/docker-in-travis/issues/new)!\n\n#### Acknowledgements\n\nThis docker example does not contain anything new. It is based on multiple online sources. Mainly the following:\n\n* https://github.com/tcnksm-sample/test-driven-development-dockerfile\n* https://coderwall.com/p/5xylsg/tdd-for-dockerfile-by-rspec-severspec\n* https://github.com/voidlock/travis-docker\n* https://gist.github.com/masonforest/194e0cb6bb16c88e21a0\n* https://robots.thoughtbot.com/tdd-your-dockerfiles-with-rspec-and-serverspec\n* https://github.com/lukecyca/travis-docker-example\n* https://github.com/mdarse/travis-docker-build\n* https://github.com/d11wtq/dockerpty/blob/master/.travis.yml\n* https://github.com/gap-system/gap-docker-travis\n* https://github.com/rocker-org/rocker/blob/56cb59cc262e9d2c02f9e11cfacab65f0b659c5f/.travis.yml\n\nThanks to all of you ;-)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzuazo%2Fdocker-in-travis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzuazo%2Fdocker-in-travis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzuazo%2Fdocker-in-travis/lists"}