clc-promote 0.1.4 → 0.2.0.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe800d49579f78d5f25faf255f23d48415f153c0
4
- data.tar.gz: bf16f163d2d0e64d93988d66164e4acdaacc9b81
3
+ metadata.gz: 24e8944f0082aa895bf69fff09a1016943e6b212
4
+ data.tar.gz: c5e93da8c48ae3507e421ddd4a1185d4bdba2b31
5
5
  SHA512:
6
- metadata.gz: 95aab19d63d79dddfbe748a8ed13f295a2d13951740b8c28ecfb780c1cd58ff2c04ecf7f25a6ed522545e197cb25dc8d2123cb80bf0b662cefd335578fdf996c
7
- data.tar.gz: d578a8370523bf53ca4b32bec9c4167b6b44b760434f56d2cfb86440cedf723d05f9677e8a4db90ccc5f59d84b15d33564bd65666d9d28ba63c4d445e800b955
6
+ metadata.gz: cfe6919ce0b01abdb44b7cfb777b3e5ad5fa5108295e44c38a5d183220be94d7548348e5e728686fd015ae779a7abc341aa4edb768da06b50d16ea0e014f0fc5
7
+ data.tar.gz: 833b9efee560ff24642a3d624638a799e31cb83a5f91ea1c3dffd43bf074f6a9d05545c5e718fd32e3adb7113abc51d2ace8f4aac03c74b8a941111c0d75d702
@@ -9,6 +9,7 @@ module Promote
9
9
  config = Config.new(config) if config.is_a?(Hash)
10
10
  config = Config.new({ :repo_root => config }) if config.is_a?(String)
11
11
  @versioner = Versioner.new(config)
12
+ @uploader = Uploader.new(config)
12
13
  yield self if block_given?
13
14
  define_version_cookbook
14
15
  define_version_cookbooks
@@ -16,6 +17,10 @@ module Promote
16
17
  define_version_environments
17
18
  define_version_data_bag
18
19
  define_version_data_bags
20
+ define_upload_cookbooks
21
+ define_upload_environment
22
+ define_upload_data_bags
23
+ define_constrain_environment
19
24
  end
20
25
 
21
26
  private
@@ -34,6 +39,7 @@ module Promote
34
39
  namespace "Promote" do
35
40
  desc "Version all cookbooks"
36
41
  task "version_cookbooks" do
42
+ puts "Version stamping cookbooks and syncing berksfile.locks..."
37
43
  @versioner.version_cookbooks.each do |result|
38
44
  puts "Versioned cookbook: #{result[:cookbook]} v#{result[:version]}"
39
45
  end
@@ -50,10 +56,24 @@ module Promote
50
56
  end
51
57
  end
52
58
 
59
+ def define_constrain_environment
60
+ namespace "Promote" do
61
+ desc "Constrain the cookbook versions of an environment"
62
+ task "constrain_environment", :environment, :environment_cookbook do |task, args|
63
+ puts "Checking for cookbok constraints for the #{args.environment} environment using the #{args.environment_cookbook} cookbook..."
64
+ deps = @versioner.constrain_environment(args.environment, args.environment_cookbook)
65
+ deps.each do |dep|
66
+ puts "#{dep.name} -> #{dep.locked_version.to_s}"
67
+ end
68
+ end
69
+ end
70
+ end
71
+
53
72
  def define_version_environments
54
73
  namespace "Promote" do
55
74
  desc "Version all environments"
56
75
  task "version_environments" do
76
+ puts "Version stamping changed environments..."
57
77
  @versioner.version_environments.each do |result|
58
78
  puts "Versioned environment: #{result[:artifact]} v#{result[:version]}"
59
79
  end
@@ -74,6 +94,7 @@ module Promote
74
94
  namespace "Promote" do
75
95
  desc "Version all data_bags"
76
96
  task "version_data_bags" do
97
+ puts "Version stamping changed data_bags..."
77
98
  @versioner.version_data_bags.each do |result|
