Class: Lambda::MicroVMs::Deployer
- Inherits:
-
Object
- Object
- Lambda::MicroVMs::Deployer
- Defined in:
- lib/lambda/microvms/deployer.rb
Overview
Project-aware deployment helper: package, upload to S3, create MicroVM image.
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#s3 ⇒ Object
readonly
Returns the value of attribute s3.
Instance Method Summary collapse
- #deploy ⇒ Object
-
#initialize(project:, client: nil, s3: nil) ⇒ Deployer
constructor
rubocop:disable Naming/MethodParameterName.
- #package ⇒ Object
- #run ⇒ Object
- #upload(path) ⇒ Object
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
#client ⇒ Object (readonly)
Returns the value of attribute client.
15 16 17 |
# File 'lib/lambda/microvms/deployer.rb', line 15 def client @client end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
15 16 17 |
# File 'lib/lambda/microvms/deployer.rb', line 15 def project @project end |
#s3 ⇒ Object (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
#deploy ⇒ Object
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 |
#package ⇒ Object
23 24 25 |
# File 'lib/lambda/microvms/deployer.rb', line 23 def package Packager.new(project).package end |
#run ⇒ Object
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 |