kitchen-chef_zero_berks_env 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +4 -0
- data/lib/kitchen/provisioner/chef_zero_berks_env.rb +12 -83
- data/lib/kitchen/provisioner/sandbox_berks_env.rb +96 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjdiYmRkMTYzZTEzY2FkZGVmMTEyNjJmZGQyYzBmYzZhM2E1MjIwMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MjI5OWU3MGU0MDM3NjZjZmMwNjhiOGY4MWQxNmVhMDBjOGI4OTk2YQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MjllYjQwZTM4ODFiYTAyZDY5NGE1YzFjZjAzOGM1NDM0YTEzNDI0ZjdjMTEy
|
10
|
+
YWE1ZDY1NjFlNmI1NGVlMGQ1Y2I1ODJkMjllODcxMWNlYTE1NDY0ZGQ4MTJj
|
11
|
+
NGNjMDhlZTFlMDJmODM5YTJhZGQyYWIxZDhmYzFmMjc1NGEyNzE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MGM5Mjk5ZTI0MWVkOGYyOWZhYzQ0Y2U1YTgwMGExOTI1MjdmNDI5YjMwZWIz
|
14
|
+
MDhhODhhYTMxMzM1NDI0MWE4MGZjMWY3MDc4MzNlYTdlMTk3NDdkNWViZDcx
|
15
|
+
YTU2Y2NkMmM3YTI1N2EyYWIxM2ZhMWUyZDI0ZjZmYjk5NzhmMTM=
|
data/CHANGELOG.md
CHANGED
@@ -1,94 +1,23 @@
|
|
1
|
-
# -*-
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
3
|
require 'kitchen/provisioner/chef_zero'
|
4
|
-
require '
|
4
|
+
require 'kitchen/provisioner/sandbox_berks_env'
|
5
5
|
|
6
6
|
module Kitchen
|
7
7
|
module Provisioner
|
8
|
-
#
|
9
|
-
# cookbook restrictions from Chef environments.
|
8
|
+
# Chef Zero Berkshelf Environment provisioner.
|
10
9
|
#
|
11
10
|
# @author Mario Santos <mario.rf.santos@gmail.com>
|
12
11
|
class ChefZeroBerksEnv < ChefZero
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
# skip if the environment was not specified
|
23
|
-
unless chef_environment.nil?
|
24
|
-
unless config[:environments_repo].nil?
|
25
|
-
config[:environments_path] = environments_path_from_git(config[:environments_repo])
|
26
|
-
end
|
27
|
-
info("Loading chef environment '#{chef_environment}'...")
|
28
|
-
lock_berksfile(berks, cookbook_versions("#{config[:environments_path]}/#{chef_environment}.json"))
|
29
|
-
end
|
30
|
-
Kitchen.mutex.synchronize do
|
31
|
-
info("Resolving cookbook dependencies with Berkshelf #{::Berkshelf::VERSION}...")
|
32
|
-
debug("Using Berksfile from #{berksfile}")
|
33
|
-
|
34
|
-
::Berkshelf.ui.mute do
|
35
|
-
if ::Berkshelf::Berksfile.method_defined?(:vendor)
|
36
|
-
# Berkshelf 3.0 requires the directory to not exist
|
37
|
-
FileUtils.rm_rf(tmpbooks_dir)
|
38
|
-
berks.vendor(tmpbooks_dir)
|
39
|
-
else
|
40
|
-
berks.install(path => tmpbooks_dir)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
# Fetches a git repo to a temporary directory
|
47
|
-
#
|
48
|
-
# @param args [String] git repo
|
49
|
-
# @return [String] the environments_path directory
|
50
|
-
# @api private
|
51
|
-
def environments_path_from_git(repo)
|
52
|
-
info("Fetching chef environments from repo '#{repo}'...")
|
53
|
-
tmpenv_dir = Dir.mktmpdir('environments-')
|
54
|
-
Git.clone(repo, 'chef_env', path: tmpenv_dir, depth: 1)
|
55
|
-
"#{tmpenv_dir}/chef_env"
|
56
|
-
end
|
57
|
-
|
58
|
-
# Gets the cookbook version restrictions from a chef environment
|
59
|
-
#
|
60
|
-
# @param [String] chef environment path
|
61
|
-
# @return [Hash] cookbook versions
|
62
|
-
# @api private
|
63
|
-
def cookbook_versions(json_path)
|
64
|
-
info("Using environment from '#{json_path}'")
|
65
|
-
JSON.parse(File.read("#{json_path}"))['cookbook_versions']
|
66
|
-
end
|
67
|
-
|
68
|
-
# Locks the cookbook versions into Berksfile.lock
|
69
|
-
#
|
70
|
-
# @param [Berksfile] berksfile to lock
|
71
|
-
# @param [Hash] cookbook versions
|
72
|
-
# @api private
|
73
|
-
def lock_berksfile(berksfile, cookbook_versions)
|
74
|
-
::Berkshelf.ui.mute do
|
75
|
-
info("Resolving dependency graph with Berkshelf #{::Berkshelf::VERSION}...")
|
76
|
-
berksfile.install
|
77
|
-
unless cookbook_versions.nil?
|
78
|
-
berksfile.lockfile.graph.each do |graphitem|
|
79
|
-
version = cookbook_versions[graphitem.name]
|
80
|
-
unless version.nil? || berksfile.has_dependency?(graphitem.name)
|
81
|
-
info("Adding Berkshelf dependency: #{graphitem.name} (#{version})")
|
82
|
-
berksfile.add_dependency(graphitem.name, version)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
# update the lockfile
|
86
|
-
berksfile.update
|
87
|
-
berksfile.lockfile.graph.update(berksfile.install)
|
88
|
-
berksfile.lockfile.update(berksfile.dependencies)
|
89
|
-
berksfile.lockfile.save
|
90
|
-
end
|
91
|
-
end
|
12
|
+
def create_sandbox
|
13
|
+
@sandbox_path = Dir.mktmpdir("#{instance.name}-sandbox-")
|
14
|
+
File.chmod(0755, sandbox_path)
|
15
|
+
info('Preparing files for transfer')
|
16
|
+
debug("Creating local sandbox in #{sandbox_path}")
|
17
|
+
SandboxBerksEnv.new(config, sandbox_path, instance).populate
|
18
|
+
prepare_chef_client_zero_rb
|
19
|
+
prepare_validation_pem
|
20
|
+
prepare_client_rb
|
92
21
|
end
|
93
22
|
end
|
94
23
|
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'kitchen/provisioner/chef/common_sandbox'
|
4
|
+
require 'git'
|
5
|
+
|
6
|
+
module Kitchen
|
7
|
+
module Provisioner
|
8
|
+
# Internal object to manage sandbox preparation for
|
9
|
+
# Chef Zero Berkshelf Environment.
|
10
|
+
#
|
11
|
+
# @author Mario Santos <mario.rf.santos@gmail.com>
|
12
|
+
# @api private
|
13
|
+
class SandboxBerksEnv < Chef::CommonSandbox
|
14
|
+
# Performs a Berkshelf cookbook resolution inside a common mutex.
|
15
|
+
#
|
16
|
+
# @api private
|
17
|
+
def resolve_with_berkshelf
|
18
|
+
# Load Berksfile
|
19
|
+
berks = ::Berkshelf::Berksfile.from_file(berksfile)
|
20
|
+
|
21
|
+
chef_environment = config[:client_rb][:environment]
|
22
|
+
|
23
|
+
# skip if the environment was not specified
|
24
|
+
unless chef_environment.nil?
|
25
|
+
unless config[:environments_repo].nil?
|
26
|
+
config[:environments_path] = environments_path_from_git(config[:environments_repo])
|
27
|
+
end
|
28
|
+
info("Loading chef environment '#{chef_environment}'...")
|
29
|
+
lock_berksfile(berks, cookbook_versions("#{config[:environments_path]}/#{chef_environment}.json"))
|
30
|
+
end
|
31
|
+
Kitchen.mutex.synchronize do
|
32
|
+
info("Resolving cookbook dependencies with Berkshelf #{::Berkshelf::VERSION}...")
|
33
|
+
debug("Using Berksfile from #{berksfile}")
|
34
|
+
|
35
|
+
::Berkshelf.ui.mute do
|
36
|
+
if ::Berkshelf::Berksfile.method_defined?(:vendor)
|
37
|
+
# Berkshelf 3.0 requires the directory to not exist
|
38
|
+
FileUtils.rm_rf(tmpbooks_dir)
|
39
|
+
berks.vendor(tmpbooks_dir)
|
40
|
+
else
|
41
|
+
berks.install(path => tmpbooks_dir)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Fetches a git repo to a temporary directory
|
48
|
+
#
|
49
|
+
# @param args [String] git repo
|
50
|
+
# @return [String] the environments_path directory
|
51
|
+
# @api private
|
52
|
+
def environments_path_from_git(repo)
|
53
|
+
info("Fetching chef environments from repo '#{repo}'...")
|
54
|
+
tmpenv_dir = Dir.mktmpdir('environments-')
|
55
|
+
Git.clone(repo, 'chef_env', path: tmpenv_dir, depth: 1)
|
56
|
+
"#{tmpenv_dir}/chef_env"
|
57
|
+
end
|
58
|
+
|
59
|
+
# Gets the cookbook version restrictions from a chef environment
|
60
|
+
#
|
61
|
+
# @param [String] chef environment path
|
62
|
+
# @return [Hash] cookbook versions
|
63
|
+
# @api private
|
64
|
+
def cookbook_versions(json_path)
|
65
|
+
info("Using environment from '#{json_path}'")
|
66
|
+
JSON.parse(File.read("#{json_path}"))['cookbook_versions']
|
67
|
+
end
|
68
|
+
|
69
|
+
# Locks the cookbook versions into Berksfile.lock
|
70
|
+
#
|
71
|
+
# @param [Berksfile] berksfile to lock
|
72
|
+
# @param [Hash] cookbook versions
|
73
|
+
# @api private
|
74
|
+
def lock_berksfile(berksfile, cookbook_versions)
|
75
|
+
::Berkshelf.ui.mute do
|
76
|
+
info("Resolving dependency graph with Berkshelf #{::Berkshelf::VERSION}...")
|
77
|
+
berksfile.install
|
78
|
+
unless cookbook_versions.nil?
|
79
|
+
berksfile.lockfile.graph.each do |graphitem|
|
80
|
+
version = cookbook_versions[graphitem.name]
|
81
|
+
unless version.nil? || berksfile.has_dependency?(graphitem.name)
|
82
|
+
info("Adding Berkshelf dependency: #{graphitem.name} (#{version})")
|
83
|
+
berksfile.add_dependency(graphitem.name, version)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
# update the lockfile
|
87
|
+
berksfile.update
|
88
|
+
berksfile.lockfile.graph.update(berksfile.install)
|
89
|
+
berksfile.lockfile.update(berksfile.dependencies)
|
90
|
+
berksfile.lockfile.save
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kitchen-chef_zero_berks_env
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mário Santos
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- LICENSE
|
81
81
|
- README.md
|
82
82
|
- lib/kitchen/provisioner/chef_zero_berks_env.rb
|
83
|
+
- lib/kitchen/provisioner/sandbox_berks_env.rb
|
83
84
|
- lib/kitchen_chef_zero_berks_env.rb
|
84
85
|
homepage: https://github.com/ruizink/kitchen-chef_zero_berks_env
|
85
86
|
licenses:
|