Class: Lambda::MicroVMs::Deployer

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

Overview

Project-aware deployment helper: package, upload to S3, create MicroVM image.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project:, client: nil, s3: nil) ⇒ Deployer

rubocop:disable Naming/MethodParameterName



17
18
19
20
21
# File 'lib/lambda/microvms/deployer.rb', line 17

def initialize(project:, client: nil, s3: nil) # rubocop:disable Naming/MethodParameterName
  @project = project
  @client = client || Client.new(region: project.region, profile: project.profile)
  @s3 = s3 || build_s3
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



15
16
17
# File 'lib/lambda/microvms/deployer.rb', line 15

def client
  @client
end

#projectObject (readonly)

Returns the value of attribute project.



15
16
17
# File 'lib/lambda/microvms/deployer.rb', line 15

def project
  @project
end

#s3Object (readonly)

Returns the value of attribute s3.



15
16
17
# File 'lib/lambda/microvms/deployer.rb', line 15

def s3
  @s3
end

Instance Method Details

#deployObject



34
35
36
37
38
# File 'lib/lambda/microvms/deployer.rb', line 34

def deploy
  artifact = package
  artifact_uri = upload(artifact)
  client.create_image(**project.create_image_params(artifact_uri: artifact_uri))
end

#packageObject



23
24
25
# File 'lib/lambda/microvms/deployer.rb', line 23

def package
  Packager.new(project).package
end

#runObject



40
41
42
43
44
# File 'lib/lambda/microvms/deployer.rb', line 40

def run
  image_arn = project.require!('image.arn', project.image_arn)
  role_arn = project.require!('role_arn', project.role_arn)
  client.image(image_arn).run(**project.run_params, role_arn: role_arn)
end

#upload(path) ⇒ Object



27
28
29
30
31
32
# File 'lib/lambda/microvms/deployer.rb', line 27

def upload(path)
  bucket = project.require!('deployment.bucket', project.s3_bucket)
  key = [project.s3_prefix.sub(%r{/\z}, ''), File.basename(path)].join('/')
  s3.put_object(bucket: bucket, key: key, body: File.open(path, 'rb'))
  "s3://#{bucket}/#{key}"
end