Class: Deployer
- Inherits:
-
Object
- Object
- Deployer
- Defined in:
- lib/deployer.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#artifact ⇒ Object
Returns the value of attribute artifact.
-
#config ⇒ Object
Returns the value of attribute config.
-
#deploy_all ⇒ Object
Returns the value of attribute deploy_all.
-
#environments ⇒ Object
Returns the value of attribute environments.
-
#lambda ⇒ Object
Returns the value of attribute lambda.
-
#project ⇒ Object
Returns the value of attribute project.
-
#project_path ⇒ Object
Returns the value of attribute project_path.
Instance Method Summary collapse
- #archive_project(environment) ⇒ Object
- #construct_s3_key(properties, env) ⇒ Object
- #deploy(environments) ⇒ Object
- #diff_projects(new_project) ⇒ Object
- #get_deployable_lambdas(lambda_env_map) ⇒ Object
- #get_s3_bucket(properties, env) ⇒ Object
-
#initialize(deploy_all, project_path, account, artifact = nil, lambda = nil) ⇒ Deployer
constructor
A new instance of Deployer.
- #parse_archive ⇒ Object
- #set_config ⇒ Object
Constructor Details
#initialize(deploy_all, project_path, account, artifact = nil, lambda = nil) ⇒ Deployer
Returns a new instance of Deployer.
14 15 16 17 18 19 20 21 22 |
# File 'lib/deployer.rb', line 14 def initialize(deploy_all, project_path, account, artifact=nil, lambda=nil) @deploy_all = deploy_all @project_path = project_path @account = account @project = Project.new("#{project_path}") @config = set_config @artifact = artifact @lambda = lambda end |
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
6 7 8 |
# File 'lib/deployer.rb', line 6 def account @account end |
#artifact ⇒ Object
Returns the value of attribute artifact.
10 11 12 |
# File 'lib/deployer.rb', line 10 def artifact @artifact end |
#config ⇒ Object
Returns the value of attribute config.
7 8 9 |
# File 'lib/deployer.rb', line 7 def config @config end |
#deploy_all ⇒ Object
Returns the value of attribute deploy_all.
12 13 14 |
# File 'lib/deployer.rb', line 12 def deploy_all @deploy_all end |
#environments ⇒ Object
Returns the value of attribute environments.
11 12 13 |
# File 'lib/deployer.rb', line 11 def environments @environments end |
#lambda ⇒ Object
Returns the value of attribute lambda.
9 10 11 |
# File 'lib/deployer.rb', line 9 def lambda @lambda end |
#project ⇒ Object
Returns the value of attribute project.
8 9 10 |
# File 'lib/deployer.rb', line 8 def project @project end |
#project_path ⇒ Object
Returns the value of attribute project_path.
5 6 7 |
# File 'lib/deployer.rb', line 5 def project_path @project_path end |
Instance Method Details
#archive_project(environment) ⇒ Object
99 100 101 102 103 |
# File 'lib/deployer.rb', line 99 def archive_project(environment) FileUtils.mkpath("#{project_path}/.history/") FileUtils.copy_entry("#{project_path}/config","#{project_path}/.history/config") FileUtils.copy_entry("#{project_path}/environments/#{environment}.yaml","#{project_path}/.history/environments/#{environment}.yaml") end |
#construct_s3_key(properties, env) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/deployer.rb', line 91 def construct_s3_key(properties, env) if properties['s3_key'] return properties['s3_key'] else return "#{config['environments'][env]['base_path']}/#{properties['artifact_name']}-#{properties['version']}.#{properties['extension']}" end end |
#deploy(environments) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/deployer.rb', line 48 def deploy(environments) account_env_map = project.account_env_map[account] env_region_map = project.env_region_map #Filter by account as the primary owner of envs lambda_env_map = project.get_lambdas unless deploy_all lambda_env_map = diff_projects(lambda_env_map) if lambda_env_map.empty? puts "No lambdas have been changed, skipping deploy" return end end lambda_env_map = get_deployable_lambdas(lambda_env_map) environments ||= project.environments account_env_map.each do |env| #IF users has specified environments, skip if the environment is not a user specified one next unless !environments.nil? && environments.include?(env) && !lambda_env_map[env].nil? lambda_env_map[env].each do |lambda_name, properties| client = Client.new(env_region_map[env]) s3_bucket = get_s3_bucket(properties, env) s3_key = construct_s3_key(properties, env) puts "ENV: #{env}" puts "Lambda Name: #{lambda_name}" puts "S3 Bucket: #{s3_bucket}" puts "S3 Key: #{s3_key}" client.update_function_code(lambda_name,s3_bucket,s3_key) end archive_project(env) end end |
#diff_projects(new_project) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/deployer.rb', line 110 def diff_projects(new_project) historic = parse_archive historic.each do |environment, lambdas| lambdas.each do |lambda, configs| next if new_project[environment][lambda].nil? if new_project[environment][lambda].has_key?('sha1') if configs.has_key?('sha1') && (configs['sha1'] == new_project[environment][lambda]['sha1']) new_project[environment].delete(lambda) end elsif new_project[environment][lambda].eql?(configs) new_project[environment].delete(lambda) end end #Delete empty environments as no lambdas changed so they all removed from bing deployable new_project.delete(environment) if new_project[environment].empty? end new_project end |
#get_deployable_lambdas(lambda_env_map) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/deployer.rb', line 28 def get_deployable_lambdas(lambda_env_map) if artifact lambda_env_map.each do |env, lambdas| lambdas.each do |lambda_name, properties| lambdas.delete(lambda_name) unless properties['artifact_name'] == artifact end end end if lambda lambda_env_map.each do |env, lambdas| lambdas.each do |lambda_name, properties| lambdas.delete(lambda_name) unless lambda_name == lambda end end end lambda_env_map end |
#get_s3_bucket(properties, env) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/deployer.rb', line 82 def get_s3_bucket(properties, env) if properties['s3_bucket'] return properties['s3_bucket'] else return config['environments'][env]['s3_bucket'] end end |
#parse_archive ⇒ Object
105 106 107 108 |
# File 'lib/deployer.rb', line 105 def parse_archive archived_project = Project.new("#{project_path}/.history/") archived_project.get_lambdas end |
#set_config ⇒ Object
24 25 26 |
# File 'lib/deployer.rb', line 24 def set_config @project.config end |