kitchen-habitat 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 214fe452fd77fdc55785e5f8d14b0187f1b940bf
4
+ data.tar.gz: c3e5686edd119d4c16b44393992362dfe86e759f
5
+ SHA512:
6
+ metadata.gz: 323f8e9d9b496645e4bee1e533fcbd91ba866164f2f62b72b21bbddd5249e503fa5384176cd0b00961fedb3fbc4bffeebc59b748f6fc08953515eb573589a306
7
+ data.tar.gz: c664eb0a7b82c7303e0ba62b1d7ffc1501e40ad49d0e52ecb72c91a49bc21b9042e856292fc00004bba025d4d73c10743570df316470aa5d6f977e4d5eacd2d4
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ [![Gem Version](https://badge.fury.io/rb/kitchen-habitat.svg)](http://badge.fury.io/rb/kitchen-habitat)
2
+
3
+ # kitchen-habitat
4
+ A Test Kitchen Provisioner for [Habitat](https://habitat.sh)
5
+
6
+ ## Requirements
7
+
8
+
9
+ ## Installation & Setup
10
+ 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.
11
+
12
+ ## Configuration Settings
13
+
14
+ ### Depot settings
15
+
16
+ * `depot_url`
17
+ * Target Habitat Depot to use to install packages.
18
+ * Defaults to `nil` (which will use the default depot settings for the `hab` CLI).
19
+
20
+ ### Supervisor Settings
21
+
22
+ * `hab_sup`
23
+ * Package identification for the supervisor to use.
24
+ * Defaults to `core/hab-sup`
25
+ * `hab_sup_listen_http`
26
+ * Port for the supervisor's sidecar to listen on.
27
+ * Defaults to `nil`
28
+ * `hab_sup_listen_gossip`
29
+ * Port for the supervisor's gossip communication
30
+ * Defaults to `nil`
31
+
32
+ ### Package Settings
33
+
34
+ * `artifact_name`
35
+ * Artifact package filename to install and run.
36
+ * Used to upload and test a local artifact.
37
+ * Example - `core-jq-static-1.5-20170127185151-x86_64-linux.hart`
38
+ * Defaults to `nil`
39
+ * `package_origin`
40
+ * Origin for the package to run.
41
+ * Defaults to `core`, or or, if `artifact_name` is supplied, the `package_origin` will be parsed from the filename of the hart file.
42
+ * `package_name`
43
+ * Package name for the supervisor to run.
44
+ * Defaults to the suite name or, if `artifact_name` is supplied, the `package_name` will be parsed from the filename of the hart file.
45
+ * `package_version`
46
+ * Package version of the package to be run.
47
+ * Defaults to `nil` or if `artifact_name` is supplied, the `package_version` will be parsed from the filename of the hart file.
48
+ * `package_timestamp`
49
+ * Package timestamp of the package to be run.
50
+ * Defaults to `nil` or if `artifact_name` is supplied, the `package_timestamp` will be parsed from the filename of the hart file.
51
+
52
+
53
+ ## Example
54
+
55
+ ```yaml
56
+ provisioner:
57
+ - name: habitat
58
+ hab_sup: core/hab/0.16.0
59
+
60
+
61
+ suite:
62
+ - name: core/redis
63
+ ```
@@ -0,0 +1,38 @@
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
+ require "kitchen-habitat/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "kitchen-habitat"
6
+ s.version = Kitchen::Habitat::VERSION
7
+ s.authors = ["Steven Murawski"]
8
+ s.email = ["smurawski@chef.io"]
9
+ s.homepage = "https://github.com/test-kitchen/kitchen-habitat"
10
+ s.summary = "Habitat provisioner for test-kitchen"
11
+ candidates = Dir.glob("lib/**/*") + ["README.md", "kitchen-habitat.gemspec"]
12
+ s.files = candidates.sort
13
+ s.platform = Gem::Platform::RUBY
14
+ s.require_paths = ["lib"]
15
+ s.rubyforge_project = "[none]"
16
+ s.license = "Apache 2"
17
+ s.description = <<-EOF
18
+ == DESCRIPTION:
19
+
20
+ Habitat Provisioner for Test Kitchen
21
+
22
+ == FEATURES:
23
+
24
+ TBD
25
+
26
+ EOF
27
+ s.add_dependency "test-kitchen", "~> 1.4"
28
+
29
+ s.add_development_dependency "countloc", "~> 0.4"
30
+ s.add_development_dependency "rake"
31
+ s.add_development_dependency "rspec", "~> 3.2"
32
+ s.add_development_dependency "simplecov", "~> 0.9"
33
+
34
+ # style and complexity libraries are tightly version pinned as newer releases
35
+ # may introduce new and undesireable style choices which would be immediately
36
+ # enforced in CI
37
+ s.add_development_dependency "chefstyle"
38
+ end
@@ -0,0 +1,5 @@
1
+ module Kitchen
2
+ module Habitat
3
+ VERSION = "0.1.0".freeze
4
+ end
5
+ end
@@ -0,0 +1,153 @@
1
+ #
2
+ # Author:: Steven Murawski (<steven.murawski@gmail.com>)
3
+ #
4
+ # Copyright (C) 2014 Steven Murawski
5
+ #
6
+ # Licensed under the MIT License.
7
+ # See LICENSE for more details
8
+
9
+ require "fileutils"
10
+ require "pathname"
11
+ require "kitchen/provisioner/base"
12
+ require "kitchen/util"
13
+
14
+ module Kitchen
15
+ module Provisioner
16
+ class Habitat < Base
17
+ kitchen_provisioner_api_version 2
18
+
19
+ default_config :depot_url, nil
20
+ default_config :hab_sup, "core/hab-sup"
21
+
22
+ # hab-sup manager options
23
+ default_config :hab_sup_listen_http, nil
24
+ default_config :hab_sup_listen_gossip, nil
25
+
26
+ # hab-sup service options
27
+ #default_config :
28
+ default_config :artifact_name
29
+ default_config :package_origin, "core"
30
+ default_config :package_name do |provisioner|
31
+ provisioner.instance.suite.name
32
+ end
33
+ default_config :package_version
34
+ default_config :package_timestamp
35
+
36
+ default_config :user_toml_path
37
+
38
+ def finalize_config!(instance)
39
+ unless config[:artifact_name].nil?
40
+ ident = artifact_name_to_package_ident_regex.match(config[:artifact_name])
41
+ config[:package_origin] = ident["origin"]
42
+ config[:package_name] = ident["name"]
43
+ config[:package_version] = ident["version"]
44
+ config[:package_timestamp] = ident["timestamp"]
45
+ end
46
+ super(instance)
47
+ end
48
+
49
+ def install_command
50
+ if instance.platform == "windows"
51
+ raise "Need to fill in some implementation here."
52
+ else
53
+ wrap_shell_code <<-BASH
54
+ #{export_hab_origin}
55
+ if command -v hab >/dev/null 2>&1
56
+ then
57
+ echo "Habitat CLI already installed."
58
+ else
59
+ curl 'https://raw.githubusercontent.com/habitat-sh/habitat/master/components/hab/install.sh' | sudo bash
60
+ fi
61
+ BASH
62
+ end
63
+ end
64
+
65
+ def init_command
66
+ wrap_shell_code "id -u hab > /dev/null || sudo useradd hab > /dev/null"
67
+ end
68
+
69
+ def create_sandbox
70
+ super
71
+ copy_results_to_sandbox
72
+ end
73
+
74
+ def prepare_command
75
+ wrap_shell_code <<-EOH
76
+ #{export_hab_origin}
77
+ #{install_supervisor_command}
78
+ #{binlink_supervisor_command}
79
+ #{install_service_package}
80
+ EOH
81
+ end
82
+
83
+ def run_command
84
+ run = <<-RUN
85
+ if sudo screen -ls | grep -q #{clean_package_name}
86
+ then
87
+ echo "Killing previous supervisor session."
88
+ sudo screen -S \"#{clean_package_name}\" -X quit > /dev/null
89
+ echo "Removing dead session."
90
+ sudo screen -wipe > /dev/null
91
+ fi
92
+ #{export_hab_origin}
93
+ echo "Running #{package_ident}."
94
+ sudo screen -mdS \"#{clean_package_name}\" hab-sup start #{package_ident} #{supervisor_options}
95
+ RUN
96
+
97
+ wrap_shell_code run
98
+ end
99
+
100
+ private
101
+
102
+ def copy_results_to_sandbox
103
+ FileUtils.mkdir_p(File.join(sandbox_path, "results"))
104
+ FileUtils.cp_r(
105
+ File.join(config[:kitchen_root], "/results"),
106
+ File.join(sandbox_path, "results"),
107
+ preserve: true
108
+ )
109
+ end
110
+
111
+ def install_service_package
112
+ return if config[:artifact_name].nil?
113
+ "sudo hab pkg install #{File.join(File.join(config[:root_path], "results"), config[:artifact_name])}"
114
+ end
115
+
116
+ def export_hab_origin
117
+ return if config[:depot_url].nil?
118
+ "export HAB_ORIGIN=#{config[:depot_url]}"
119
+ end
120
+
121
+ def install_supervisor_command
122
+ "sudo hab pkg install #{config[:hab_sup]}"
123
+ end
124
+
125
+ def binlink_supervisor_command
126
+ "sudo hab pkg binlink #{config[:hab_sup]} hab-sup"
127
+ end
128
+
129
+ def artifact_name_to_package_ident_regex
130
+ /(?<origin>\w+)-(?<name>.*)-(?<version>(\d+)?(\.\d+)?(\.\d+)?(\.\d+)?)-(?<timestamp>\d+)-(?<target>.*)\.hart$/
131
+ end
132
+
133
+ def package_ident
134
+ ident = "#{config[:package_origin]}/" \
135
+ "#{config[:package_name]}/" \
136
+ "#{config[:package_version]}/" \
137
+ "#{config[:package_timestamp]}".chomp("/").chomp("/")
138
+ @pkg_ident ||= ident
139
+ end
140
+
141
+ def clean_package_name
142
+ @clean_name ||= "#{config[:package_origin]}-#{config[:package_name]}"
143
+ end
144
+
145
+ def supervisor_options
146
+ options = "#{'--listen-gossip' + config[:hab_sup_listen_gossip] unless config[:hab_sup_listen_gossip].nil?} " \
147
+ "#{'--listen-http' + config[:hab_sup_listen_http] unless config[:hab_sup_listen_http].nil?} " \
148
+ ""
149
+ options.strip
150
+ end
151
+ end
152
+ end
153
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kitchen-habitat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Steven Murawski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: test-kitchen
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: countloc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: chefstyle
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: |+
98
+ == DESCRIPTION:
99
+
100
+ Habitat Provisioner for Test Kitchen
101
+
102
+ == FEATURES:
103
+
104
+ TBD
105
+
106
+ email:
107
+ - smurawski@chef.io
108
+ executables: []
109
+ extensions: []
110
+ extra_rdoc_files: []
111
+ files:
112
+ - README.md
113
+ - kitchen-habitat.gemspec
114
+ - lib/kitchen-habitat/version.rb
115
+ - lib/kitchen/provisioner/habitat.rb
116
+ homepage: https://github.com/test-kitchen/kitchen-habitat
117
+ licenses:
118
+ - Apache 2
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project: "[none]"
136
+ rubygems_version: 2.6.10
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Habitat provisioner for test-kitchen
140
+ test_files: []