kitchen-chef_zero_berks_env 1.1.0 → 1.1.1

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTk4NjZlOTk3NjM4YWQ1YmI4MTk1ZmJiNmI2YTk0YWU3NWExZWRjOA==
4
+ MjdiYmRkMTYzZTEzY2FkZGVmMTEyNjJmZGQyYzBmYzZhM2E1MjIwMg==
5
5
  data.tar.gz: !binary |-
6
- MWM4M2RmYWRiN2M3NmYyMTZhMmMwNzYyMjIzMTU5NzEwOTRjNzc3Mg==
6
+ MjI5OWU3MGU0MDM3NjZjZmMwNjhiOGY4MWQxNmVhMDBjOGI4OTk2YQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NjExMzg4Y2IyNjBkMDUyMmRjMWY5ZDZiZDg1NjRjYzk1N2M1ZGIyYjdiMmUw
10
- YzgzYmJiMmRiYzhiYWQ0OTcxYjRlOTEyZjI1MjAzMWZlYTRmNzBjZjE5MGM3
11
- YWNkMTFmZGM3NWNhMzU3MjRiOTgzNWIzYmI2ZGM5NjZhNThhM2M=
9
+ MjllYjQwZTM4ODFiYTAyZDY5NGE1YzFjZjAzOGM1NDM0YTEzNDI0ZjdjMTEy
10
+ YWE1ZDY1NjFlNmI1NGVlMGQ1Y2I1ODJkMjllODcxMWNlYTE1NDY0ZGQ4MTJj
11
+ NGNjMDhlZTFlMDJmODM5YTJhZGQyYWIxZDhmYzFmMjc1NGEyNzE=
12
12
  data.tar.gz: !binary |-
13
- MGE4NmQxMDg3NWNhZDc3MTg1MjczYzMyMjhkYThhYTZmYThiOGNlODcwNjlk
14
- NzJmMGQxYmE2OTkyZDRlYWE3ZjUwYTk1MDc0ZGYwNzU4NGZlMDg4ZWNlNDRm
15
- OTgxYTgxMjM5ZTYwODI5MDhhMWM0NTdmMzY3MTE5YTIwNWE0OTM=
13
+ MGM5Mjk5ZTI0MWVkOGYyOWZhYzQ0Y2U1YTgwMGExOTI1MjdmNDI5YjMwZWIz
14
+ MDhhODhhYTMxMzM1NDI0MWE4MGZjMWY3MDc4MzNlYTdlMTk3NDdkNWViZDcx
15
+ YTU2Y2NkMmM3YTI1N2EyYWIxM2ZhMWUyZDI0ZjZmYjk5NzhmMTM=
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # kitchen-chef_zero_berks_env
2
2
 
3
+ ## v1.1.1 (2015-09-21)
4
+
5
+ Bugfixes.
6
+
3
7
  ## v1.1.0 (2015-09-21)
4
8
 
5
9
  New feature: Added config option `environments_repo`.
@@ -1,94 +1,23 @@
1
- # -*- coding: utf-8 -*-
1
+ # -*- encoding: utf-8 -*-
2
2
 
3
3
  require 'kitchen/provisioner/chef_zero'
4
- require 'git'
4
+ require 'kitchen/provisioner/sandbox_berks_env'
5
5
 
6
6
  module Kitchen
7
7
  module Provisioner
8
- # Tweaked Chef Zero provisioner that enables Berkshelf to load
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
- # Performs a Berkshelf cookbook resolution inside a common mutex.
14
- #
15
- # @api private
16
- def resolve_with_berkshelf
17
- # Load Berksfile
18
- berks = ::Berkshelf::Berksfile.from_file(berksfile)
19
-
20
- chef_environment = config[:client_rb][:environment]
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.0
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: