Class: Jets::Code
Defined Under Namespace
Modules: Copy
Classes: Dummy, Stager, User
Constant Summary
collapse
- @@s3_key =
nil
Instance Method Summary
collapse
Methods included from Util::Sh
#capture, #quiet_sh, #sh
#log
#apigateway, #aws_options, #cfn, #codebuild, #dynamodb, #lambda_client, #logs, #s3, #s3_resource, #sns, #sqs, #ssm, #sts, #wafv2
#output_value, #stack_exists?
included, #reset_cache!
Constructor Details
#initialize(options = {}) ⇒ Code
Returns a new instance of Code.
10
11
12
|
# File 'lib/jets/code.rb', line 10
def initialize(options = {})
@options = options
end
|
Instance Method Details
#s3_key ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/jets/code.rb', line 27
def s3_key
return @@s3_key if @@s3_key
timestamp = Time.now.utc.strftime("%Y-%m-%dT%H-%M-%SZ")
git = Jets::Git::Info.new
branch, sha, dirty = git.params.values_at(:git_branch, :git_sha, :git_dirty)
sha = sha[0..6] if sha dirty = dirty ? "dirty" : nil
key = ["jets/code/#{timestamp}", branch, sha, dirty].compact.join("-")
key = key.gsub(/[^a-zA-Z0-9\-_:\/]/, "-").squeeze("-") @@s3_key = key + ".zip"
end
|
#s3_location ⇒ Object
40
41
42
|
# File 'lib/jets/code.rb', line 40
def s3_location
"s3://#{s3_bucket}/#{s3_key}"
end
|
#stage ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/jets/code.rb', line 50
def stage
if @options[:dummy]
Dummy.new.build
else
Stager.new.build
end
end
|
#upload ⇒ Object
44
45
46
47
48
|
# File 'lib/jets/code.rb', line 44
def upload
s3_resource.bucket(s3_bucket).object(s3_key).upload_file(zip_path)
logger.debug "Uploaded code to s3://#{s3_bucket}/#{s3_key}"
s3_location end
|
#zip ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/jets/code.rb', line 58
def zip
unless Dir.exist?("#{build_root}/stage/code")
logger.info "Error: Source folder not found: #{build_root}/stage/code"
return
end
FileUtils.mkdir_p(File.dirname(zip_path))
FileUtils.rm_f(zip_path)
quiet_sh "cd #{build_root}/stage/code && zip --symlinks -rq #{zip_path} ."
unless $?.success?
logger.info "Error: Failed to zip the folder: #{build_root}/stage/code"
end
zip_path
end
|
#zip_and_upload ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/jets/code.rb', line 14
def zip_and_upload
command = ARGV.reject { |s| s.match(/^-/) }.join(":") log.info "Packaging code for #{command}: #{Jets.project.namespace}"
stage
zip
upload
end
|
#zip_path ⇒ Object
22
23
24
|
# File 'lib/jets/code.rb', line 22
def zip_path
"#{build_root}/code/code.zip"
end
|