sambot 0.1.203 → 0.1.204

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: 65f6e139502a03d29376143393f19b118a42dca6
4
- data.tar.gz: 6d99cdc59179bac7bf0ff536f40a851c226e78ed
3
+ metadata.gz: d7e5b98edfaa523588cba1182b154f6890eaf1e5
4
+ data.tar.gz: ba1f6b8202149555b974ae804c68336575c69f7a
5
5
  SHA512:
6
- metadata.gz: b4a4b0d75a6c2b33a0959bf5a2a006893d928de5111c5a85dab4eba84fda7fe0fd4e97eebafb50049e788eda5d2cd6120799f18c7d5773328f75ab5ab933c39d
7
- data.tar.gz: edfcda2c0b642ae8cb1c18c6aad07ccda74fb7db4f29ec49193d0a52740420c210f15d49d05ca5fa27dc88c12427dd5af4dbdf663f0fdeced8c9ea7968a092a4
6
+ metadata.gz: 054fd6f4d8e0488e5867916ce7e06e578fac3e73e41b8b3c68c5eb0ba11223cb6afad92e98a12af9111627c87d74400b56723cf23c0f3046af0924d432634470
7
+ data.tar.gz: 1647b8433eee09b90f35f9583f119a8bc400fe4f8928698f76213381ca8257498a0a8af07dbcc66d79c156c422f53da2afdeb1ac685f98bc4b36373f12ab1cbf
data/lib/sambot.rb CHANGED
@@ -9,6 +9,7 @@ require_relative 'sambot/runtime'
9
9
  require_relative 'sambot/version'
10
10
  require_relative 'sambot/template'
11
11
  require_relative 'sambot/fs'
12
+ require_relative 'sambot/source_control'
12
13
 
13
14
  require_relative 'sambot/testing/consul_helper'
14
15
  require_relative 'sambot/testing/vault_helper'
@@ -20,6 +21,7 @@ require_relative 'sambot/chef/hooks'
20
21
  require_relative 'sambot/chef/cookbook'
21
22
  require_relative 'sambot/chef/server'
22
23
  require_relative 'sambot/chef/generator'
24
+ require_relative 'sambot/chef/roles'
23
25
 
24
26
  require_relative 'sambot/cli'
