forked from test-kitchen/kitchen-habitat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Steven Murawski <[email protected]>
- Loading branch information
0 parents
commit f809a49
Showing
7 changed files
with
237 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Because this is a gem, ignore Gemfile.lock: | ||
|
||
Gemfile.lock | ||
|
||
# And because this is Ruby, ignore the following | ||
# (source: https://github.com/github/gitignore/blob/master/Ruby.gitignore): | ||
|
||
*.rbc | ||
*.gem | ||
.bundle | ||
.config | ||
.rubocop.yml | ||
coverage | ||
InstalledFiles | ||
lib/bundler/man | ||
pkg | ||
rdoc | ||
spec/reports | ||
test/tmp | ||
test/version_tmp | ||
tmp | ||
.DS_Store | ||
|
||
# YARD artifacts | ||
.yardoc | ||
_yardoc | ||
doc/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# encoding: utf-8 | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in kitchen-habitat.gemspec | ||
gemspec | ||
|
||
group :test do | ||
gem 'rake' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[](http://badge.fury.io/rb/kitchen-habitat) | ||
|
||
# kitchen-habitat | ||
A Test Kitchen Provisioner for [Habitat](https://habitat.sh) | ||
|
||
## Requirements | ||
|
||
|
||
## Installation & Setup | ||
You'll need the test-kitchen & kitchen-habitat gems installed in your system, along with kitchen-vagrant or some ther suitable driver for test-kitchen. | ||
|
||
## Configuration Settings | ||
* depot_url | ||
* Target Habitat Depot to use to install packages. | ||
* Defaults to `nil` (which will use the default depot settings for the `hab` CLI). | ||
* hab_sup | ||
* Package identification for the supervisor to use | ||
* Defaults to `core/hab-sup` | ||
* package_name | ||
* Package identification for the supervisor to run. | ||
* Defaults to the suite name | ||
|
||
## Example | ||
|
||
```yaml | ||
provisioner: | ||
- name: habitat | ||
hab_sup: core/hab/0.16.0 | ||
|
||
|
||
suite: | ||
- name: core/redis | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- encoding: utf-8 -*- | ||
|
||
require 'bundler/gem_tasks' | ||
|
||
require 'rake/testtask' | ||
Rake::TestTask.new(:unit) do |t| | ||
t.libs.push 'lib' | ||
t.test_files = FileList['spec/**/*_spec.rb'] | ||
t.verbose = true | ||
end | ||
|
||
desc 'Run all test suites' | ||
task test: [:unit] | ||
|
||
desc 'Display LOC stats' | ||
task :stats do | ||
puts "\n## Production Code Stats" | ||
sh 'countloc -r lib' | ||
puts "\n## Test Code Stats" | ||
sh 'countloc -r spec' | ||
end | ||
|
||
begin | ||
require "chefstyle" | ||
require "rubocop/rake_task" | ||
RuboCop::RakeTask.new(:style) do |task| | ||
task.options += ["--display-cop-names", "--no-color"] | ||
end | ||
rescue LoadError | ||
puts "chefstyle is not available. gem install chefstyle to do style checking." | ||
end | ||
|
||
desc 'Run all quality tasks' | ||
task quality: [:style, :stats] | ||
|
||
|
||
task default: [:test, :quality] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# encoding: utf-8 | ||
|
||
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__) | ||
require 'kitchen-habitat/version' | ||
|
||
Gem::Specification.new do |s| | ||
s.name = 'kitchen-habitat' | ||
s.version = Kitchen::Habitat::VERSION | ||
s.authors = ['Steven Murawski'] | ||
s.email = ['[email protected]'] | ||
s.homepage = 'https://github.com/test-kitchen/kitchen-habitat' | ||
s.summary = 'Habitat provisioner for test-kitchen' | ||
candidates = Dir.glob('lib/**/*') + ['README.md', 'kitchen-habitat.gemspec'] | ||
s.files = candidates.sort | ||
s.platform = Gem::Platform::RUBY | ||
s.require_paths = ['lib'] | ||
s.rubyforge_project = '[none]' | ||
s.license = 'Apache 2' | ||
s.description = <<-EOF | ||
== DESCRIPTION: | ||
Habitat Provisioner for Test Kitchen | ||
== FEATURES: | ||
TBD | ||
EOF | ||
s.add_dependency 'test-kitchen', '~> 1.4' | ||
|
||
s.add_development_dependency 'countloc', '~> 0.4' | ||
s.add_development_dependency 'rake' | ||
s.add_development_dependency 'rspec', '~> 3.2' | ||
s.add_development_dependency 'simplecov', '~> 0.9' | ||
|
||
# style and complexity libraries are tightly version pinned as newer releases | ||
# may introduce new and undesireable style choices which would be immediately | ||
# enforced in CI | ||
s.add_development_dependency 'chefstyle' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# encoding: utf-8 | ||
|
||
module Kitchen | ||
module Habitat | ||
VERSION = '0.1.0'.freeze | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# -*- encoding: utf-8 -*- | ||
# | ||
# Author:: Steven Murawski (<[email protected]>) | ||
# | ||
# Copyright (C) 2014 Steven Murawski | ||
# | ||
# Licensed under the MIT License. | ||
# See LICENSE for more details | ||
|
||
require "fileutils" | ||
require "pathname" | ||
require "kitchen/provisioner/base" | ||
require "kitchen/util" | ||
|
||
module Kitchen | ||
module Provisioner | ||
class Habitat < Base | ||
kitchen_provisioner_api_version 2 | ||
|
||
default_config :depot_url, nil | ||
default_config :hab_sup, "core/hab-sup" | ||
default_config :package_origin, "core" | ||
default_config :package_name do |provisioner| | ||
provisioner.instance.suite.name | ||
end | ||
|
||
def install_command | ||
if instance.platform == "windows" | ||
raise "Need to fill in some implementation here." | ||
else | ||
wrap_shell_code <<-BASH | ||
if command -v hab >/dev/null 2>&1 | ||
then | ||
echo "Habitat CLI already installed." | ||
else | ||
curl 'https://raw.githubusercontent.com/habitat-sh/habitat/master/components/hab/install.sh' | sudo bash | ||
fi | ||
BASH | ||
end | ||
end | ||
|
||
def init_command | ||
wrap_shell_code "id -u hab || sudo useradd hab" | ||
end | ||
|
||
def create_sandbox | ||
super | ||
|
||
end | ||
|
||
def prepare_command | ||
wrap_shell_code <<-EOH | ||
sudo hab pkg install #{config[:hab_sup]} | ||
sudo hab pkg binlink #{config[:hab_sup]} hab-sup | ||
EOH | ||
end | ||
|
||
def run_command | ||
run = <<-RUN | ||
if sudo screen -ls | grep -q #{clean_package_name} | ||
then | ||
echo "Killing previous supervisor session." | ||
sudo screen -S \"#{clean_package_name}\" -X quit > /dev/null | ||
echo "Removing dead session." | ||
sudo screen -wipe > /dev/null | ||
fi | ||
sudo screen -mdS \"#{clean_package_name}\" hab-sup start #{package_ident} | ||
RUN | ||
info("Running #{package_ident}.") | ||
wrap_shell_code run | ||
end | ||
|
||
private | ||
|
||
def package_ident | ||
@pkg_ident ||= "#{config[:package_origin]}/#{config[:package_name]}" | ||
end | ||
|
||
def clean_package_name | ||
@clean_name ||= "#{config[:package_origin]}-#{config[:package_name]}" | ||
end | ||
end | ||
end | ||
end |