78
99
  puts "Versioned data_bag: #{result[:artifact]} v#{result[:version]}"
79
100
  end
@@ -85,9 +106,28 @@ module Promote
85
106
  namespace "Promote" do
86
107
  desc "Upload all cookbooks to chef server"
87
108
  task "upload_cookbooks" do
88
- @uploader.upload_cookbooks.each do |result|
89
- #puts "Versioned cookbook: #{result[:cookbook]} v#{result[:version]}"
90
- end
109
+ puts "Uploading cookbooks not already on server..."
110
+ @uploader.upload_cookbooks
111
+ end
112
+ end
113
+ end
114
+
115
+ def define_upload_environment
116
+ namespace "Promote" do
117
+ desc "Upload an environment to the chef server"
118
+ task "upload_environment", :environment do |task, args|
119
+ puts "Uploading environment..."
120
+ @uploader.upload_environment(args.environment)
121
+ end
122
+ end
123
+ end
124
+
125
+ def define_upload_data_bags
126
+ namespace "Promote" do
127
+ desc "Upload data_bags to the chef server"
128
+ task "upload_data_bags" do |task, args|
129
+ puts "Uploading data_bags..."
130
+ @uploader.upload_data_bags
91
131
  end
92
132
  end
93
133
  end
@@ -1,33 +1,76 @@
1
1
  require 'chef'
2
+ require 'chef/chef_fs/knife'
3
+ require 'chef/chef_fs/parallelizer'
4
+ require 'chef/chef_fs/config'
5
+ require 'chef/chef_fs/file_pattern'
6
+ require 'chef/chef_fs/file_system'
7
+ require 'chef/config'
2
8
  require 'chef/knife/cookbook_upload'
9
+ require 'chef/chef_fs/path_utils'
10
+ require 'chef/knife/upload'
3
11
 
4
12
  module Promote
5
13
  class Uploader
6
14
  def initialize(config)
7
15
  @config = config
8
16
  validate_config
9
- end
10
-
11
- def upload_cookbook(cookbook_name)
12
- berks_name = File.join(config.cookbook_directory, cookbook_name, "Berksfile")
13
- upload_dir = config.cookbook_directory
14
- if File.exist?(berks_name)
15
- FileUtils.rm_rf(config.temp_directory) if Dir.exist?(config.temp_directory)
16
- berksfile = Berkshelf::Berksfile.from_file(berks_name)
17
- berksfile.vendor(config.temp_directory)
18
- upload_dir = config.temp_directory
19
- end
20
-
21
- knife = Chef::Knife::CookbookUpload.new()
22
17
  Chef::Config.reset
23
18
  Chef::Config[:client_key] = config.client_key
24
19
  Chef::Config[:chef_server_url] = config.chef_server_url
25
20
  Chef::Config[:node_name] = config.node_name
26
- knife.config[:all] = true
27
- knife.config[:cookbook_path] = upload_dir
28
- knife.run
29
21
  end