25
27
 
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sambot
4
+ module Chef
5
+ class Roles
6
+
7
+ class << self
8
+
9
+ ROLE_COOKBOOK_ORGANIZATION = 'ads-role-cookbooks'
10
+ COOKBOOK_CONFIG = '.config.yml'
11
+
12
+ def pin_cookbook_version(dependency_name, version = nil, role_name = nil)
13
+ raise 'No dependency name provided' unless dependency_name
14
+ roles = role_name ? [role_name] : list_roles
15
+ roles.each do |role|
16
+ update_dependency_version(repository, dependency_name, version)
17
+ end
18
+ end
19
+
20
+ def update_dependency_version(repository, dependency_name, version)
21
+ file = SourceControl.get_file(ROLE_COOKBOOK_ORGANIZATION, repository, COOKBOOK_CONFIG)
22
+ config = update_config(file, dependency_name, version)
23
+ config ? apply_changes(config, repository, file) : false
24
+ end
25
+
26
+ def list_roles
27
+ SourceControl.list_organization_repositories(ROLE_COOKBOOK_ORGANIZATION)
28
+ end
29
+
30
+ def update_config(file, dependency, version)
31
+ body = Base64.decode64(file.content)
32
+ new_contents = body.lines.map do |line|
33
+ line.match(/^\s*- #{dependency}/) ? update_line(line, dependency, version) : line
34
+ end.join
35
+ new_contents == body.lines.join ? nil : new_contents
36
+ end
37
+
38
+ private
39
+
40
+ def update_line(val, dependency, version)
41
+ val
42
+ end
43
+
44
+ def apply_changes(contents, repository, file)
45
+ puts 'Not stubbed'
46
+ exit
47
+ msg = "Updated cookbook dependency #{dependency_name} to #{version}"
48
+ SourceControl.edit_file(ROLE_COOKBOOK_ORGANIZATION, repository, COOKBOOK_CONFIG, contents, file, msg)
49
+ return true
50
+ end
51
+
52
+ end
53
+ end
54
+ end
55
+ end
data/lib/sambot/cli.rb CHANGED
@@ -1,10 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'base_command'
4
+ require 'docker/compose'
4
5
 
5
6
  module Sambot
6
7
  class CLI < BaseCommand
7
8
 
9
+ desc 'checkout', 'Checks out or updates all the repositories in a given organization'
10
+ def checkout(organization, dir)
11
+ Dir.chdir(dir) do
12
+ SourceControl.checkout(organization)
13
+ end
14
+ end
15
+
8
16
  desc 'clean', 'Remove all generated build files from a Chef cookbook'
9
17
  def clean
10
18
  execute { Chef::Cookbook.clean }
@@ -86,6 +94,10 @@ module Sambot
86
94
  execute { puts "##teamcity[buildNumber '#{Config.read.version}']" }
87
95
  end
88
96
 
97
+ desc 'pin', 'Goes through role cookbooks and updates a wrapper cookbook version'
98
+ def pin
99
+ end
100
+
89
101
  no_commands do
90
102
 
91
103
  def populate_cmd
@@ -95,11 +107,13 @@ module Sambot
95
107
  end
96
108
 
97
109
  def down_cmd
98
- `docker-compose -p chef down`
110
+ compose = Docker::Compose.new
111
+ compose.down
99
112
  end
100
113
 
101
114
  def up_cmd
102
- `docker-compose -p chef up -d`
115
+ compose = Docker::Compose.new
116
+ compose.up(detached: true)
103
117
  end
104
118
 
105
119
  end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pry'
4
+ require 'github_api'
5
+ require 'git'
6
+
7
+ module Sambot
8
+ class SourceControl
9
+
10
+ class << self
11
+
12
+ ET_GITHUB_API = 'https://github.exacttarget.com/api/v3'
13
+ ET_GITHUB = 'https://github.exacttarget.com'
14
+
15
+ def checkout(organization)
16
+ repositories = list_organization_repositories(organization)
17
+ repositories.each do |repository|
18
+ if Dir.exist?(repository.name)
19
+ UI.info("#{repository.name} already exists and will be updated")
20
+ Dir.chdir(repository.name) do
21
+ `git pull`
22
+ end
23
+ else
24
+ `git clone #{repository.ssh_url}`
25
+ end
26
+ end
27
+ end
28
+
29
+ def list_organization_repositories(organization)
30
+ api.repos.list org: organization
31
+ end
32
+
33
+ def get_file(organization, repository, path)
34
+ contents_api.find user: organization, repo: repository, path: path
35
+ end
36
+
37
+ def edit_file(organization, repository, path, contents, file, msg)
38
+ contents_api.update organization, repository, path,
39
+ content: contents,
40
+ path: path,
41
+ message: msg,
42
+ sha: file.sha
43
+ end
44
+
45
+ private
46
+
47
+ def contents_api
48
+ api.repos.contents
49
+ end
50
+
51
+ def api
52
+ @github ||= Github.new do |c|
53
+ c.basic_auth = "#{ENV['GITHUB_USERNAME']}:#{ENV['GITHUB_PERSONAL_TOKEN']}"
54
+ c.endpoint = ET_GITHUB_API
55
+ c.site = ET_GITHUB
56
+ end
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sambot
4
- VERSION = '0.1.203'
4
+ VERSION = '0.1.204'
5
5
  end
data/sambot.gemspec CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency 'git', '~> 1.3'
24
24
  spec.add_dependency 'process_exists'
25
25
  spec.add_dependency 'climate_control'
26
+ spec.add_dependency 'github_api'
26
27
  spec.add_dependency 'vault'
27
28
  spec.add_dependency 'ridley'
28
29
  spec.add_dependency 'titan'
@@ -33,9 +34,10 @@ Gem::Specification.new do |spec|
33
34
  spec.add_dependency 'thor', '~> 0.19'
34
35
  spec.add_dependency 'erubis', '~> 2.7', '>= 2.7.0'
35
36
  spec.add_dependency 'gems', '~> 1.0', '>= 1.0.0'
36
- spec.add_dependency 'awesome_print'
37
+ spec.add_dependency 'awesome_print'
37
38
  spec.add_development_dependency 'pry'
38
39
  spec.add_development_dependency 'fuubar'
40
+ spec.add_development_dependency 'docker-compose'
39
41
  spec.add_development_dependency 'rubocop', '~> 0.49'
40
42
  spec.add_development_dependency 'gem-release', '~> 1.0'
41
43
  spec.add_development_dependency 'bundler'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sambot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.203
4
+ version: 0.1.204
5
5
  platform: ruby
6
6
  authors:
7
7
  - Olivier Kouame
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-27 00:00:00.000000000 Z
11
+ date: 2017-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor-hollaback
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: github_api
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: vault
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -260,6 +274,20 @@ dependencies:
260
274
  - - ">="
261
275
  - !ruby/object:Gem::Version
262
276
  version: '0'
277
+ - !ruby/object:Gem::Dependency
278
+ name: docker-compose
279
+ requirement: !ruby/object:Gem::Requirement
280
+ requirements:
281
+ - - ">="
282
+ - !ruby/object:Gem::Version
283
+ version: '0'
284
+ type: :development
285
+ prerelease: false
286
+ version_requirements: !ruby/object:Gem::Requirement
287
+ requirements:
288
+ - - ">="
289
+ - !ruby/object:Gem::Version
290
+ version: '0'
263
291
  - !ruby/object:Gem::Dependency
264
292
  name: rubocop
265
293
  requirement: !ruby/object:Gem::Requirement
@@ -374,6 +402,7 @@ files:
374
402
  - lib/sambot/chef/hooks.rb
375
403
  - lib/sambot/chef/kitchen.rb
376
404
  - lib/sambot/chef/metadata.rb
405
+ - lib/sambot/chef/roles.rb
377
406
  - lib/sambot/chef/server.rb
378
407
  - lib/sambot/cli.rb
379
408
  - lib/sambot/config.rb
@@ -385,6 +414,7 @@ files:
385
414
  - lib/sambot/docs/version.txt
386
415
  - lib/sambot/fs.rb
387
416
  - lib/sambot/runtime.rb
417
+ - lib/sambot/source_control.rb
388
418
  - lib/sambot/template.rb
389
419
  - lib/sambot/templates/.config.yml.erb
390
420
  - lib/sambot/templates/.env