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 ⇒ Image
Package, upload, and create a MicroVM image.
-
#initialize(project:, client: nil, s3: nil) ⇒ Deployer
constructor
rubocop:disable Naming/MethodParameterName.
-
#package ⇒ String
Package the project into a deployable zip artifact.
-
#run ⇒ MicroVM
Run the configured image with configured runtime parameters.
-
#upload(path) ⇒ String
Upload an artifact to the configured S3 bucket and prefix.
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.validate! @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 ⇒ Image
Package, upload, and create a MicroVM image.
44 45 46 47 48 49 |
# File 'lib/lambda/microvms/deployer.rb', line 44 def deploy ensure_microvm_contract! artifact = package artifact_uri = upload(artifact) client.create_image(**project.create_image_params(artifact_uri: artifact_uri)) end |
#package ⇒ String
Package the project into a deployable zip artifact.
26 27 28 |
# File 'lib/lambda/microvms/deployer.rb', line 26 def package Packager.new(project).package end |
#run ⇒ MicroVM
Run the configured image with configured runtime parameters.
54 55 56 57 58 59 |
# File 'lib/lambda/microvms/deployer.rb', line 54 def run ensure_microvm_contract! 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) ⇒ String
Upload an artifact to the configured S3 bucket and prefix.
34 35 36 37 38 39 |
# File 'lib/lambda/microvms/deployer.rb', line 34 def upload(path) bucket = project.require!('deployment.bucket', project.s3_bucket) key = [project.s3_prefix.sub(%r{/\z}, ''), File.basename(path)].join('/') File.open(path, 'rb') { |body| s3.put_object(bucket: bucket, key: key, body: body) } "s3://#{bucket}/#{key}" end |