Class: Deployer

Inherits:
Object
  • Object
show all
Defined in:
lib/deployer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project_path, account, artifact = nil, lambda = nil) ⇒ Deployer

Returns a new instance of Deployer.



12
13
14
15
16
17
18
19
# File 'lib/deployer.rb', line 12

def initialize(project_path, , artifact=nil, lambda=nil)
  @project_path  = project_path
  @account = 
  @project = Project.new("#{project_path}")
  @config = set_config
  @artifact =  artifact
  @lambda =  lambda
end

Instance Attribute Details

#accountObject

Returns the value of attribute account.



5
6
7
# File 'lib/deployer.rb', line 5

def 
  @account
end

#artifactObject

Returns the value of attribute artifact.



9
10
11
# File 'lib/deployer.rb', line 9

def artifact
  @artifact
end

#configObject

Returns the value of attribute config.



6
7
8
# File 'lib/deployer.rb', line 6

def config
  @config
end

#environmentsObject

Returns the value of attribute environments.



10
11
12
# File 'lib/deployer.rb', line 10

def environments
  @environments
end

#lambdaObject

Returns the value of attribute lambda.



8
9
10
# File 'lib/deployer.rb', line 8

def lambda
  @lambda
end

#projectObject

Returns the value of attribute project.



7
8
9
# File 'lib/deployer.rb', line 7

def project
  @project
end

#project_pathObject

Returns the value of attribute project_path.



4
5
6
# File 'lib/deployer.rb', line 4

def project_path
  @project_path
end

Instance Method Details

#construct_s3_key(properties, env) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/deployer.rb', line 80

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['artifact_name']}-#{properties['version']}.#{properties['extension']}"
  end
end

#deploy(environments) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/deployer.rb', line 45

def deploy(environments)
   = project.[]
  env_region_map = project.env_region_map
  #Filter by account as the primary owner of envs
  lambda_env_map = project.get_lambdas
  lambda_env_map = get_deployable_lambdas(lambda_env_map)
  environments ||= project.environments
  .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].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
  end
end

#get_deployable_lambdas(lambda_env_map) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/deployer.rb', line 25

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



71
72
73
74
75
76
77
78
# File 'lib/deployer.rb', line 71

def get_s3_bucket(properties, env)
  if properties['s3_bucket']
    return properties['s3_bucket']
  else
    return config['environments'][env]['s3_bucket']
  end

end

#set_configObject



21
22
23
# File 'lib/deployer.rb', line 21

def set_config
  @project.config
end