30
-
22
+
23
+ def upload_cookbooks
24
+ nothing_to_upload = true
25
+ rest = Chef::REST.new(config.chef_server_url, config.node_name, config.client_key)
26
+ server_cookbooks = rest.get_rest("/cookbooks?num_versions=all")
27
+ FileUtils.rm_rf(config.temp_directory) if Dir.exist?(config.temp_directory)
28
+ Dir.mkdir(config.temp_directory)
29
+ Dir.glob(File.expand_path("~/.berkshelf/cookbooks/*")).each do | dir |
30
+ cp_name = File.basename(dir)
31
+ idx = cp_name.rindex('-')
32
+ if !server_cookbooks.has_key?(cp_name[0,idx]) || (server_cookbooks[cp_name[0,idx]]["versions"].select {|v| v['version'] == cp_name[idx+1,cp_name.length-idx]}).empty?
33
+ FileUtils.copy_entry(dir, File.join(config.temp_directory, cp_name[0,idx]))
34
+ nothing_to_upload = false
35
+ end
36
+ end
37
+
38
+ Dir.glob(File.join(config.cookbook_directory, "*")).each do | dir |
39
+ metadata = Chef::Cookbook::Metadata.new
40
+ metadata.from_file(File.join(dir, "metadata.rb"))
41
+ if !server_cookbooks.has_key?(metadata.name) || (server_cookbooks[metadata.name]["versions"].select {|v| v['version'] == metadata.version}).empty?
42
+ FileUtils.copy_entry(dir, File.join(config.temp_directory, metadata.name))
43
+ nothing_to_upload = false
44
+ end
45
+ end
46
+
47
+ if !nothing_to_upload
48
+ knife = Chef::Knife::CookbookUpload.new()
49
+ knife.config[:all] = true
50
+ knife.config[:freeze] = true
51
+ knife.config[:cookbook_path] = config.temp_directory
52
+ knife.run
53
+ end
54
+ end
55
+
56
+ def upload_environment(environment_name)
57
+ knife = Chef::Knife::Upload.new(["/environments/#{environment_name}.json"])
58
+ knife.config[:chef_repo_path] = config.repo_root
59
+ Chef::ChefFS::Knife.deps do
60
+ knife.configure_chef
61
+ knife.run
62
+ end
63
+ end
64
+
65
+ def upload_data_bags
66
+ knife = Chef::Knife::Upload.new(["/data_bags"])
67
+ knife.config[:chef_repo_path] = config.repo_root
68
+ Chef::ChefFS::Knife.deps do
69
+ knife.configure_chef
70
+ knife.run
71
+ end
72
+ end
73
+
31
74
  attr_accessor :config
32
75
 
33
76
  private
@@ -47,6 +47,7 @@ module Promote
47
47
  cookbooks.each do |cookbook|
48
48
  berks_name = File.join(config.cookbook_directory, File.basename(cookbook), "Berksfile")
49
49
  if File.exist?(berks_name)
50
+ Berkshelf.set_format :null
50
51
  berksfile = Berkshelf::Berksfile.from_file(berks_name)
51
52
  berksfile.install
52
53
  end
@@ -87,6 +88,23 @@ module Promote
87
88
  results
88
89
  end
89
90
 
91
+ def constrain_environment(environment_name, cookbook_name)
92
+ berks_name = File.join(config.cookbook_directory, cookbook_name, "Berksfile")
93
+ berksfile = Berkshelf::Berksfile.from_file(berks_name)
94
+ dependencies = berksfile.list
95
+ env_file = File.join(config.environment_directory, "#{environment_name}.json")
96
+ content = JSON.parse(File.read(env_file))
97
+ content['cookbook_versions'] = {}
98
+ dependencies.each do | dep |
99
+ content['cookbook_versions'][dep.name] = dep.locked_version.to_s
100
+ end
101
+
102
+ File.open(env_file, 'w') do |out|
103
+ out << JSON.pretty_generate(content)
104
+ end
105
+ dependencies
106
+ end
107
+
90
108
  attr_accessor :config
91
109
 
92
110
  private
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clc-promote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - CenturyLink Cloud
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-19 00:00:00.000000000 Z
11
+ date: 2014-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: knife-spork
14
+ name: chef
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.4'
20
17
  - - ">="
21
18
  - !ruby/object:Gem::Version
22
- version: 1.4.1
19
+ version: '0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '1.4'
30
24
  - - ">="
31
25
  - !ruby/object:Gem::Version
32
- version: 1.4.1
26
+ version: '0'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: git
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -137,9 +131,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
137
131
  version: '0'
138
132
  required_rubygems_version: !ruby/object:Gem::Requirement
139
133
  requirements:
140
- - - ">="
134
+ - - ">"
141
135
  - !ruby/object:Gem::Version
142
- version: '0'
136
+ version: 1.3.1
143
137
  requirements: []
144
138
  rubyforge_project:
145
139
  rubygems_version: 2.2.1