lambda-version-manager 0.0.13 → 0.0.18

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 956f8eec69ae5cd6730d7e4a61a5dd98e90fa8af
4
- data.tar.gz: cf2597c815b9a37eeb5778fec66fe2810b716435
3
+ metadata.gz: a06023537b8e81252217196c3273da36f59c5dff
4
+ data.tar.gz: aab71c5d45d1a99e9dabd484dd154783b983144b
5
5
  SHA512:
6
- metadata.gz: a9bcbf3f8e310b63db6b1151bc9eba8d51f3888a492d8a5121a319bafd348766315d7327b22bb9160ed0e026a9b3f1931bd3a5e365dd2d7ee61a176f75ad457f
7
- data.tar.gz: 5a45b8da5fa4bd410ffad070b1ded3b91beaa17edf0db64728a1c9640e6c36c77f38459f889701aca8b0e8c0ac4066fd2b69c20a8d4676a1b21c24518ee8b910
6
+ metadata.gz: 64103478875e2d14a67baec6327a3f7a942fbebfef6be5f2d7bbaa7e937c01a28e48860955d202c3a280603ee14ba2ab8b6bcdd279c69a1c0c57d3e51f331342
7
+ data.tar.gz: '087c08623d652cc936344007c5808dacaa01ea05ae2a1348c8d9a5a5c41b1ea872ddbd537ea248dbf247693eef9d48a750e5e127329dea32c3633c2c0c4b9332'
@@ -13,29 +13,20 @@ class GeneratorCLI < ::Thor
13
13
  option 'artifact', banner: 'ARTIFACT', type: :string, desc: 'Deploy lambdas that use this artifact'
14
14
  option 'lambda', banner: 'LAMBDA', type: :string, desc: 'Deploy lambdas with this name'
15
15
  option 'account', banner: 'ACCOUNT', type: :string, desc: 'Account to deploy to', :required => true
16
- option 'version_map_file', banner: 'VERSION_MAP_FILE', type: :string, desc: 'A java properties file mapping artifacts to update to version'
16
+ option 'deploy_all', banner: 'DEPLOY_ALL', type: :boolean, desc: 'Ignore the history therefore deploy everything included in the filter', default: false
17
17
 
18
18
  def deploy
19
19
  opts = validate_deploy(options)
20
- if opts['version_map_file']
21
- #for each x=y pair we need to call
22
- File.readlines(options['version_map_file']).each do |line|
23
- array = line.split("=")
24
- deployer = Deployer.new(opts['project_path'], opts['account'], array[0].strip)
25
- deployer.deploy(opts['environments'])
26
- end
27
- else
28
- deployer = Deployer.new(opts['project_path'], opts['account'], opts['artifact'], opts['lambda'])
29
- deployer.deploy(opts['environments'])
30
- end
20
+ deployer = Deployer.new(opts['deploy_all'], opts['project_path'], opts['account'], opts['artifact'], opts['lambda'])
21
+ deployer.deploy(opts['environments'])
31
22
  end
32
23
 
33
24
  desc 'update_project', 'Update the versions'
34
25
  option 'project_path', banner: 'PROJECT_PATH', type: :string, desc: 'Path to the lambda version mappings project'
35
26
  option 'artifact', banner: 'ARTIFACT', type: :string, desc: 'Deploy lambdas that use this artifact'
36
27
  option 'version', banner: 'VERSION', type: :string, desc: 'Version of the new artifact'
37
- option 'version_map_file', banner: 'VERSION_MAP_FILE', type: :string, desc: 'A java properties file mapping artifacts to update to version'
38
28
  option 'accounts', banner: 'ACCOUNT', type: :array, desc: 'Account to deploy to', :required => true
29
+ option 'sha1', banner: 'SHA1', type: :string, desc: 'SHA1 of the artifact'
39
30
 
40
31
  def update_project
41
32
  opts = validate_project_update(options)
@@ -54,31 +45,21 @@ class GeneratorCLI < ::Thor
54
45
  end
55
46
  end
56
47
 
57
-
58
- if opts['version_map_file']
59
- #for each artifact=version pair we need to call
60
- File.readlines(opts['version_map_file']).each do |line|
61
- array = line.split("=")
62
- updated_files = project.update_by_artifact(lambda_env_map, array[0].strip, array[1].strip)
63
- lambda_env_map = updated_files
64
- end
65
- else
66
- lambda_env_map = project.update_by_artifact(lambda_env_map, opts['artifact'], opts['version'])
67
- end
48
+ lambda_env_map = project.update_by_artifact(lambda_env_map, opts['artifact'], opts['version'], opts['sha1'])
68
49
  project.write_new_files(lambda_env_map)
69
50
  end
70
51
 
71
52
  no_commands do
72
53
  def validate_project_update(options)
73
- unless options['version_map_file'] || (options['version'] && (options['lambda'] || options['artifact']))
74
- raise 'Either a file must be specified or a version and lambda or artifact.'
54
+ unless options['version'] && (options['lambda'] || options['artifact'])
55
+ raise 'Either a version and lambda or artifact must be specified.'
75
56
  end
76
57
  options.dup
77
58
  end
