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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/deploy.rb', line 32
def self.sync
Aws.config[:region] = @config['aws_region']
Aws.config[:credentials] = Aws::Credentials.new(@config['aws_key'], @config['aws_secret'])
s3 = Aws.s3
Dir.glob("#{@config['deploy_folder']}/**/*").each do |file|
if File.file?(file)
remote_file = file.sub("#{@config['deploy_folder']}/", "")
content_type = case file.split('.').last
when 'css'
Deploy::Compress.compress(file)
'text/css'
when 'js'
Deploy::Compress.compile(file)
'application/javascript'
when 'otf'
'font/opentype'
when 'svg'
'image/svg+xml'
when 'xml'
'text/xml'
when 'html', 'htm'
'text/html'
when 'gz'
'skip'
end
unless content_type == 'skip'
if File.exist?("#{file}.gz")
puts "+ #{file} (compressed)"
s3.put_object(bucket: @config['aws_bucket'], key: remote_file, body: File.read("#{file}.gz"),
content_type: content_type, content_encoding: 'gzip', acl: 'public-read')
else
puts "+ #{file}"
s3.put_object(bucket: @config['aws_bucket'], key: remote_file, body: File.read(file),
content_type: content_type, acl: 'public-read')
end
end
end
end
end
|