chef-raketasks 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/README.md +212 -0
- data/lib/chef-raketasks.rb +41 -0
- data/lib/chef/raketasks/clean.rb +82 -0
- data/lib/chef/raketasks/doc.rb +39 -0
- data/lib/chef/raketasks/gem.rb +74 -0
- data/lib/chef/raketasks/package.rb +146 -0
- data/lib/chef/raketasks/release.rb +97 -0
- data/lib/chef/raketasks/test.rb +107 -0
- data/lib/chef/raketasks/version.rb +23 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4a206cd5eb0b4304b19c982c0e229cc682b935d3f60e3a7c7fdb0db9f237a239
|
4
|
+
data.tar.gz: 69a5526064b85e790c7e923da858cdd86765d2ab67250485251100c520188607
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '01851a1c137d43a58e26a024085911e2936985db9b3ca5b400995b48aa57217d4c6a05b1ebea4dc2558d1a34fbe626383ef32d89dbfb6f47897c7934e0bdd8d6'
|
7
|
+
data.tar.gz: 0f2d7f87407e78b1f4bd81a42611272462b50e06b31e486cc5f0a13edc7252afd6e86c3e872bfcab1b573516f0be73863b903c948a37ff01618c43e2c4af17f3
|
data/CHANGELOG.md
ADDED
data/README.md
ADDED
@@ -0,0 +1,212 @@
|
|
1
|
+
# chef-raketasks
|
2
|
+
|
3
|
+
## Summary
|
4
|
+
|
5
|
+
A RubyGem which helps out with some technical functionality to
|
6
|
+
make life easier with chef.
|
7
|
+
|
8
|
+
## Requirements
|
9
|
+
|
10
|
+
* Chef Infra >= 14.0
|
11
|
+
* Gems
|
12
|
+
* berkshelf
|
13
|
+
* rake
|
14
|
+
* yard
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
Install gem using ```gem install chef-raketasks``` or add it
|
19
|
+
to your Gemfile/.gemspec
|
20
|
+
|
21
|
+
Include the Gem via ```require 'chef-raketasks'``` at the top of your
|
22
|
+
Rakefile. After that, just run ```rake -T``` or ```rake --tasks``` to see all
|
23
|
+
available tasks.
|
24
|
+
|
25
|
+
## Cleanup Tasks
|
26
|
+
|
27
|
+
### rake clean:chefcache
|
28
|
+
|
29
|
+
Removes cache dirs from any local chef installation.
|
30
|
+
Uses always the regular cache dirs of chef, chefdk and workstation.
|
31
|
+
|
32
|
+
### rake clean:cookbook
|
33
|
+
|
34
|
+
Removes any temporary files from a cookbook.
|
35
|
+
Based on your current position in your filesystem.
|
36
|
+
|
37
|
+
### rake clean:inspec
|
38
|
+
|
39
|
+
Removes any temporary files from an InSpec profile.
|
40
|
+
Based on your current position in your filesystem.
|
41
|
+
|
42
|
+
## Installation Tasks
|
43
|
+
|
44
|
+
### rake gem:install:static
|
45
|
+
|
46
|
+
Installs latest version of kitchen-static gem.
|
47
|
+
|
48
|
+
### rake gem:install:static:kitchen[version,source]
|
49
|
+
|
50
|
+
Installs `kitchen-static` for kitchen.
|
51
|
+
|
52
|
+
* `version`: define a specific version of the gem
|
53
|
+
* `source`: define a different source than rubygems.org
|
54
|
+
|
55
|
+
### rake gem:install:vcenter
|
56
|
+
|
57
|
+
Installs latest version of kitchen-vcenter and related gems.
|
58
|
+
|
59
|
+
### rake gem:install:vcenter:kitchen[version,source]
|
60
|
+
|
61
|
+
Installs kitchen-vcenter for kitchen
|
62
|
+
|
63
|
+
* `version`: define a specific version of the gem
|
64
|
+
* `source`: define a different source than rubygems.org
|
65
|
+
|
66
|
+
### rake gem:install:vcenter:sdk[version,source]
|
67
|
+
|
68
|
+
Installs vcenter sdk for kitchen.
|
69
|
+
|
70
|
+
* `version`: define a specific version of the gem
|
71
|
+
* `source`: define a different source than rubygems.org
|
72
|
+
|
73
|
+
## Packaging Tasks
|
74
|
+
|
75
|
+
### rake package:cookbook
|
76
|
+
|
77
|
+
Package cookbook as .tgz file.
|
78
|
+
Based on your current position in your filesystem.
|
79
|
+
|
80
|
+
### rake package:inspec
|
81
|
+
|
82
|
+
Package InSpec profile as .tgz file
|
83
|
+
|
84
|
+
### rake package:policyfile:install
|
85
|
+
|
86
|
+
Generate new policyfile lock
|
87
|
+
|
88
|
+
## Release Tasks
|
89
|
+
|
90
|
+
### rake release:artifactory[endpoint,apikey,repokey,path]
|
91
|
+
|
92
|
+
Upload to Artifactory with required settings like:
|
93
|
+
|
94
|
+
* `endpoint`: defines the url of artifactory
|
95
|
+
* `apikey`: the api key from artifactory with the necessary rights
|
96
|
+
* `repokey`: add the repokey for artifactory
|
97
|
+
* `path`: add the path within the repo
|
98
|
+
|
99
|
+
### rake release:chefserver
|
100
|
+
|
101
|
+
Upload to Chef Server.
|
102
|
+
It uses the current configured supermarket in your knife.rb or config.rb.
|
103
|
+
|
104
|
+
### rake release:supermarket
|
105
|
+
|
106
|
+
Upload to Chef Supermarket.
|
107
|
+
It uses the current configured supermarket in your knife.rb or config.rb.
|
108
|
+
|
109
|
+
## Test Tasks
|
110
|
+
|
111
|
+
### rake test:integration:ec2[regexp,action]
|
112
|
+
|
113
|
+
Run integration tests on AWS EC2
|
114
|
+
|
115
|
+
* `regexp`: Suite identifier (when calling `kitchen windows test`, this would be
|
116
|
+
`windows`. Default: all)
|
117
|
+
* `action`: Kitchen action (default: `test`)
|
118
|
+
|
119
|
+
For this, your `.kitchen.yml` file gets merged with `.kitchen.ec2.yml` which
|
120
|
+
includes the driver settings.
|
121
|
+
|
122
|
+
Example:
|
123
|
+
|
124
|
+
```yaml
|
125
|
+
driver:
|
126
|
+
name: ec2
|
127
|
+
aws_ssh_key_id: testkitchen
|
128
|
+
region: eu-west-1
|
129
|
+
subnet_id: subnet-123456789
|
130
|
+
security_group_ids: [...]
|
131
|
+
iam_profile_name: ChefKitchen
|
132
|
+
instance_type: t3a.small
|
133
|
+
skip_cost_warning: true
|
134
|
+
tags:
|
135
|
+
Name: ChefKitchen
|
136
|
+
CreatedBy: test-kitchen
|
137
|
+
```
|
138
|
+
|
139
|
+
Details at <https://github.com/test-kitchen/kitchen-ec2>
|
140
|
+
|
141
|
+
### rake test:integration:static[regexp,action]
|
142
|
+
|
143
|
+
Run integration tests using static IPs (e.g. physical hosts).
|
144
|
+
|
145
|
+
You can add some regex and action like you do with kitchen itself. The platform
|
146
|
+
specific file for this task is `.kitchen.static.yml`.
|
147
|
+
|
148
|
+
Details at <https://github.com/tecracer-theinen/kitchen-static>
|
149
|
+
|
150
|
+
### rake test:integration:vagrant[regexp,action]
|
151
|
+
|
152
|
+
Run integration tests using Vagrant.
|
153
|
+
|
154
|
+
You can add some regex and action like you do with kitchen itself. The platform
|
155
|
+
specific file for this task is `.kitchen.vagrant.yml`.
|
156
|
+
|
157
|
+
Details at <https://github.com/test-kitchen/kitchen-vagrant>
|
158
|
+
|
159
|
+
### rake test:integration:vcenter[regexp,action]
|
160
|
+
|
161
|
+
Run integration tests using vCenter.
|
162
|
+
|
163
|
+
You can add some regex and action like you do with kitchen itself. The platform
|
164
|
+
specific file for this task is `.kitchen.vcenter.yml`.
|
165
|
+
|
166
|
+
Details at <https://github.com/chef/kitchen-vcenter>
|
167
|
+
|
168
|
+
|
169
|
+
### rake test:lint:cookbook
|
170
|
+
|
171
|
+
Run linting tests for cookbook in current dir.
|
172
|
+
|
173
|
+
## Contributing
|
174
|
+
|
175
|
+
For information on contributing to this project see <https://github.com/chef/chef/blob/master/CONTRIBUTING.md>
|
176
|
+
|
177
|
+
## Development
|
178
|
+
|
179
|
+
* Report issues/questions/feature requests on [GitHub Issues][issues]
|
180
|
+
* Source hosted at [GitHub][repo]
|
181
|
+
|
182
|
+
Pull requests are very welcome! Make sure your patches are well tested.
|
183
|
+
Ideally create a topic branch for every separate change you make. For
|
184
|
+
example:
|
185
|
+
|
186
|
+
1. Fork the repo
|
187
|
+
1. Create your feature branch (`git checkout -b my-new-feature`)
|
188
|
+
1. Commit your changes with signing them (`git commit -s -am 'Added some feature'`)
|
189
|
+
1. Push to the branch (`git push origin my-new-feature`)
|
190
|
+
1. Create new Pull Request
|
191
|
+
|
192
|
+
## License
|
193
|
+
|
194
|
+
Author:: Patrick Schaumburg ([pschaumburg@tecracer.de](mailto:pschaumburg@tecracer.de))
|
195
|
+
|
196
|
+
Copyright:: Copyright (c) 2020 tecRacer Group
|
197
|
+
|
198
|
+
License:: Apache License, Version 2.0
|
199
|
+
|
200
|
+
```text
|
201
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
202
|
+
you may not use this file except in compliance with the License.
|
203
|
+
You may obtain a copy of the License at
|
204
|
+
|
205
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
206
|
+
|
207
|
+
Unless required by applicable law or agreed to in writing, software
|
208
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
209
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
210
|
+
See the License for the specific language governing permissions and
|
211
|
+
limitations under the License.
|
212
|
+
```
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Patrick Schaumburg (<pschaumburg@tecracer.de>)
|
3
|
+
# Copyright:: Copyright 2020, tecRacer Group
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'rake'
|
20
|
+
require 'rake/tasklib'
|
21
|
+
|
22
|
+
require_relative 'chef/raketasks/clean'
|
23
|
+
require_relative 'chef/raketasks/doc'
|
24
|
+
require_relative 'chef/raketasks/gem'
|
25
|
+
require_relative 'chef/raketasks/package'
|
26
|
+
require_relative 'chef/raketasks/release'
|
27
|
+
require_relative 'chef/raketasks/test'
|
28
|
+
require_relative 'chef/raketasks/version'
|
29
|
+
|
30
|
+
# Hide tasks which are rescoped or not needed usually
|
31
|
+
%w[
|
32
|
+
doc
|
33
|
+
gem:install:generator
|
34
|
+
gem:install:generator:appinstall
|
35
|
+
package:policyfile:pack
|
36
|
+
package:policyfile:update
|
37
|
+
test:integration
|
38
|
+
test:unit:cookbook
|
39
|
+
].each do |task|
|
40
|
+
Rake::Task[task].clear_comments if Rake::Task.task_defined? task
|
41
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Patrick Schaumburg (<pschaumburg@tecracer.de>)
|
3
|
+
# Copyright:: Copyright 2020, tecRacer Group
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
module ChefRake
|
20
|
+
module Task
|
21
|
+
include Rake::DSL if defined? Rake::DSL
|
22
|
+
class Clean < ::Rake::TaskLib
|
23
|
+
def initialize
|
24
|
+
|
25
|
+
namespace :clean do
|
26
|
+
desc 'Removes cache dirs from any local chef installation'
|
27
|
+
task :chefcache do
|
28
|
+
cachedirs = [
|
29
|
+
ENV['HOME'] + '/.chef/cache',
|
30
|
+
ENV['HOME'] + '/.chefdk/cache',
|
31
|
+
ENV['HOME'] + '/.chef-workstation/cache'
|
32
|
+
]
|
33
|
+
cachedirs.each { |f| FileUtils.rm_rf(Dir.glob(f)) }
|
34
|
+
end
|
35
|
+
|
36
|
+
desc 'Removes any temporary files from a cookbook'
|
37
|
+
task :cookbook do
|
38
|
+
%w[
|
39
|
+
Berksfile.lock
|
40
|
+
.bundle
|
41
|
+
.cache
|
42
|
+
coverage
|
43
|
+
doc/
|
44
|
+
Gemfile.lock
|
45
|
+
.kitchen
|
46
|
+
metadata.json
|
47
|
+
pkg/
|
48
|
+
policies/*.lock.json
|
49
|
+
*.lock.json
|
50
|
+
reports/
|
51
|
+
rspec.xml
|
52
|
+
vendor
|
53
|
+
.yardoc
|
54
|
+
.DS_Store
|
55
|
+
].each { |f| FileUtils.rm_rf(Dir.glob(f)) }
|
56
|
+
end
|
57
|
+
|
58
|
+
desc 'Removes any temporary files from an InSpec profile'
|
59
|
+
task :inspec do
|
60
|
+
%w[
|
61
|
+
inspec.lock
|
62
|
+
coverage
|
63
|
+
doc/
|
64
|
+
Gemfile.lock
|
65
|
+
pkg/
|
66
|
+
reports/
|
67
|
+
rspec.xml
|
68
|
+
vendor
|
69
|
+
.yardoc
|
70
|
+
.DS_Store
|
71
|
+
].each { |f| FileUtils.rm_rf(Dir.glob(f)) }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
task clean: :'clean:cookbook'
|
76
|
+
|
77
|
+
end # def initialize
|
78
|
+
end # class Clean
|
79
|
+
end # module RakeTasks
|
80
|
+
end # module Chef
|
81
|
+
|
82
|
+
ChefRake::Task::Clean.new
|
@@ -0,0 +1,39 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Thomas Heinen (<theinen@tecracer.de>)
|
3
|
+
# Copyright:: Copyright 2020, tecRacer Group
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
module ChefRake
|
20
|
+
module Task
|
21
|
+
include Rake::DSL if defined? Rake::DSL
|
22
|
+
class Doc < ::Rake::TaskLib
|
23
|
+
def initialize
|
24
|
+
|
25
|
+
desc 'Generate Ruby documentation'
|
26
|
+
task :doc do
|
27
|
+
require 'yaml'
|
28
|
+
require 'yard'
|
29
|
+
YARD::Rake::YardocTask.new do |t|
|
30
|
+
t.stats_options = %w[--list-undoc]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end # def initialize
|
35
|
+
end # class Doc
|
36
|
+
end # module RakeTasks
|
37
|
+
end # module Chef
|
38
|
+
|
39
|
+
ChefRake::Task::Doc.new
|
@@ -0,0 +1,74 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Patrick Schaumburg (<pschaumburg@tecracer.de>)
|
3
|
+
# Copyright:: Copyright 2020, tecRacer Group
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
module ChefRake
|
20
|
+
module Task
|
21
|
+
include Rake::DSL if defined? Rake::DSL
|
22
|
+
class Gem < ::Rake::TaskLib
|
23
|
+
def initialize
|
24
|
+
|
25
|
+
namespace :gem do
|
26
|
+
desc 'gem:install'
|
27
|
+
namespace :install do
|
28
|
+
def install_gem(name, version, source)
|
29
|
+
cmd = 'chef gem install '
|
30
|
+
cmd << name + ' '
|
31
|
+
cmd << "-v #{version} " unless version.nil?
|
32
|
+
cmd << "-s #{source} " unless source.nil?
|
33
|
+
cmd << '--no-document'
|
34
|
+
|
35
|
+
sh cmd
|
36
|
+
end
|
37
|
+
|
38
|
+
# NAMESPACE: gem:install:static
|
39
|
+
desc 'Installs necessary static gems for kitchen'
|
40
|
+
task static: %i[
|
41
|
+
gem:install:static:kitchen
|
42
|
+
]
|
43
|
+
namespace :static do
|
44
|
+
desc 'Installs kitchen-static for kitchen'
|
45
|
+
task :kitchen, [:version, :source] do |_t, args|
|
46
|
+
install_gem('kitchen-static', args.version, args.source)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# NAMESPACE: gem:install:vcenter
|
51
|
+
desc 'Installs necessary vcenter gems for kitchen'
|
52
|
+
task vcenter: %i[
|
53
|
+
gem:install:vcenter:sdk
|
54
|
+
gem:install:vcenter:kitchen
|
55
|
+
]
|
56
|
+
namespace :vcenter do
|
57
|
+
desc 'Installs vcenter sdk for kitchen'
|
58
|
+
task :sdk, [:version, :source] do |_t, args|
|
59
|
+
install_gem('vsphere-automation-sdk', args.version, args.source)
|
60
|
+
end
|
61
|
+
|
62
|
+
desc 'Installs kitchen-vcenter for kitchen'
|
63
|
+
task :kitchen, [:version, :source] do |_t, args|
|
64
|
+
install_gem('kitchen-vcenter', args.version, args.source)
|
65
|
+
end
|
66
|
+
end # namespace vcenter
|
67
|
+
end # namespace install
|
68
|
+
end # namespace gem
|
69
|
+
end # def initialize
|
70
|
+
end # class Gem
|
71
|
+
end # module RakeTasks
|
72
|
+
end # module Chef
|
73
|
+
|
74
|
+
ChefRake::Task::Gem.new
|
@@ -0,0 +1,146 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Patrick Schaumburg (<pschaumburg@tecracer.de>)
|
3
|
+
# Author:: Thomas Heinen (<theinen@tecracer.de>)
|
4
|
+
# Copyright:: Copyright 2020, tecRacer Group
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
module ChefRake
|
21
|
+
module Task
|
22
|
+
include Rake::DSL if defined? Rake::DSL
|
23
|
+
class Package < ::Rake::TaskLib
|
24
|
+
def initialize
|
25
|
+
|
26
|
+
namespace :package do
|
27
|
+
desc 'Package cookbook as .tgz file'
|
28
|
+
task :cookbook do
|
29
|
+
# Berkshelf::Packager does not use chefignore, so a cleanup is necessary before
|
30
|
+
Rake::Task['clean:cookbook'].execute
|
31
|
+
|
32
|
+
require 'berkshelf'
|
33
|
+
current_dir = Rake.application.original_dir
|
34
|
+
metadata = Chef::Cookbook::Metadata.new
|
35
|
+
metadata.from_file File.join(current_dir, 'metadata.rb')
|
36
|
+
file_name = format('cookbook-%<name>s-%<version>s.tar.gz', metadata.to_hash.transform_keys(&:to_sym))
|
37
|
+
rel_path = File.join('pkg', file_name)
|
38
|
+
abs_path = File.join(current_dir, rel_path)
|
39
|
+
# Clean up and prepare
|
40
|
+
Dir.mkdir('pkg') unless Dir.exist?('pkg')
|
41
|
+
packager = Berkshelf::Packager.new abs_path
|
42
|
+
packager.run(current_dir)
|
43
|
+
printf("Cookbook(s) packaged to %s (size %d bytes)\n", rel_path, File.size(rel_path))
|
44
|
+
|
45
|
+
rescue StandardError => e
|
46
|
+
puts ">>> Gem load error: #{e}, omitting package" unless ENV['CI']
|
47
|
+
end
|
48
|
+
|
49
|
+
desc 'Package InSpec profile as .tgz file'
|
50
|
+
task :inspec do
|
51
|
+
# Berkshelf::Packager does not use chefignore, so a cleanup is necessary before
|
52
|
+
Rake::Task['clean:inspec'].execute
|
53
|
+
|
54
|
+
require 'inspec'
|
55
|
+
require 'train'
|
56
|
+
current_dir = Rake.application.original_dir
|
57
|
+
pkg_path = File.join(current_dir, 'pkg')
|
58
|
+
|
59
|
+
data = File.read(File.join(current_dir, 'inspec.yml'))
|
60
|
+
metadata = Inspec::Metadata.from_yaml(nil, data, nil)
|
61
|
+
metadata_as_hash = metadata.params.to_hash.transform_keys(&:to_sym)
|
62
|
+
file_name = format('inspecprofile-%<name>s-%<version>s.tar.gz', metadata_as_hash)
|
63
|
+
pkg_rel_path = File.join('pkg', file_name)
|
64
|
+
abs_path = File.join(current_dir, pkg_rel_path)
|
65
|
+
|
66
|
+
Dir.mkdir(pkg_path) unless Dir.exist?(pkg_path)
|
67
|
+
Dir.mkdir(ENV['HOME'] + '/.inspec/cache') unless Dir.exist?(ENV['HOME'] + '/.inspec/cache')
|
68
|
+
|
69
|
+
cmd = Train.create('local', command_runner: :generic).connection
|
70
|
+
command = 'inspec'
|
71
|
+
command << ' archive ' + current_dir
|
72
|
+
command << ' --overwrite'
|
73
|
+
command << ' --output ' + abs_path
|
74
|
+
# command << ' --vendor-cache=' + ENV['HOME'] + "/.inspec/cache" # looks like this has an error in main code
|
75
|
+
|
76
|
+
puts command
|
77
|
+
cmd.run_command(command)
|
78
|
+
|
79
|
+
printf("InSpec Profile(s) packaged to %s (size %d bytes)\n", abs_path, File.size(abs_path))
|
80
|
+
|
81
|
+
rescue StandardError => e
|
82
|
+
puts ">>> Gem load error: #{e}, omitting package" unless ENV['CI']
|
83
|
+
end
|
84
|
+
|
85
|
+
namespace :policyfile do
|
86
|
+
desc 'Generate new policyfile lock'
|
87
|
+
task :install do
|
88
|
+
# Rake::Task["clean:policyfile"].execute
|
89
|
+
current_dir = Rake.application.original_dir
|
90
|
+
|
91
|
+
require 'chef-cli/cli'
|
92
|
+
policyfile_rel_path = 'Policyfile.rb'
|
93
|
+
policyfile_full_path = File.expand_path(policyfile_rel_path, current_dir)
|
94
|
+
|
95
|
+
cli = ChefCLI::CLI.new(['install', policyfile_full_path])
|
96
|
+
subcommand_name, *subcommand_params = cli.argv
|
97
|
+
subcommand = cli.instantiate_subcommand(subcommand_name)
|
98
|
+
subcommand.run_with_default_options(subcommand_params)
|
99
|
+
|
100
|
+
rescue StandardError => e
|
101
|
+
puts ">>> Gem load error: #{e}, omitting package" unless ENV['CI']
|
102
|
+
end
|
103
|
+
|
104
|
+
desc 'Update current policyfile.lock.json'
|
105
|
+
task :update do
|
106
|
+
current_dir = Rake.application.original_dir
|
107
|
+
require 'chef-cli/cli'
|
108
|
+
|
109
|
+
policyfile_rel_path = 'Policyfile.rb'
|
110
|
+
policyfile_full_path = File.expand_path(policyfile_rel_path, current_dir)
|
111
|
+
|
112
|
+
cli = ChefCLI::CLI.new(['update', policyfile_full_path])
|
113
|
+
|
114
|
+
subcommand_name, *subcommand_params = cli.argv
|
115
|
+
subcommand = cli.instantiate_subcommand(subcommand_name)
|
116
|
+
subcommand.run_with_default_options(subcommand_params)
|
117
|
+
|
118
|
+
rescue StandardError => e
|
119
|
+
puts ">>> Gem load error: #{e}, omitting package" unless ENV['CI']
|
120
|
+
end
|
121
|
+
|
122
|
+
desc 'Pack current policyfile.lock.json'
|
123
|
+
task :pack do
|
124
|
+
current_dir = Rake.application.original_dir
|
125
|
+
|
126
|
+
require 'chef-cli/cli'
|
127
|
+
policyfile_rel_path = 'Policyfile.rb'
|
128
|
+
policyfile_full_path = File.expand_path(policyfile_rel_path, current_dir)
|
129
|
+
|
130
|
+
cli = ChefCLI::CLI.new(['update', policyfile_full_path])
|
131
|
+
|
132
|
+
subcommand_name, *subcommand_params = cli.argv
|
133
|
+
subcommand = cli.instantiate_subcommand(subcommand_name)
|
134
|
+
subcommand.run_with_default_options(subcommand_params)
|
135
|
+
|
136
|
+
rescue StandardError => e
|
137
|
+
puts ">>> Gem load error: #{e}, omitting package" unless ENV['CI']
|
138
|
+
end
|
139
|
+
end # namespace policyfile
|
140
|
+
end # namespace package
|
141
|
+
end # def initialize
|
142
|
+
end # class Package
|
143
|
+
end # module RakeTasks
|
144
|
+
end # module Chef
|
145
|
+
|
146
|
+
ChefRake::Task::Package.new
|
@@ -0,0 +1,97 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Patrick Schaumburg (<pschaumburg@tecracer.de>)
|
3
|
+
# Copyright:: Copyright 2020, tecRacer Group
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
module ChefRake
|
20
|
+
module Task
|
21
|
+
include Rake::DSL if defined? Rake::DSL
|
22
|
+
class Release < ::Rake::TaskLib
|
23
|
+
def initialize
|
24
|
+
|
25
|
+
namespace :release do
|
26
|
+
desc 'Upload to Artifactory'
|
27
|
+
task :artifactory, [:endpoint, :apikey, :repokey, :path] do |_t, args|
|
28
|
+
Rake::Task['package:cookbook'].execute
|
29
|
+
|
30
|
+
require 'berkshelf'
|
31
|
+
current_dir = Rake.application.original_dir
|
32
|
+
metadata = Chef::Cookbook::Metadata.new
|
33
|
+
metadata.from_file File.join(current_dir, 'metadata.rb')
|
34
|
+
file_name = format('cookbook-%<name>s-%<version>s.tar.gz', metadata.to_hash.transform_keys(&:to_sym))
|
35
|
+
rel_path = File.join('pkg', file_name)
|
36
|
+
abs_path = File.join(current_dir, rel_path)
|
37
|
+
|
38
|
+
require 'artifactory'
|
39
|
+
Artifactory.endpoint = args.endpoint # @TODO: Remove trailing slash, if exist
|
40
|
+
Artifactory.api_key = args.apikey
|
41
|
+
targetpath = args.path + '/' + file_name
|
42
|
+
|
43
|
+
artifact = Artifactory::Resource::Artifact.new(local_path: abs_path)
|
44
|
+
upload = artifact.upload(args.repokey, targetpath)
|
45
|
+
|
46
|
+
printf("Cookbook released to %s (size %d bytes)\n", upload.uri, upload.size)
|
47
|
+
printf("SHA256 Checksum: %s\n", upload.checksums['sha256'])
|
48
|
+
|
49
|
+
rescue StandardError => e
|
50
|
+
puts ">>> Gem load error: #{e}, omitting package" unless ENV['CI']
|
51
|
+
end
|
52
|
+
|
53
|
+
desc 'Upload to Chef Server'
|
54
|
+
task :chefserver do
|
55
|
+
Rake::Task['clean:cookbook'].execute
|
56
|
+
|
57
|
+
require 'berkshelf'
|
58
|
+
current_dir = Rake.application.original_dir
|
59
|
+
parent_dir = File.expand_path('..', current_dir)
|
60
|
+
metadata = Chef::Cookbook::Metadata.new
|
61
|
+
metadata.from_file File.join(current_dir, 'metadata.rb')
|
62
|
+
|
63
|
+
cmd = "knife cookbook upload #{metadata.name} --freeze"
|
64
|
+
cmd << " --cookbook-path #{parent_dir}"
|
65
|
+
sh cmd
|
66
|
+
|
67
|
+
rescue StandardError => e
|
68
|
+
puts ">>> Gem load error: #{e}, omitting package" unless ENV['CI']
|
69
|
+
end
|
70
|
+
|
71
|
+
desc 'Upload to Chef Supermarket'
|
72
|
+
task :supermarket do
|
73
|
+
Rake::Task['clean:cookbook'].execute
|
74
|
+
|
75
|
+
require 'berkshelf'
|
76
|
+
current_dir = Rake.application.original_dir
|
77
|
+
parent_dir = File.expand_path('..', current_dir)
|
78
|
+
metadata = Chef::Cookbook::Metadata.new
|
79
|
+
metadata.from_file File.join(current_dir, 'metadata.rb')
|
80
|
+
|
81
|
+
cmd = "knife supermarket share #{metadata.name}"
|
82
|
+
cmd << " --cookbook-path #{parent_dir}"
|
83
|
+
sh cmd
|
84
|
+
|
85
|
+
# require 'chef/mixin/shell_out'
|
86
|
+
# require 'chef/knife/supermarket_share'
|
87
|
+
|
88
|
+
rescue StandardError => e
|
89
|
+
puts ">>> Gem load error: #{e}, omitting package" unless ENV['CI']
|
90
|
+
end
|
91
|
+
end # namespace release
|
92
|
+
end # def initialize
|
93
|
+
end # class Release
|
94
|
+
end # module RakeTasks
|
95
|
+
end # module Chef
|
96
|
+
|
97
|
+
ChefRake::Task::Release.new
|
@@ -0,0 +1,107 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Patrick Schaumburg (<pschaumburg@tecracer.de>)
|
3
|
+
# Author:: Thomas Heinen (<theinen@tecracer.de>)
|
4
|
+
# Copyright:: Copyright 2020, tecRacer Group
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
module ChefRake
|
21
|
+
module Task
|
22
|
+
include Rake::DSL if defined? Rake::DSL
|
23
|
+
class Test < ::Rake::TaskLib
|
24
|
+
def initialize
|
25
|
+
|
26
|
+
namespace :test do
|
27
|
+
desc 'Run all integration tests'
|
28
|
+
task integration: %i[
|
29
|
+
integration:ec2
|
30
|
+
integration:physical
|
31
|
+
integration:vagrant
|
32
|
+
integration:vcenter
|
33
|
+
]
|
34
|
+
|
35
|
+
namespace :integration do
|
36
|
+
def kitchen_instances(regexp, config)
|
37
|
+
# Gets a collection of instances.
|
38
|
+
#
|
39
|
+
# @param regexp [String] regular expression to match against instance names.
|
40
|
+
# @param config [Hash] configuration values for the `Kitchen::Config` class.
|
41
|
+
# @return [Collection<Instance>] all instances.
|
42
|
+
active_config = Kitchen::Config.new(config)
|
43
|
+
# If we are in CI mode then add formatter options (@refactor)
|
44
|
+
kitchen_config = active_config.send(:data).send(:data)
|
45
|
+
|
46
|
+
if ENV['CI']
|
47
|
+
kitchen_config[:verifier][:reporter] = ['junit:reports/integration/inspec_%{platform}_%{suite}.xml']
|
48
|
+
end
|
49
|
+
|
50
|
+
instances = active_config.instances
|
51
|
+
return instances if regexp.nil? || regexp == 'all'
|
52
|
+
|
53
|
+
instances.get_all(Regexp.new(regexp))
|
54
|
+
end
|
55
|
+
|
56
|
+
def run_kitchen(action, regexp, loader_config = {})
|
57
|
+
# Runs a test kitchen action against some instances.
|
58
|
+
#
|
59
|
+
# @param action [String] kitchen action to run (defaults to `'test'`).
|
60
|
+
# @param regexp [String] regular expression to match against instance names.
|
61
|
+
# @param loader_config [Hash] loader configuration options.
|
62
|
+
# @return void
|
63
|
+
action = 'test' if action.nil?
|
64
|
+
require 'kitchen'
|
65
|
+
Kitchen.logger = Kitchen.default_file_logger
|
66
|
+
config = { loader: Kitchen::Loader::YAML.new(loader_config) }
|
67
|
+
kitchen_instances(regexp, config).each { |i| i.send(action) }
|
68
|
+
rescue StandardError
|
69
|
+
# Clean up on any error
|
70
|
+
kitchen_instances(regexp, config).each { |i| i.send('destroy') }
|
71
|
+
end
|
72
|
+
|
73
|
+
desc 'Run integration tests on AWS EC2'
|
74
|
+
task :ec2, [:regexp, :action] do |_t, args|
|
75
|
+
run_kitchen(args.action, args.regexp, local_config: '.kitchen.ec2.yml')
|
76
|
+
end
|
77
|
+
|
78
|
+
desc 'Run integration tests using static IPs'
|
79
|
+
task :static, [:regexp, :action] do |_t, args|
|
80
|
+
run_kitchen(args.action, args.regexp, local_config: '.kitchen.static.yml')
|
81
|
+
end
|
82
|
+
|
83
|
+
desc 'Run integration tests locally with vagrant'
|
84
|
+
task :vagrant, [:regexp, :action] do |_t, args|
|
85
|
+
run_kitchen(args.action, args.regexp, local_config: '.kitchen.vagrant.yml')
|
86
|
+
end
|
87
|
+
|
88
|
+
desc 'Run integration tests using vCenter'
|
89
|
+
task :vcenter, [:regexp, :action] do |_t, args|
|
90
|
+
run_kitchen(args.action, args.regexp, local_config: '.kitchen.vcenter.yml')
|
91
|
+
end
|
92
|
+
end # namespace integration
|
93
|
+
|
94
|
+
namespace :lint do
|
95
|
+
desc 'Run linting tests for cookbook'
|
96
|
+
task :cookbook do
|
97
|
+
puts 'running cookstyle for cookbook'
|
98
|
+
puts `cookstyle`
|
99
|
+
end
|
100
|
+
end # namespace lint
|
101
|
+
end # namespace test
|
102
|
+
end # def initialize
|
103
|
+
end # class Test
|
104
|
+
end # module RakeTasks
|
105
|
+
end # module Chef
|
106
|
+
|
107
|
+
ChefRake::Task::Test.new
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Patrick Schaumburg (<pschaumburg@tecracer.de>)
|
3
|
+
# Copyright:: Copyright 2020, tecRacer Group
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
module ChefRake
|
20
|
+
module Task
|
21
|
+
VERSION = '0.1.0'.freeze
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chef-raketasks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Patrick Schaumburg
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-04-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mdl
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.4'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop-rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.18'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.18'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: berkshelf
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '7.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '7.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: parse_gemspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '13.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '13.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.9'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.9'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: yard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.9'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.9'
|
111
|
+
description: Provides a central repository of the most essential tasks
|
112
|
+
email:
|
113
|
+
- pschaumburg@tecracer.de
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- CHANGELOG.md
|
119
|
+
- README.md
|
120
|
+
- lib/chef-raketasks.rb
|
121
|
+
- lib/chef/raketasks/clean.rb
|
122
|
+
- lib/chef/raketasks/doc.rb
|
123
|
+
- lib/chef/raketasks/gem.rb
|
124
|
+
- lib/chef/raketasks/package.rb
|
125
|
+
- lib/chef/raketasks/release.rb
|
126
|
+
- lib/chef/raketasks/test.rb
|
127
|
+
- lib/chef/raketasks/version.rb
|
128
|
+
homepage: https://www.tecracer.de
|
129
|
+
licenses:
|
130
|
+
- Apache-2.0
|
131
|
+
metadata: {}
|
132
|
+
post_install_message: Add `require 'chef-raketasks'` to your `Rakefile`.
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '2.5'
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubygems_version: 3.0.3
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
150
|
+
summary: Collection of reusable Rake tasks for Chef
|
151
|
+
test_files: []
|