kitchen-habitat 0.9.0 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +143 -4
- data/lib/kitchen-habitat/version.rb +1 -1
- data/lib/kitchen/provisioner/habitat.rb +211 -131
- metadata +19 -12
- data/kitchen-habitat.gemspec +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 307c3545cbd9d4738778e6d14c02e75929f52c805a7b3cea679af0a185748bb1
|
4
|
+
data.tar.gz: 6a61cb7f38f2074f25cc9b9ce429da766e27b120e1e0c2dcd19dc53e1f9db884
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee379fa70d6808368dd5d63fe8a5ac0cf172e2524a876a9ab535b32cb98cee7cd59f6fd42252df02cbcf70fa48eff7c7c3ce7d06ceedcc9294f2faa60c578ec9
|
7
|
+
data.tar.gz: d856038e6443e73343fcba7fab4fee84bfffd318feb5b33285421cb7e3ac40db1e1861be1246ccfbf90683e54700c7f6a935bdee3890285ff3404d32dbc3c036
|
data/README.md
CHANGED
@@ -1,16 +1,21 @@
|
|
1
1
|
[![Gem Version](https://badge.fury.io/rb/kitchen-habitat.svg)](http://badge.fury.io/rb/kitchen-habitat)
|
2
|
+
[![Build Status](https://github.com/test-kitchen/kitchen-habitat/workflows/CI/badge.svg?branch=master)](https://github.com/test-kitchen/kitchen-habitat/actions?query=workflow%3ACI+branch%3Amaster)
|
2
3
|
|
3
4
|
# kitchen-habitat
|
5
|
+
|
4
6
|
A Test Kitchen Provisioner for [Habitat](https://habitat.sh)
|
5
7
|
|
6
8
|
## Requirements
|
7
9
|
|
8
|
-
|
9
10
|
## Installation & Setup
|
11
|
+
|
10
12
|
You'll need the test-kitchen & kitchen-habitat gems installed in your system, along with kitchen-vagrant or some other suitable driver for test-kitchen.
|
11
13
|
|
12
14
|
## Configuration Settings
|
13
15
|
|
16
|
+
* `hab_license`: Habitat license acceptance type (for more information please read the [chef license documentation](https://docs.chef.io/chef_license_accept.html#habitat)).
|
17
|
+
* `hab_version`: The version of habitat to be used in test kitchen.
|
18
|
+
|
14
19
|
### Depot settings
|
15
20
|
|
16
21
|
* `depot_url`
|
@@ -51,6 +56,9 @@ You'll need the test-kitchen & kitchen-habitat gems installed in your system, al
|
|
51
56
|
* `hab_sup_peer`
|
52
57
|
* IP and port (e.g. `192.168.1.86:9010`) of the supervisor of which to connect to join the ring.
|
53
58
|
* Default is `[]`
|
59
|
+
* `hab_sup_ring`
|
60
|
+
* Ring key name
|
61
|
+
* Default is `nil`
|
54
62
|
|
55
63
|
### Package Settings
|
56
64
|
|
@@ -62,7 +70,7 @@ You'll need the test-kitchen & kitchen-habitat gems installed in your system, al
|
|
62
70
|
* Defaults to `nil`
|
63
71
|
* `results_directory`
|
64
72
|
* Directory (relative to the location of the .kitchen.yml) containing package artifacts (harts) to copy to the remote system
|
65
|
-
* Defaults to checking the local directory for a `results` directory, then its parent (`../results`) and grandparent (`../../results`), which should
|
73
|
+
* Defaults to checking the local directory for a `results` directory, then its parent (`../results`) and grandparent (`../../results`), which should accommodate most studio layouts.
|
66
74
|
* `package_origin`
|
67
75
|
* Origin for the package to run.
|
68
76
|
* Defaults to `core`, or, if `artifact_name` is supplied, the `package_origin` will be parsed from the filename of the hart file.
|
@@ -95,6 +103,26 @@ You'll need the test-kitchen & kitchen-habitat gems installed in your system, al
|
|
95
103
|
* `package_version` and `package_release` will be ignored
|
96
104
|
* Defaults to `false`
|
97
105
|
|
106
|
+
### EAS Application Dashboard Settings
|
107
|
+
|
108
|
+
* `event_stream_application`
|
109
|
+
* The name of your application.
|
110
|
+
* Defaults to `nil`
|
111
|
+
* `event_stream_environment`
|
112
|
+
* The application environment for this supervisor.
|
113
|
+
* Defaults to `nil`
|
114
|
+
* `event_stream_site`
|
115
|
+
* Describes the physical (for example, datacenter) or cloud-specific (for example, the AWS region) location where your services are deployed.
|
116
|
+
* Defaults to `nil`
|
117
|
+
* `event_stream_url`
|
118
|
+
* The Chef Automate URL with port 4222 specified.
|
119
|
+
* Defaults to `nil`
|
120
|
+
* `event_stream_token`
|
121
|
+
* Chef Automate Token
|
122
|
+
* Defaults to `nil`
|
123
|
+
|
124
|
+
> NOTE: All 5 EAS settings are required for it to report to Automate.
|
125
|
+
|
98
126
|
## Examples
|
99
127
|
|
100
128
|
Run the core-redis package
|
@@ -117,7 +145,7 @@ suites:
|
|
117
145
|
- name: default
|
118
146
|
```
|
119
147
|
|
120
|
-
Two node: elasticsearch and kibana
|
148
|
+
Two node: elasticsearch and kibana
|
121
149
|
|
122
150
|
```yaml
|
123
151
|
driver:
|
@@ -149,5 +177,116 @@ suites:
|
|
149
177
|
- elasticsearch:elasticsearch.default
|
150
178
|
driver:
|
151
179
|
instance_name: kibana
|
152
|
-
links: elastic:elastic
|
180
|
+
links: elastic:elastic
|
181
|
+
```
|
182
|
+
|
183
|
+
EAS Application Dashboard Example
|
184
|
+
|
185
|
+
``` yaml
|
186
|
+
---
|
187
|
+
driver:
|
188
|
+
name: azurerm
|
189
|
+
|
190
|
+
driver_config:
|
191
|
+
subscription_id: <%= ENV['subscription_id'] %>
|
192
|
+
location: <%= ENV['region'] %>
|
193
|
+
machine_size: "Standard_DS2_v2"
|
194
|
+
|
195
|
+
verifier:
|
196
|
+
name: inspec
|
197
|
+
|
198
|
+
provisioner:
|
199
|
+
name: habitat
|
200
|
+
hab_version: 'latest'
|
201
|
+
hab_license: accept
|
202
|
+
event_stream_application: Effortless
|
203
|
+
event_stream_environment: stable
|
204
|
+
event_stream_site: <%= ENV['region'] %>
|
205
|
+
event_stream_url: automate.example.com:4222
|
206
|
+
event_stream_token: <%= ENV['automate_token'] %>
|
207
|
+
|
208
|
+
platforms:
|
209
|
+
- name: windows
|
210
|
+
driver:
|
211
|
+
image_urn: MicrosoftWindowsServer:WindowsServer:2019-Datacenter:latest
|
212
|
+
vm_name: windows
|
213
|
+
provisioner:
|
214
|
+
package_origin: <%= ENV['package_orgin'] %>
|
215
|
+
package_name: <%= ENV['package_name'] %>
|
216
|
+
|
217
|
+
suites:
|
218
|
+
- name: default
|
219
|
+
verifier:
|
220
|
+
inspec_tests:
|
221
|
+
- tests
|
222
|
+
```
|
223
|
+
|
224
|
+
Latest Artifact example
|
225
|
+
|
226
|
+
> This example assumes you've already done a build via hab studio.
|
227
|
+
|
228
|
+
```yaml
|
229
|
+
driver:
|
230
|
+
name: vagrant
|
231
|
+
customize:
|
232
|
+
memory: 2048
|
233
|
+
|
234
|
+
verifier:
|
235
|
+
name: inspec
|
236
|
+
|
237
|
+
provisioner:
|
238
|
+
name: habitat
|
239
|
+
hab_version: 'latest'
|
240
|
+
hab_license: accept
|
241
|
+
|
242
|
+
platforms:
|
243
|
+
- name: wildfly-local
|
244
|
+
driver:
|
245
|
+
box: bento/ubuntu-16.04
|
246
|
+
provisioner:
|
247
|
+
package_origin: jmassardo
|
248
|
+
package_name: wildfly
|
249
|
+
results_directory: results
|
250
|
+
install_latest_artifact: true
|
251
|
+
|
252
|
+
suites:
|
253
|
+
- name: default
|
254
|
+
verifier:
|
255
|
+
inspec_tests:
|
256
|
+
- tests
|
257
|
+
```
|
258
|
+
|
259
|
+
Apply `user.toml` Example
|
260
|
+
|
261
|
+
> This example assumes that you have a `/configs/user.toml` in your project directory.
|
262
|
+
|
263
|
+
```yaml
|
264
|
+
driver:
|
265
|
+
name: vagrant
|
266
|
+
customize:
|
267
|
+
memory: 2048
|
268
|
+
|
269
|
+
verifier:
|
270
|
+
name: inspec
|
271
|
+
|
272
|
+
provisioner:
|
273
|
+
name: habitat
|
274
|
+
hab_version: 'latest'
|
275
|
+
hab_license: accept
|
276
|
+
|
277
|
+
platforms:
|
278
|
+
- name: wildfly
|
279
|
+
driver:
|
280
|
+
box: bento/ubuntu-16.04
|
281
|
+
provisioner:
|
282
|
+
package_origin: jmassardo
|
283
|
+
package_name: wildfly
|
284
|
+
channel: unstable
|
285
|
+
config_directory: configs
|
286
|
+
|
287
|
+
suites:
|
288
|
+
- name: default
|
289
|
+
verifier:
|
290
|
+
inspec_tests:
|
291
|
+
- tests
|
153
292
|
```
|
@@ -17,6 +17,9 @@ module Kitchen
|
|
17
17
|
kitchen_provisioner_api_version 2
|
18
18
|
|
19
19
|
default_config :depot_url, nil
|
20
|
+
default_config :hab_license, nil
|
21
|
+
default_config :hab_version, "latest"
|
22
|
+
default_config :hab_channel, "stable"
|
20
23
|
default_config :hab_sup_origin, "core"
|
21
24
|
default_config :hab_sup_name, "hab-sup"
|
22
25
|
default_config :hab_sup_version, nil
|
@@ -30,6 +33,7 @@ module Kitchen
|
|
30
33
|
default_config :hab_sup_peer, []
|
31
34
|
default_config :hab_sup_bind, []
|
32
35
|
default_config :hab_sup_group, nil
|
36
|
+
default_config :hab_sup_ring, nil
|
33
37
|
|
34
38
|
# hab-sup service options
|
35
39
|
default_config :install_latest_artifact, false
|
@@ -41,6 +45,7 @@ module Kitchen
|
|
41
45
|
default_config :service_topology, nil
|
42
46
|
default_config :service_update_strategy, nil
|
43
47
|
default_config :channel, "stable"
|
48
|
+
default_config :service_load_timeout, 300
|
44
49
|
|
45
50
|
# local stuffs to copy
|
46
51
|
default_config :results_directory, nil
|
@@ -48,12 +53,16 @@ module Kitchen
|
|
48
53
|
default_config :user_toml_name, "user.toml"
|
49
54
|
default_config :override_package_config, false
|
50
55
|
|
51
|
-
#
|
52
|
-
default_config :
|
56
|
+
# event stream options
|
57
|
+
default_config :event_stream_application, nil
|
58
|
+
default_config :event_stream_environment, nil
|
59
|
+
default_config :event_stream_site, nil
|
60
|
+
default_config :event_stream_url, nil
|
61
|
+
default_config :event_stream_token, nil
|
53
62
|
|
54
63
|
def finalize_config!(instance)
|
55
64
|
# Check to see if a package ident was specified for package name and be helpful
|
56
|
-
unless config[:package_name].nil? || (config[:package_name] =~
|
65
|
+
unless config[:package_name].nil? || (config[:package_name] =~ %r{/}).nil?
|
57
66
|
config[:package_origin], config[:package_name], config[:package_version], config[:package_release] = config[:package_name].split("/")
|
58
67
|
end
|
59
68
|
|
@@ -76,25 +85,19 @@ module Kitchen
|
|
76
85
|
end
|
77
86
|
|
78
87
|
def install_command
|
79
|
-
|
80
|
-
|
81
|
-
#{export_hab_bldr_url}
|
82
|
-
if command -v hab >/dev/null 2>&1
|
83
|
-
then
|
84
|
-
echo "Habitat CLI already installed."
|
88
|
+
if windows_os?
|
89
|
+
wrap_shell_code(windows_install_cmd)
|
85
90
|
else
|
86
|
-
|
87
|
-
|
88
|
-
BASH
|
91
|
+
wrap_shell_code(linux_install_cmd)
|
92
|
+
end
|
89
93
|
end
|
90
94
|
|
91
95
|
def init_command
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
EOH
|
96
|
+
if windows_os?
|
97
|
+
wrap_shell_code(windows_install_service)
|
98
|
+
else
|
99
|
+
wrap_shell_code(linux_install_service)
|
100
|
+
end
|
98
101
|
end
|
99
102
|
|
100
103
|
def create_sandbox
|
@@ -105,78 +108,152 @@ module Kitchen
|
|
105
108
|
end
|
106
109
|
|
107
110
|
def prepare_command
|
108
|
-
|
109
|
-
|
110
|
-
#{install_supervisor_command}
|
111
|
-
#{binlink_supervisor_command}
|
112
|
-
#{install_service_package}
|
111
|
+
debug("Prepare command is running")
|
112
|
+
wrap_shell_code <<~PREPARE
|
113
113
|
#{remove_previous_user_toml}
|
114
114
|
#{copy_user_toml_to_service_directory}
|
115
|
-
|
115
|
+
PREPARE
|
116
116
|
end
|
117
117
|
|
118
118
|
def run_command
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
119
|
+
# This little bit figures out what package should be loaded
|
120
|
+
if config[:install_latest_artifact] || !config[:artifact_name].nil?
|
121
|
+
# TODO: throw error and bail if there's no artifacts in the results directory
|
122
|
+
target_pkg = get_artifact_name
|
123
|
+
target_ident = "#{config[:package_origin]}/#{config[:package_name]}"
|
124
|
+
# TODO: This is a workaround for windows. The hart file sometimes gets copied to the
|
125
|
+
# %TEMP%\kitchen instead of %TEMP%\kitchen\results.
|
126
|
+
if windows_os?
|
127
|
+
target_pkg = target_pkg.gsub("results/", "") unless File.exist?(target_pkg)
|
128
|
+
end
|
129
|
+
else
|
130
|
+
target_pkg = package_ident
|
131
|
+
target_ident = package_ident
|
132
|
+
end
|
133
|
+
|
134
|
+
if windows_os?
|
135
|
+
wrap_shell_code <<~PWSH
|
136
|
+
if (!($env:Path | Select-String "Habitat")) {
|
137
|
+
$env:Path += ";C:\\ProgramData\\Habitat"
|
138
|
+
}
|
139
|
+
hab pkg install #{target_pkg} --channel #{config[:channel]} --force
|
140
|
+
if (Test-Path -Path "$(hab pkg path #{target_ident})\\hooks\\run") {
|
141
|
+
hab svc load #{target_ident} #{service_options} --force
|
142
|
+
$timer = 0
|
143
|
+
Do {
|
144
|
+
if ($timer -gt #{config[:service_load_timeout]}){exit 1}
|
145
|
+
Start-Sleep -Seconds 1
|
146
|
+
$timer++
|
147
|
+
} until( hab svc status | out-string -stream | select-string #{target_ident})
|
148
|
+
}
|
149
|
+
PWSH
|
150
|
+
else
|
151
|
+
wrap_shell_code <<~BASH
|
152
|
+
until sudo -E hab svc status > /dev/null
|
153
|
+
do
|
154
|
+
echo "Waiting 5 seconds for supervisor to finish loading"
|
155
|
+
sleep 5
|
156
|
+
done
|
157
|
+
sudo hab pkg install #{target_pkg} --channel #{config[:channel]} --force
|
158
|
+
if [ -f $(sudo hab pkg path #{target_ident})/hooks/run ]
|
159
|
+
then
|
160
|
+
sudo -E hab svc load #{target_ident} #{service_options} --force
|
161
|
+
timer=0
|
162
|
+
until sudo -E hab svc status | grep #{target_ident}
|
163
|
+
do
|
164
|
+
if [$timer -gt #{config[:service_load_timeout]}]; then exit 1; fi
|
165
|
+
sleep 1
|
166
|
+
$timer++
|
167
|
+
done
|
168
|
+
fi
|
169
|
+
BASH
|
170
|
+
end
|
128
171
|
end
|
129
172
|
|
130
173
|
private
|
131
174
|
|
132
|
-
def
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
CLEAN
|
175
|
+
def windows_install_cmd
|
176
|
+
<<~PWSH
|
177
|
+
if ((Get-Command hab -ErrorAction Ignore).Path) {
|
178
|
+
Write-Output "Habitat CLI already installed."
|
179
|
+
} else {
|
180
|
+
Set-ExecutionPolicy Bypass -Scope Process -Force
|
181
|
+
$InstallScript = ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/habitat-sh/habitat/master/components/hab/install.ps1'))
|
182
|
+
Invoke-Command -ScriptBlock ([scriptblock]::Create($InstallScript)) -ArgumentList #{config[:hab_channel]}, #{config[:hab_version]}
|
183
|
+
}
|
184
|
+
PWSH
|
143
185
|
end
|
144
186
|
|
145
|
-
def
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
187
|
+
def linux_install_cmd
|
188
|
+
version = " -v #{config[:hab_version]}" unless config[:hab_version].eql?("latest")
|
189
|
+
<<~BASH
|
190
|
+
if command -v hab >/dev/null 2>&1
|
191
|
+
then
|
192
|
+
echo "Habitat CLI already installed."
|
193
|
+
else
|
194
|
+
curl -o /tmp/install.sh 'https://raw.githubusercontent.com/habitat-sh/habitat/master/components/hab/install.sh'
|
195
|
+
sudo -E bash /tmp/install.sh#{version}
|
196
|
+
fi
|
197
|
+
BASH
|
154
198
|
end
|
155
199
|
|
156
|
-
def
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
200
|
+
def windows_install_service
|
201
|
+
<<~WINDOWS_SERVICE_SETUP
|
202
|
+
New-Item -Path C:\\Windows\\Temp\\kitchen -ItemType Directory -Force | Out-Null
|
203
|
+
#{"New-Item -Path C:\\Windows\\Temp\\kitchen\\config -ItemType Directory -Force | Out-Null" unless config[:override_package_config]}
|
204
|
+
if (!($env:Path | Select-String "Habitat")) {
|
205
|
+
$env:Path += ";C:\\ProgramData\\Habitat"
|
206
|
+
}
|
207
|
+
if (!(Get-Service -Name Habitat -ErrorAction Ignore)) {
|
208
|
+
hab license accept
|
209
|
+
Write-Output "Installing Habitat Windows Service"
|
210
|
+
hab pkg install core/windows-service
|
211
|
+
if ($(Get-Service -Name Habitat).Status -ne "Stopped") {
|
212
|
+
Stop-Service -Name Habitat
|
213
|
+
}
|
214
|
+
$HabSvcConfig = "c:\\hab\\svc\\windows-service\\HabService.dll.config"
|
215
|
+
[xml]$xmlDoc = Get-Content $HabSvcConfig
|
216
|
+
$obj = $xmlDoc.configuration.appSettings.add | where {$_.Key -eq "launcherArgs" }
|
217
|
+
$obj.value = "--no-color#{supervisor_options}"
|
218
|
+
$xmlDoc.Save($HabSvcConfig)
|
219
|
+
Start-Service -Name Habitat
|
220
|
+
}
|
221
|
+
WINDOWS_SERVICE_SETUP
|
222
|
+
end
|
176
223
|
|
177
|
-
|
178
|
-
|
179
|
-
|
224
|
+
def linux_install_service
|
225
|
+
<<~LINUX_SERVICE_SETUP
|
226
|
+
id -u hab >/dev/null 2>&1 || sudo -E useradd hab >/dev/null 2>&1
|
227
|
+
rm -rf /tmp/kitchen
|
228
|
+
mkdir -p /tmp/kitchen/results
|
229
|
+
#{"mkdir -p /tmp/kitchen/config" unless config[:override_package_config]}
|
230
|
+
if [ -f /etc/systemd/system/hab-sup.service ]
|
231
|
+
then
|
232
|
+
echo "Hab-sup service already exists"
|
233
|
+
else
|
234
|
+
echo "Starting hab-sup service install"
|
235
|
+
hab license accept
|
236
|
+
if ! id -u hab > /dev/null 2>&1; then
|
237
|
+
echo "Adding hab user"
|
238
|
+
sudo -E groupadd hab
|
239
|
+
fi
|
240
|
+
if ! id -g hab > /dev/null 2>&1; then
|
241
|
+
echo "Adding hab group"
|
242
|
+
sudo -E useradd -g hab hab
|
243
|
+
fi
|
244
|
+
echo [Unit] | sudo tee /etc/systemd/system/hab-sup.service
|
245
|
+
echo Description=The Chef Habitat Supervisor | sudo tee -a /etc/systemd/system/hab-sup.service
|
246
|
+
echo [Service] | sudo tee -a /etc/systemd/system/hab-sup.service
|
247
|
+
echo Environment="HAB_BLDR_URL=#{config[:depot_url]}" | sudo tee -a /etc/systemd/system/hab-sup.service
|
248
|
+
echo Environment="HAB_LICENSE=#{config[:hab_license]}" | sudo tee -a /etc/systemd/system/hab-sup.service
|
249
|
+
echo "ExecStart=/bin/hab sup run #{supervisor_options}" | sudo tee -a /etc/systemd/system/hab-sup.service
|
250
|
+
echo [Install] | sudo tee -a /etc/systemd/system/hab-sup.service
|
251
|
+
echo WantedBy=default.target | sudo tee -a /etc/systemd/system/hab-sup.service
|
252
|
+
sudo -E systemctl daemon-reload
|
253
|
+
sudo -E systemctl start hab-sup
|
254
|
+
sudo -E systemctl enable hab-sup
|
255
|
+
fi
|
256
|
+
LINUX_SERVICE_SETUP
|
180
257
|
end
|
181
258
|
|
182
259
|
def resolve_results_directory
|
@@ -198,6 +275,7 @@ module Kitchen
|
|
198
275
|
def copy_package_config_from_override_to_sandbox
|
199
276
|
return if config[:config_directory].nil?
|
200
277
|
return unless config[:override_package_config]
|
278
|
+
|
201
279
|
local_config_dir = File.join(config[:kitchen_root], config[:config_directory])
|
202
280
|
return unless Dir.exist?(local_config_dir)
|
203
281
|
|
@@ -207,8 +285,10 @@ module Kitchen
|
|
207
285
|
|
208
286
|
def copy_results_to_sandbox
|
209
287
|
return if config[:artifact_name].nil? && !config[:install_latest_artifact]
|
288
|
+
|
210
289
|
results_dir = resolve_results_directory
|
211
290
|
return if results_dir.nil?
|
291
|
+
|
212
292
|
FileUtils.mkdir_p(File.join(sandbox_path, "results"))
|
213
293
|
FileUtils.cp(
|
214
294
|
File.join(results_dir, config[:install_latest_artifact] ? latest_artifact_name : config[:artifact_name]),
|
@@ -228,82 +308,63 @@ module Kitchen
|
|
228
308
|
def copy_user_toml_to_sandbox
|
229
309
|
return if config[:config_directory].nil?
|
230
310
|
return unless File.exist?(full_user_toml_path)
|
311
|
+
|
231
312
|
FileUtils.mkdir_p(File.join(sandbox_path, "config"))
|
232
313
|
debug("Copying user.toml from #{full_user_toml_path} to #{sandbox_user_toml_path}")
|
233
314
|
FileUtils.cp(full_user_toml_path, sandbox_user_toml_path)
|
234
315
|
end
|
235
316
|
|
236
|
-
def install_service_package
|
237
|
-
return unless config[:install_latest_artifact] || !config[:artifact_name].nil?
|
238
|
-
|
239
|
-
artifact_name = ""
|
240
|
-
if config[:install_latest_artifact]
|
241
|
-
artifact_name = latest_artifact_name
|
242
|
-
elsif !config[:install_latest_artifact] && !config[:artifact_name].nil?
|
243
|
-
artifact_name = config[:artifact_name]
|
244
|
-
else
|
245
|
-
return
|
246
|
-
end
|
247
|
-
parsed_name = artifact_name.split("-")
|
248
|
-
config[:package_origin] = parsed_name[0]
|
249
|
-
config[:package_name] = parsed_name[1]
|
250
|
-
config[:package_version] = parsed_name[2]
|
251
|
-
config[:package_release] = parsed_name[3]
|
252
|
-
|
253
|
-
artifact_path = File.join(File.join(config[:root_path], "results"), artifact_name)
|
254
|
-
"sudo -E hab pkg install #{artifact_path}"
|
255
|
-
end
|
256
|
-
|
257
317
|
def latest_artifact_name
|
258
318
|
results_dir = resolve_results_directory
|
259
319
|
return if results_dir.nil?
|
260
320
|
|
261
|
-
|
321
|
+
if config[:install_latest_artifact]
|
322
|
+
if config[:package_origin].nil? || config[:package_name].nil?
|
323
|
+
raise UserError,
|
324
|
+
"You must specify a 'package_origin' and 'package_name' to use the 'install_latest_artifact' option"
|
325
|
+
end
|
326
|
+
end
|
262
327
|
|
328
|
+
artifact_path = Dir.glob(File.join(results_dir, "#{config[:package_origin]}-#{config[:package_name]}-*.hart")).max_by { |f| File.mtime(f) }
|
263
329
|
File.basename(artifact_path)
|
264
330
|
end
|
265
331
|
|
266
332
|
def copy_user_toml_to_service_directory
|
267
333
|
return unless !config[:config_directory].nil? && File.exist?(full_user_toml_path)
|
268
|
-
<<-EOH
|
269
|
-
sudo -E mkdir -p /hab/svc/#{config[:package_name]}
|
270
|
-
sudo -E cp #{File.join(File.join(config[:root_path], 'config'), 'user.toml')} /hab/svc/#{config[:package_name]}/user.toml
|
271
|
-
EOH
|
272
|
-
end
|
273
|
-
|
274
|
-
def remove_previous_user_toml
|
275
|
-
<<-REMOVE
|
276
|
-
if [ -d "/hab/svc/#{config[:package_name]}" ]; then
|
277
|
-
sudo -E find /hab/svc/#{config[:package_name]} -name user.toml -delete
|
278
|
-
fi
|
279
|
-
REMOVE
|
280
|
-
end
|
281
|
-
|
282
|
-
def export_hab_bldr_url
|
283
|
-
return if config[:depot_url].nil?
|
284
|
-
"export HAB_BLDR_URL=#{config[:depot_url]}"
|
285
|
-
end
|
286
334
|
|
287
|
-
|
288
|
-
|
335
|
+
if windows_os?
|
336
|
+
<<~PWSH
|
337
|
+
New-Item -Path c:\\hab\\user\\#{config[:package_name]}\\config -ItemType Directory -Force | Out-Null
|
338
|
+
Copy-Item -Path #{File.join(File.join(config[:root_path], "config"), "user.toml")} -Destination c:\\hab\\user\\#{config[:package_name]}\\config\\user.toml -Force
|
339
|
+
PWSH
|
340
|
+
else
|
341
|
+
<<~BASH
|
342
|
+
sudo -E mkdir -p /hab/user/#{config[:package_name]}/config
|
343
|
+
sudo -E cp #{File.join(File.join(config[:root_path], "config"), "user.toml")} /hab/user/#{config[:package_name]}/config/user.toml
|
344
|
+
BASH
|
345
|
+
end
|
289
346
|
end
|
290
347
|
|
291
|
-
def
|
292
|
-
|
348
|
+
def remove_previous_user_toml
|
349
|
+
if windows_os?
|
350
|
+
<<~REMOVE
|
351
|
+
if (Test-Path c:\\hab\\user\\#{config[:package_name]}\\config\\user.toml) {
|
352
|
+
Remove-Item -Path c:\\hab\\user\\#{config[:package_name]}\\config\\user.toml -Force
|
353
|
+
}
|
354
|
+
REMOVE
|
355
|
+
else
|
356
|
+
<<~REMOVE
|
357
|
+
if [ -d "/hab/user/#{config[:package_name]}/config" ]; then
|
358
|
+
sudo -E find /hab/user/#{config[:package_name]}/config -name user.toml -delete
|
359
|
+
fi
|
360
|
+
REMOVE
|
361
|
+
end
|
293
362
|
end
|
294
363
|
|
295
364
|
def artifact_name_to_package_ident_regex
|
296
365
|
/(?<origin>\w+)-(?<name>.*)-(?<version>(\d+)?(\.\d+)?(\.\d+)?(\.\d+)?)-(?<release>\d+)-(?<target>.*)\.hart$/
|
297
366
|
end
|
298
367
|
|
299
|
-
def hab_sup_ident
|
300
|
-
ident = "#{config[:hab_sup_origin]}/" \
|
301
|
-
"#{config[:hab_sup_name]}/" \
|
302
|
-
"#{config[:hab_sup_version]}/" \
|
303
|
-
"#{config[:hab_sup_release]}".chomp("/").chomp("/")
|
304
|
-
@sup_ident ||= ident
|
305
|
-
end
|
306
|
-
|
307
368
|
def package_ident
|
308
369
|
ident = "#{config[:package_origin]}/" \
|
309
370
|
"#{config[:package_name]}/" \
|
@@ -312,21 +373,40 @@ module Kitchen
|
|
312
373
|
@pkg_ident = ident
|
313
374
|
end
|
314
375
|
|
315
|
-
def
|
316
|
-
|
376
|
+
def get_artifact_name
|
377
|
+
artifact_name = ""
|
378
|
+
if config[:install_latest_artifact]
|
379
|
+
artifact_name = latest_artifact_name
|
380
|
+
elsif !config[:install_latest_artifact] && !config[:artifact_name].nil?
|
381
|
+
artifact_name = config[:artifact_name]
|
382
|
+
else
|
383
|
+
return
|
384
|
+
end
|
385
|
+
ident = artifact_name_to_package_ident_regex.match(artifact_name)
|
386
|
+
config[:package_origin] = ident["origin"]
|
387
|
+
config[:package_name] = ident["name"]
|
388
|
+
config[:package_version] = ident["version"]
|
389
|
+
config[:package_release] = ident["release"]
|
390
|
+
File.join(File.join(config[:root_path], "results"), artifact_name)
|
317
391
|
end
|
318
392
|
|
319
393
|
def supervisor_options
|
320
394
|
options = ""
|
321
395
|
options += " --listen-ctl #{config[:hab_sup_listen_ctl]}" unless config[:hab_sup_listen_ctl].nil?
|
322
396
|
options += " --listen-gossip #{config[:hab_sup_listen_gossip]}" unless config[:hab_sup_listen_gossip].nil?
|
323
|
-
options += " --config-from #{File.join(config[:root_path],
|
397
|
+
options += " --config-from #{File.join(config[:root_path], "config/")}" if config[:override_package_config]
|
324
398
|
options += config[:hab_sup_bind].map { |b| " --bind #{b}" }.join(" ") if config[:hab_sup_bind].any?
|
325
399
|
options += config[:hab_sup_peer].map { |p| " --peer #{p}" }.join(" ") if config[:hab_sup_peer].any?
|
326
400
|
options += " --group #{config[:hab_sup_group]}" unless config[:hab_sup_group].nil?
|
401
|
+
options += " --ring #{config[:hab_sup_ring]}" unless config[:hab_sup_ring].nil?
|
327
402
|
options += " --topology #{config[:service_topology]}" unless config[:service_topology].nil?
|
328
403
|
options += " --strategy #{config[:service_update_strategy]}" unless config[:service_update_strategy].nil?
|
329
404
|
options += " --channel #{config[:channel]}" unless config[:channel].nil?
|
405
|
+
options += " --event-stream-application #{config[:event_stream_application]}" unless config[:event_stream_application].nil?
|
406
|
+
options += " --event-stream-environment #{config[:event_stream_environment]}" unless config[:event_stream_environment].nil?
|
407
|
+
options += " --event-stream-site #{config[:event_stream_site]}" unless config[:event_stream_site].nil?
|
408
|
+
options += " --event-stream-url #{config[:event_stream_url]}" unless config[:event_stream_url].nil?
|
409
|
+
options += " --event-stream-token #{config[:event_stream_token]}" unless config[:event_stream_token].nil?
|
330
410
|
|
331
411
|
options
|
332
412
|
end
|
metadata
CHANGED
@@ -1,29 +1,36 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kitchen-habitat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Murawski
|
8
|
-
|
8
|
+
- Robb Kidd
|
9
|
+
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2020-07-29 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: test-kitchen
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
|
-
- - "
|
18
|
+
- - ">="
|
18
19
|
- !ruby/object:Gem::Version
|
19
20
|
version: '1.4'
|
21
|
+
- - "<"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '3'
|
20
24
|
type: :runtime
|
21
25
|
prerelease: false
|
22
26
|
version_requirements: !ruby/object:Gem::Requirement
|
23
27
|
requirements:
|
24
|
-
- - "
|
28
|
+
- - ">="
|
25
29
|
- !ruby/object:Gem::Version
|
26
30
|
version: '1.4'
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3'
|
27
34
|
- !ruby/object:Gem::Dependency
|
28
35
|
name: countloc
|
29
36
|
requirement: !ruby/object:Gem::Requirement
|
@@ -104,20 +111,20 @@ description: |+
|
|
104
111
|
TBD
|
105
112
|
|
106
113
|
email:
|
107
|
-
-
|
114
|
+
- steven.murawski@gmail.com
|
115
|
+
- robb@thekidds.org
|
108
116
|
executables: []
|
109
117
|
extensions: []
|
110
118
|
extra_rdoc_files: []
|
111
119
|
files:
|
112
120
|
- README.md
|
113
|
-
- kitchen-habitat.gemspec
|
114
121
|
- lib/kitchen-habitat/version.rb
|
115
122
|
- lib/kitchen/provisioner/habitat.rb
|
116
123
|
homepage: https://github.com/test-kitchen/kitchen-habitat
|
117
124
|
licenses:
|
118
|
-
- Apache
|
125
|
+
- Apache-2.0
|
119
126
|
metadata: {}
|
120
|
-
post_install_message:
|
127
|
+
post_install_message:
|
121
128
|
rdoc_options: []
|
122
129
|
require_paths:
|
123
130
|
- lib
|
@@ -132,9 +139,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
139
|
- !ruby/object:Gem::Version
|
133
140
|
version: '0'
|
134
141
|
requirements: []
|
135
|
-
|
136
|
-
|
137
|
-
signing_key:
|
142
|
+
rubygems_version: 3.1.2
|
143
|
+
signing_key:
|
138
144
|
specification_version: 4
|
139
145
|
summary: Habitat provisioner for test-kitchen
|
140
146
|
test_files: []
|
147
|
+
...
|
data/kitchen-habitat.gemspec
DELETED
@@ -1,38 +0,0 @@
|
|
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
|