78
59
 
79
60
  def validate_deploy(options)
80
- unless options['version_map_file'] || options['environments'] || options['lambda'] || options['artifact']
81
- raise 'Either a file must be specified or a environment or lambda or artifact.'
61
+ unless options['environments'] || options['lambda'] || options['artifact']
62
+ raise 'Either a environment or lambda or artifact must be specified.'
82
63
  end
83
64
  options.dup
84
65
  end
data/lib/deployer.rb CHANGED
@@ -9,8 +9,10 @@ class Deployer
9
9
  attr_accessor :lambda
10
10
  attr_accessor :artifact
11
11
  attr_accessor :environments
12
+ attr_accessor :deploy_all
12
13
 
13
- def initialize(project_path, account, artifact=nil, lambda=nil)
14
+ def initialize(deploy_all, project_path, account, artifact=nil, lambda=nil)
15
+ @deploy_all = deploy_all
14
16
  @project_path = project_path
15
17
  @account = account
16
18
  @project = Project.new("#{project_path}")
@@ -48,12 +50,18 @@ class Deployer
48
50
  env_region_map = project.env_region_map
49
51
  #Filter by account as the primary owner of envs
50
52
  lambda_env_map = project.get_lambdas
51
- lambda_env_map = diff_projects(lambda_env_map)
53
+ unless deploy_all
54
+ lambda_env_map = diff_projects(lambda_env_map)
55
+ if lambda_env_map.empty?
56
+ puts "No lambdas have been changed, skipping deploy"
57
+ return
58
+ end
59
+ end
52
60
  lambda_env_map = get_deployable_lambdas(lambda_env_map)
53
61
  environments ||= project.environments
54
62
  account_env_map.each do |env|
55
63
  #IF users has specified environments, skip if the environment is not a user specified one
56
- next unless !environments.nil? && environments.include?(env)
64
+ next unless !environments.nil? && environments.include?(env) && !lambda_env_map[env].nil?
57
65
  lambda_env_map[env].each do |lambda_name, properties|
58
66
  client = Client.new(env_region_map[env])
59
67
 
@@ -66,8 +74,8 @@ class Deployer
66
74
  puts "S3 Key: #{s3_key}"
67
75
  client.update_function_code(lambda_name,s3_bucket,s3_key)
68
76
  end
77
+ archive_project(env)
69
78
  end
70
- archive_project
71
79
  end
72
80
 
73
81
 
@@ -88,13 +96,10 @@ class Deployer
88
96
  end
89
97
  end
90
98
 
91
- def archive_project
92
- if Dir.exist?("#{project_path}/.history/")
93
- FileUtils.remove_dir("#{project_path}/.history/environments")
94
- FileUtils.remove_dir("#{project_path}/.history/config")
95
- end
99
+ def archive_project(environment)
100
+ FileUtils.mkpath("#{project_path}/.history/")
96
101
  FileUtils.copy_entry("#{project_path}/config","#{project_path}/.history/config")
97
- FileUtils.copy_entry("#{project_path}/environments","#{project_path}/.history/environments")
102
+ FileUtils.copy_entry("#{project_path}/environments/#{environment}.yaml","#{project_path}/.history/environments/#{environment}.yaml")
98
103
  end
99
104
 
100
105
  def parse_archive
@@ -103,13 +108,15 @@ class Deployer
103
108
  end
104
109
 
105
110
  def diff_projects(new_project)
106
- unless Dir.exist?("#{project_path}/.history/")
107
- return new_project
108
- end
109
111
  historic = parse_archive
110
112
  historic.each do |environment, lambdas|
111
113
  lambdas.each do |lambda, configs|
112
- if new_project[environment][lambda].eql?(configs)
114
+ next if new_project[environment][lambda].nil?
115
+ if new_project[environment][lambda].has_key?('sha1')
116
+ if configs.has_key?('sha1') && (configs['sha1'] == new_project[environment][lambda]['sha1'])
117
+ new_project[environment].delete(lambda)
118
+ end
119
+ elsif new_project[environment][lambda].eql?(configs)
113
120
  new_project[environment].delete(lambda)
114
121
  end
115
122
  end
data/lib/project.rb CHANGED
@@ -45,13 +45,14 @@ class Project
45
45
  end
46
46
 
47
47
 
48
+
48
49
  def write_new_files(lambda_env_map)
49
50
  lambda_env_map.each do |env, contents|
50
51
  File.write("#{project_path}/environments/#{env}.yaml", contents.to_yaml)
51
52
  end
52
53
  end
53
54
 
54
- def update_by_artifact(lambda_env_map, artifact, version)
55
+ def update_by_artifact(lambda_env_map, artifact, version, sha1=nil)
55
56
  #iterate through all lambdas and update the ones with version changes
56
57
  lambda_env_map.each do |env, lambda|
57
58
  pp env
@@ -59,6 +60,7 @@ class Project
59
60
  lambda.each do |lambda_name, properties|
60
61
  if properties['artifact_name'] == artifact
61
62
  properties['version'] = version
63
+ properties['sha1'] = sha1 unless sha1.nil?
62
64
  end
63
65
  end
64
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lambda-version-manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Call