{"id":20444123,"url":"https://github.com/tknerr/docker-seminar-tdi","last_synced_at":"2025-06-10T09:35:22.259Z","repository":{"id":31587510,"uuid":"35152310","full_name":"tknerr/docker-seminar-tdi","owner":"tknerr","description":"Demo code for my \"Test-Driven Infrastructure with Docker, ServerSpec and KitchenCI\" talk here http://slides.com/tknerr/tdi-with-kitchenci-and-docker/live#/","archived":false,"fork":false,"pushed_at":"2015-05-06T13:02:45.000Z","size":128,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-05T08:26:57.403Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tknerr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-06T09:58:41.000Z","updated_at":"2015-05-06T13:02:45.000Z","dependencies_parsed_at":"2022-09-09T20:52:23.409Z","dependency_job_id":null,"html_url":"https://github.com/tknerr/docker-seminar-tdi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tknerr%2Fdocker-seminar-tdi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tknerr%2Fdocker-seminar-tdi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tknerr%2Fdocker-seminar-tdi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tknerr%2Fdocker-seminar-tdi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tknerr","download_url":"https://codeload.github.com/tknerr/docker-seminar-tdi/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tknerr%2Fdocker-seminar-tdi/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259048760,"owners_count":22797794,"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":[],"created_at":"2024-11-15T09:51:22.738Z","updated_at":"2025-06-10T09:35:22.224Z","avatar_url":"https://github.com/tknerr.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Sample Repo for the Docker Seminar\n\nCode repository for my HL docker seminar talk about [Test-Driven Infrastructure with Docker, ServerSpec and KitchenCI](http://slides.com/tknerr/tdi-with-kitchenci-and-docker/live#/)\n\nBelow are the steps from the \"Demo Time!\" part for you to follow. For the demo I used the [Bill's Kitchen DevPack](https://github.com/tknerr/bills-kitchen) which includes Docker 1.6.0 (with boot2docker) and KitchenCI 1.4.0.\n\n## Generate the motd Cookbook\n\nLet's create a sample \"motd\" cookbook:\n```\nchef generate cookbook motd\ncd motd\n```\n\n## Run the (not yet existing) Tests\n\nWithout further ado, we can already run some tests:\n\n * `foodcritic .` - to run chef linting checks\n * `rspec` - to run ChefSpec unit tests\n * `kitchen test` - to run integration tests\n\nRunning `kitchen test` with VirtualBox is quite slow:\n```\nW:\\repo\\docker-seminar-tdi\\motd\u003ekitchen test 1204\n-----\u003e Starting Kitchen (v1.4.0)\n-----\u003e Cleaning up any prior instances of \u003cdefault-ubuntu-1204\u003e\n-----\u003e Destroying \u003cdefault-ubuntu-1204\u003e...\n       Finished destroying \u003cdefault-ubuntu-1204\u003e (0m0.00s).\n-----\u003e Testing \u003cdefault-ubuntu-1204\u003e\n-----\u003e Creating \u003cdefault-ubuntu-1204\u003e...\n       Bringing machine 'default' up with 'virtualbox' provider...\n       ==\u003e default: Importing base box 'opscode-ubuntu-12.04'...\n\n...\n\nFinished destroying \u003cdefault-ubuntu-1204\u003e (0m8.01s).\nFinished testing \u003cdefault-ubuntu-1204\u003e (1m31.10s).\n-----\u003e Kitchen is finished. (1m33.65s)\n```\n\n\n## Let's get faster by using Docker!\n\nSince running `kitchen test` with VirtualBox is sloooooooooooow, so let's fix that\nby creating a `.kitchen.docker.yml` file with the necessary overrides for the\ndocker provisioner:\n\n```yml\n---\ndriver:\n  name: docker\n\ndriver_config:\n  provision_command:\n    - curl -L https://www.opscode.com/chef/install.sh | bash -s -- -v 12.3.0\n  require_chef_omnibus: false\n  use_sudo: false\n```\n\nNote that we installed the omnibus chef client via `provision_command`, which\nbasically adds a `RUN` entry in the Dockerfile and thus we get it cached in\na docker layer :-)\n\nIn order to use it, you have to `set KITCHEN_LOCAL_YAML=.kitchen.docker.yml`\nand then run `kitchen test` again.\n\nWeeeeeeeeee, much faster, and we can even run it in parallel via `kitchen test -c` now! :-)\n```\nW:\\repo\\docker-seminar-tdi\\motd\u003ekitchen test -c\n-----\u003e Starting Kitchen (v1.4.0)\n-----\u003e Cleaning up any prior instances of \u003cdefault-ubuntu-1204\u003e\n-----\u003e Cleaning up any prior instances of \u003cdefault-centos-65\u003e\n-----\u003e Destroying \u003cdefault-ubuntu-1204\u003e...\n-----\u003e Destroying \u003cdefault-centos-65\u003e...\n       Finished destroying \u003cdefault-ubuntu-1204\u003e (0m0.00s).\n       Finished destroying \u003cdefault-centos-65\u003e (0m0.00s).\n-----\u003e Testing \u003cdefault-ubuntu-1204\u003e\n-----\u003e Testing \u003cdefault-centos-65\u003e\n-----\u003e Creating \u003cdefault-ubuntu-1204\u003e...\n-----\u003e Creating \u003cdefault-centos-65\u003e...\n\n...\n\nFinished testing \u003cdefault-ubuntu-1204\u003e (0m17.68s).\nFinished testing \u003cdefault-centos-65\u003e (0m23.27s).\n-----\u003e Kitchen is finished. (0m25.49s)\n```\n\n## Describe what we expect in a Test\n\nHah, let's approach it in a test-first manner :-)\n\nSo we can describe the expected state in `test/integration/default/serverspec/default_spec.rb`:\n```ruby\nrequire 'spec_helper'\n\ndescribe 'motd::default' do\n\n  # Serverspec examples can be found at\n  # http://serverspec.org/resource_types.html\n\n  describe file('/var/run/motd') do\n    it { should be_file }\n    it { should be_mode 644 }\n    it { should contain \"hellooooo\" }\n  end\nend\n```\n## Run and see it failing\n\nNow run `kitchen verify 1204` to converge the node and see the tests failing:\n```\nW:\\repo\\docker-seminar-tdi\\motd\u003ekitchen verify ubuntu\n-----\u003e Starting Kitchen (v1.4.0)\n-----\u003e Verifying \u003cdefault-ubuntu-1204\u003e...\n$$$$$$ Running legacy verify for 'Docker' Driver\n       Preparing files for transfer\n       Removing /tmp/verifier/suites/serverspec\n       Transferring files to \u003cdefault-ubuntu-1204\u003e\n-----\u003e Running serverspec test suite\n       /opt/chef/embedded/bin/ruby -I/tmp/verifier/suites/serverspec -I/tmp/verifier/gems/gems/rspec-support-3.2.2/lib:/tmp/verifier/gems/gems/rspec-core-3.2.3/lib /opt/chef/embedded/bin/rspec --pattern /tmp/verifier/suites/serverspec/\\*\\*/\\*_spec.rb --color --format documentation --default-path /tmp/verifier/suites/serverspec\n\n       motd::default\n         File \"/var/run/motd\"\n           should be file\n           should be mode 644\n           should contain \"hellooooo\" (FAILED - 1)\n\n       Failures:\n\n         1) motd::default File \"/var/run/motd\" should contain \"hellooooo\"\n            Failure/Error: it { should contain \"hellooooo\" }\n              expected File \"/var/run/motd\" to contain \"hellooooo\"\n              /bin/sh -c grep\\ -qs\\ --\\ hellooooo\\ /var/run/motd\\ \\|\\|\\ grep\\ -qFs\\ --\\ hellooooo\\ /var/run/motd\n\n            # /tmp/verifier/suites/serverspec/default_spec.rb:11:in `block (3 levels) in \u003ctop (required)\u003e'\n\n       Finished in 0.12986 seconds (files took 0.29833 seconds to load)\n       3 examples, 1 failure\n\n       Failed examples:\n\n       rspec /tmp/verifier/suites/serverspec/default_spec.rb:11 # motd::default File \"/var/run/motd\" should contain \"hellooooo\"\n```\n\n\n## Fix the test by placing the motd file\n\nOk, so let's edit `recipes/default.rb` and add a simple motd file:\n```ruby\n#\n# Cookbook Name:: motd\n# Recipe:: default\n#\n# Copyright (c) 2015 The Authors, All Rights Reserved.\n\nfile '/var/run/motd' do\n  content \"hellooooooooooo\"\n  mode \"0644\"\n  action :create\nend\n```\n\nOk, lets see it!\n```\nW:\\repo\\docker-seminar-tdi\\motd\u003ekitchen verify ubuntu\n-----\u003e Starting Kitchen (v1.4.0)\n-----\u003e Verifying \u003cdefault-ubuntu-1204\u003e...\n$$$$$$ Running legacy verify for 'Docker' Driver\n       Preparing files for transfer\n       Removing /tmp/verifier/suites/serverspec\n       Transferring files to \u003cdefault-ubuntu-1204\u003e\n-----\u003e Running serverspec test suite\n       /opt/chef/embedded/bin/ruby -I/tmp/verifier/suites/serverspec -I/tmp/verifier/gems/gems/rspec-support-3.2.2/lib:/tmp/verifier/gems/gems/rspec-core-3.2.3/lib /opt/chef/embedded/bin/rspec --pattern /tmp/verifier/suites/serverspec/\\*\\*/\\*_spec.rb --color --format documentation --default-path /tmp/verifier/suites/serverspec\n\n       motd::default\n         File \"/var/run/motd\"\n           should be file\n           should be mode 644\n           should contain \"hellooooo\"\n\n       Finished in 0.1236 seconds (files took 0.30404 seconds to load)\n       3 examples, 0 failures\n\n       Finished verifying \u003cdefault-ubuntu-1204\u003e (0m1.43s).\n-----\u003e Kitchen is finished. (0m3.66s)\n```\n\nWeeeeee, green tests! :-)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftknerr%2Fdocker-seminar-tdi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftknerr%2Fdocker-seminar-tdi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftknerr%2Fdocker-seminar-tdi/lists"}