From ccbe6f76206622790385e074906fa719c1b9cff4 Mon Sep 17 00:00:00 2001 From: Sergey Storchay Date: Mon, 23 Mar 2015 16:59:41 +0200 Subject: [PATCH] Initial commit --- .gitignore | 16 ++++ .kitchen.yml | 16 ++++ Berksfile | 3 + CHANGELOG.md | 4 + CONTRIBUTING.md | 31 ++++++ Gemfile | 5 + LICENSE | 19 ++++ README.md | 38 ++++++++ attributes/default.rb | 36 +++++++ chefignore | 95 +++++++++++++++++++ metadata.rb | 12 +++ recipes/binary.rb | 49 ++++++++++ recipes/default.rb | 26 +++++ spec/spec_helper.rb | 2 + spec/unit/recipes/default_spec.rb | 42 ++++++++ templates/default/sv-mailhog-run.erb | 3 + .../default/serverspec/default_spec.rb | 12 +++ .../default/serverspec/spec_helper.rb | 3 + 18 files changed, 412 insertions(+) create mode 100644 .gitignore create mode 100644 .kitchen.yml create mode 100644 Berksfile create mode 100644 CHANGELOG.md create mode 100644 CONTRIBUTING.md create mode 100644 Gemfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 attributes/default.rb create mode 100644 chefignore create mode 100644 metadata.rb create mode 100644 recipes/binary.rb create mode 100644 recipes/default.rb create mode 100644 spec/spec_helper.rb create mode 100644 spec/unit/recipes/default_spec.rb create mode 100644 templates/default/sv-mailhog-run.erb create mode 100644 test/integration/default/serverspec/default_spec.rb create mode 100644 test/integration/default/serverspec/spec_helper.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ec2a890 --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +.vagrant +Berksfile.lock +*~ +*# +.#* +\#*# +.*.sw[a-z] +*.un~ + +# Bundler +Gemfile.lock +bin/* +.bundle/* + +.kitchen/ +.kitchen.local.yml diff --git a/.kitchen.yml b/.kitchen.yml new file mode 100644 index 0000000..2144d37 --- /dev/null +++ b/.kitchen.yml @@ -0,0 +1,16 @@ +--- +driver: + name: vagrant + +provisioner: + name: chef_zero + +platforms: + - name: ubuntu-12.04 + - name: centos-6.5 + +suites: + - name: default + run_list: + - recipe[mailhog::default] + attributes: diff --git a/Berksfile b/Berksfile new file mode 100644 index 0000000..967b9a7 --- /dev/null +++ b/Berksfile @@ -0,0 +1,3 @@ +source "https://supermarket.chef.io" + +metadata diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..22d0cab --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +0.1.0 (2015-03-23) +------------------ + +* Initial release diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..ce2966f --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,31 @@ +# How to contribute + +I appreciate any kind of contributions. Please feel free to submit issue reports, feature suggestions and especially pull requests. But please take a moment to review following guidelines. + +## Got a Question? + +Please don't use Github Issues for asking questions. This project uses Github Issues for bug tracking and feature management only, not as some kind of support forum. +If you have personal support request or any questions about how to use this project, please feel free to send an email to project maintainer. You may find the email address in maintainer's Github profile. + +## Reporting bugs + +Please make sure that issue is reproducible on the latest code in `develop` branch in the repository. + +Be sure to include enough of information so that your issue can be recreated. + +Make sure that no other similar issues already exist. + +## Submitting pull requests + +### Branches + +This repository is using [git flow](http://nvie.com/posts/a-successful-git-branching-model/) branching model. If you're not familiar with it, please take a moment to read the text by the link. + +Generally it means that all new branches should be forked from `develop` branch, not from `master`. + +### Pull request workflow + +1. Fork the repo. +2. Checkout your new branch from `develop` branch. +3. Push your changes to your branch in your fork of repository. +4. Submit a pull request to the upstream repository. diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..2630c54 --- /dev/null +++ b/Gemfile @@ -0,0 +1,5 @@ +source "https://rubygems.org" + +gem "berkshelf" +gem "stove", "~> 3.0.0" + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7ba882e --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2015 Sergey Storchay + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..4a8447d --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# chef-mailhog + +[![CK Version](http://img.shields.io/cookbook/v/mailhog.svg)](https://supermarket.getchef.com/cookbooks/mailhog) + +This cookbook installs [MailHog](https://github.com/mailhog/MailHog). + +Usage +----- + +Include the mailhog recipe to install MailHog on your system: +```chef +include_recipe "mailhog" +``` + +MailHog service is installed and managed via `runit`. + +Requirements +------------ + +### Cookbooks: + +* runit + +### Platforms: + +* Ubuntu +* Debian +* RHEL +* CentOS +* Fedora + +License +------- + +Copyright (c) 2015 Sergey Storchay, http://r8.com.ua + +Licensed under MIT: +http://raw.github.com/r8/chef-mailhog/master/LICENSE diff --git a/attributes/default.rb b/attributes/default.rb new file mode 100644 index 0000000..e017520 --- /dev/null +++ b/attributes/default.rb @@ -0,0 +1,36 @@ +# +# Cookbook Name:: mailhog +# Recipe:: default +# +# Copyright (c) 2015 Sergey Storchay, All Rights Reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +default['mailhog']['version'] = '0.1.6' +default['mailhog']['install_method'] = 'binary' + +default['mailhog']['binary']['url'] = nil # Set it to override automatical generation + +default['mailhog']['binary']['mode'] = 0755 +default['mailhog']['binary']['path'] = '/usr/local/bin/MailHog' + +default['mailhog']['binary']['prefix_url'] = 'http://github.com/mailhog/MailHog/releases/download/v' +default['mailhog']['binary']['checksum']['linux_386'] = 'a72d1016b70964562c8a77a3b57637a77889ee61f3b22973e0a7beb17181d8da' +default['mailhog']['binary']['checksum']['linux_amd64'] = 'e8e9acb4fa4470f4d4c3a4bba312f335bfc28122ea723599531699f099b4c9a5' diff --git a/chefignore b/chefignore new file mode 100644 index 0000000..80dc2d2 --- /dev/null +++ b/chefignore @@ -0,0 +1,95 @@ +# Put files/directories that should be ignored in this file when uploading +# or sharing to the community site. +# Lines that start with '# ' are comments. + +# OS generated files # +###################### +.DS_Store +Icon? +nohup.out +ehthumbs.db +Thumbs.db + +# SASS # +######## +.sass-cache + +# EDITORS # +########### +\#* +.#* +*~ +*.sw[a-z] +*.bak +REVISION +TAGS* +tmtags +*_flymake.* +*_flymake +*.tmproj +.project +.settings +mkmf.log + +## COMPILED ## +############## +a.out +*.o +*.pyc +*.so +*.com +*.class +*.dll +*.exe +*/rdoc/ + +# Testing # +########### +.watchr +.rspec +spec/* +spec/fixtures/* +test/* +features/* +Guardfile +Procfile + +# SCM # +####### +.git +*/.git +.gitignore +.gitmodules +.gitconfig +.gitattributes +.svn +*/.bzr/* +*/.hg/* +*/.svn/* + +# Berkshelf # +############# +Berksfile +Berksfile.lock +cookbooks/* +tmp + +# Cookbooks # +############# +CONTRIBUTING + +# Strainer # +############ +Colanderfile +Strainerfile +.colander +.strainer + +# Vagrant # +########### +.vagrant +Vagrantfile + +# Travis # +########## +.travis.yml diff --git a/metadata.rb b/metadata.rb new file mode 100644 index 0000000..6605a09 --- /dev/null +++ b/metadata.rb @@ -0,0 +1,12 @@ +name 'mailhog' +maintainer 'Sergey Storchay' +maintainer_email 'r8@r8.com.ua' +license 'MIT' +description 'Installs/Configures mailhog' +version '0.1.0' + +depends 'runit', '>= 0.0.0' + +%w(debian ubuntu centos redhat smartos).each do |os| + supports os, '>= 0.0.0' +end diff --git a/recipes/binary.rb b/recipes/binary.rb new file mode 100644 index 0000000..d9cf93c --- /dev/null +++ b/recipes/binary.rb @@ -0,0 +1,49 @@ +# +# Cookbook Name:: mailhog +# Recipe:: default +# +# Copyright (c) 2015 Sergey Storchay, All Rights Reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +include_recipe 'runit' + +arch = node['kernel']['machine'] =~ /x86_64/ ? 'amd64' : '386' + +if node['mailhog']['binary']['url'] + binary_url = node['mailhog']['binary']['url'] + checksum = node['mailhog']['binary']['checksum'] +else + binary_url = "#{node['mailhog']['binary']['prefix_url']}#{node['mailhog']['version']}/MailHog_linux_#{arch}" + checksum = node['mailhog']['binary']['checksum']["linux_#{arch}"] +end + +# Download and install binary file +remote_file node['mailhog']['binary']['path'] do + source binary_url + checksum checksum + mode node['mailhog']['binary']['mode'] + action :create +end + +# Setup runit service +runit_service 'mailhog' do + default_logger true +end diff --git a/recipes/default.rb b/recipes/default.rb new file mode 100644 index 0000000..aa25e83 --- /dev/null +++ b/recipes/default.rb @@ -0,0 +1,26 @@ +# +# Cookbook Name:: mailhog +# Recipe:: default +# +# Copyright (c) 2015 Sergey Storchay, All Rights Reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +include_recipe "mailhog::#{node['mailhog']['install_method']}" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..1dd5126 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,2 @@ +require 'chefspec' +require 'chefspec/berkshelf' diff --git a/spec/unit/recipes/default_spec.rb b/spec/unit/recipes/default_spec.rb new file mode 100644 index 0000000..6411ac3 --- /dev/null +++ b/spec/unit/recipes/default_spec.rb @@ -0,0 +1,42 @@ +# +# Cookbook Name:: mailhog +# Spec:: default +# +# Copyright (c) 2015 Sergey Storchay, All Rights Reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +require 'spec_helper' + +describe 'mailhog::default' do + + context 'When all attributes are default, on an unspecified platform' do + + let(:chef_run) do + runner = ChefSpec::ServerRunner.new + runner.converge(described_recipe) + end + + it 'converges successfully' do + chef_run # This should not raise an error + end + + end +end diff --git a/templates/default/sv-mailhog-run.erb b/templates/default/sv-mailhog-run.erb new file mode 100644 index 0000000..5b7881d --- /dev/null +++ b/templates/default/sv-mailhog-run.erb @@ -0,0 +1,3 @@ +#!/bin/sh +exec 2>&1 +exec /usr/bin/env MailHog diff --git a/test/integration/default/serverspec/default_spec.rb b/test/integration/default/serverspec/default_spec.rb new file mode 100644 index 0000000..f710e2a --- /dev/null +++ b/test/integration/default/serverspec/default_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe 'mailhog::default' do + + # Serverspec examples can be found at + # http://serverspec.org/resource_types.html + + it 'does something' do + skip 'Replace this with meaningful tests' + end + +end \ No newline at end of file diff --git a/test/integration/default/serverspec/spec_helper.rb b/test/integration/default/serverspec/spec_helper.rb new file mode 100644 index 0000000..37af1b4 --- /dev/null +++ b/test/integration/default/serverspec/spec_helper.rb @@ -0,0 +1,3 @@ +require 'serverspec' + +set :backend, :exec