Module: Deploy
- Defined in:
- lib/deploy.rb
Class Method Summary collapse
Class Method Details
.create_config(config = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/deploy.rb', line 14 def self.create_config(config = {}) config = { 'aws_key' => nil, 'aws_secret' => nil, 'aws_bucket' => nil, 'deploy_folder' => nil }.merge(config) File.open("#{Dir.pwd}/.deploy", 'w+') { |file| file.write(config.to_yaml) } end |
.get_bucket ⇒ Object
24 25 26 27 28 |
# File 'lib/deploy.rb', line 24 def self.get_bucket ::AWS.config(access_key_id: @config['aws_key'], secret_access_key: @config['aws_secret'], region: @config['aws_region']) service = ::AWS::S3.new(s3_endpoint: "s3-#{@config['aws_region']}.amazonaws.com") service.buckets[@config['aws_bucket']] end |
.load_config ⇒ Object
8 9 10 11 12 |
# File 'lib/deploy.rb', line 8 def self.load_config defaults = {'aws_region' => 'us-west-2'} @config = YAML.load_file("#{Dir.pwd}/.deploy") @config = defaults.merge(@config) end |
.sync ⇒ Object
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 |
# File 'lib/deploy.rb', line 30 def self.sync bucket = get_bucket Dir.glob("#{@config['deploy_folder']}/**/*").each do |file| if File.file?(file) remote_file = file.sub("#{@config['deploy_folder']}/", "") puts "+ #{file}" remote = bucket.objects[remote_file] content_type = case file.split('.').last when 'css' 'text/css' when 'js' 'application/javascript' when 'otf' 'font/opentype' when 'svg' 'image/svg+xml' end if File.exist?("#{file}.gz") remote.write(file: "#{file}.gz", content_encoding: 'gzip', content_type: content_type) else remote.write(file: file, content_type: content_type) end remote.acl end end end |