Class: Opsk::DeployS3

Inherits:
Thor::Group
  • Object
show all
Includes:
Thorable, Thor::Actions
Defined in:
lib/opskeleton/deploy_s3.rb

Instance Method Summary collapse

Methods included from Thorable

#artifact, #artifact_path, #check_root, included, #machines, #meta, #name, #type_of

Instance Method Details

#load_confObject



17
18
19
20
21
22
# File 'lib/opskeleton/deploy_s3.rb', line 17

def load_conf
	require 'configuration'
	conf = "#{ENV['HOME']}/.configuration.rb"
	raise "#{conf} not found, please create a conf file with a s3 section" unless File.exists?(conf)
	require conf   	
end

#uploadObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/opskeleton/deploy_s3.rb', line 24

def upload
	require 'aws-sdk'
	pkg = Opsk::Package.new
	tar =  "#{pkg.artifact_path}.tar.gz"
	base = File.basename(tar)
	if(File.exists?(tar))
	  begin
 conf = Configuration.for 's3'
 Aws.config.update({
		region: conf.region,
		credentials: Aws::Credentials.new(conf.access_key, conf.secret_key),
 })
 s3 = Aws::S3::Resource.new
 s3.bucket(bucket).object("#{path}/#{base}").upload_file(tar)
 say("deployed #{base} to #{bucket}/#{path}/#{base}")
	  rescue Exception => e
 say("failed to deploy due to #{e}")
	  end
	else
	  say('package is missing please run opsk package first')
	  exit(1)
	end
end

#validateObject



13
14
15
# File 'lib/opskeleton/deploy_s3.rb', line 13

def validate
	check_root
end