Class: Envirobly::Deployment
- Inherits:
-
Object
- Object
- Envirobly::Deployment
- Includes:
- Colorize
- Defined in:
- lib/envirobly/deployment.rb
Constant Summary
Constants included from Colorize
Colorize::BLUE, Colorize::BOLD, Colorize::FAINT, Colorize::GREEN, Colorize::RED, Colorize::RESET, Colorize::YELLOW
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(environ_name:, commit:, account_id:, project_name:, project_id:, region:, shell:) ⇒ Deployment
constructor
A new instance of Deployment.
- #perform(dry_run:) ⇒ Object
Methods included from Colorize
#bold, #cross, #display_config_errors, #downwards_arrow_to_right, #faint, #green, #green_check, #red, #yellow
Constructor Details
#initialize(environ_name:, commit:, account_id:, project_name:, project_id:, region:, shell:) ⇒ Deployment
Returns a new instance of Deployment.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/envirobly/deployment.rb', line 11 def initialize(environ_name:, commit:, account_id:, project_name:, project_id:, region:, shell:) @environ_name = environ_name @commit = commit @config = Config.new @default_account = Defaults::Account.new(shell:) @default_project = Defaults::Project.new(shell:) @default_region = Defaults::Region.new(shell:) target = Target.new( default_account_id: @default_account.value, default_project_id: @default_project.value, default_region: @default_region.value, default_project_name: Defaults::Project.dirname, default_environ_name: commit.current_branch, account_id:, project_id:, region:, project_name:, environ_name: ) if target.missing_params.include?(:account_id) target.account_id = @default_account.require_value end if target.missing_params.include?(:region) target.region = @default_region.require_value end target.ignored_params.each do |param| shell.say "--#{param.to_s.parameterize} ignored, due to other arguments overriding it" end @params = { account_id: target.account_id, project_id: target.project_id, project_name: target.project_name, region: target.region, deployment: { environ_name: target.environ_name, commit_ref: @commit.ref, commit_time: @commit.time, commit_message: @commit., object_tree_checksum: @commit.object_tree_checksum, **@config.to_params } } end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
9 10 11 |
# File 'lib/envirobly/deployment.rb', line 9 def params @params end |
Instance Method Details
#perform(dry_run:) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/envirobly/deployment.rb', line 60 def perform(dry_run:) puts [ "Deploying commit", yellow(@commit.short_ref), faint("→"), green(@environ_name) ].join(" ") puts puts " #{@commit.}" puts if dry_run puts YAML.dump(@params) return end # Create deployment api = Api.new Duration.measure do response = api.create_deployment @params unless response.success? display_config_errors response.object.fetch("errors") exit 1 end print "Preparing project..." @default_account.save_if_none response.object.fetch("account_id") @default_project.save_if_none response.object.fetch("project_id") @default_region.save_if_none response.object.fetch("region") # Fetch credentials for build context upload @deployment_url = response.object.fetch("url") @credentials_response = api.get_deployment_with_delay_and_retry @deployment_url end credentials = @credentials_response.object.fetch("credentials") region = @credentials_response.object.fetch("region") bucket = @credentials_response.object.fetch("bucket") watch_deployment_url = @credentials_response.object.fetch("deployment_url") Duration.measure do # Upload build context Aws::S3.new(bucket:, region:, credentials:).push @commit # Perform deployment api.put_as_json @deployment_url end puts "Follow at #{watch_deployment_url}" end |