Class: Osiris::Deployment

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

Instance Method Summary collapse

Constructor Details

#initialize(use_bundled_cert) ⇒ Deployment

Returns a new instance of Deployment.



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

def initialize(use_bundled_cert)
  Aws.use_bundled_cert! if use_bundled_cert
end

Instance Method Details

#deploy(bucket, relative_path, version, application_name, deployment_group, description = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/osiris/deployment.rb', line 26

def deploy(bucket, relative_path, version, application_name, deployment_group, description = nil)
  begin
    codedeploy = Aws::CodeDeploy::Client.new()
    codedeploy.create_deployment({
      application_name: application_name, # required
      deployment_group_name: deployment_group,
      revision: {
        revision_type: 'S3',
        s3_location: {
          bucket: bucket,
          key: File.join(relative_path, "#{version.to_s}.zip"),
          bundle_type: 'zip'
        }
      },
      deployment_config_name: 'CodeDeployDefault.OneAtATime',
      description: description || "Deployed with Osiris, for more information see: https://github.com/wparad/Osiris",
      ignore_application_stop_failures: false
    })
  rescue Aws::CodeDeploy::Errors::ServiceError => exception
    puts "Failed to deploy resource: #{exception}"
  rescue Exception => exception
    puts "Failed to connect to AWS: #{exception}"
  end
end

#publish(bucket, relative_path, local_directory, version) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/osiris/deployment.rb', line 9

def publish(bucket, relative_path, local_directory, version)
  Dir.mktmpdir do |tmp|
    zip_file = File.join(tmp, "#{version.to_s}.zip")
    ZipFileGenerator.new().write(local_directory, zip_file);

    begin
      s3 = Aws::S3::Resource.new()
      obj = s3.bucket(bucket).object(File.join(relative_path, File.basename(zip_file)))
      obj.upload_file(zip_file)
    rescue Aws::S3::Errors::ServiceError => exception
      puts "Failed to publish resource: #{exception}"
    rescue Exception => exception
      puts "Failed to connect to AWS: #{exception}"
    end
  end
end