Last active
December 17, 2015 05:08
-
-
Save zeevallin/5555180 to your computer and use it in GitHub Desktop.
It should be quite similar using AWS insted of rackspace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Enable serving of images, stylesheets, and JavaScripts from an asset server | |
config.action_controller.asset_host = "https://c776950.ssl.cf2.rackcdn.com" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'cloudfiles' | |
cf = CloudFiles::Connection.new( | |
:username => Cloudsdale.config['rackspace_cloudfiles']['username'], | |
:api_key => Cloudsdale.config['rackspace_cloudfiles']['api_key'], | |
:snet => false | |
) | |
namespace :assets do | |
desc "Upload assets to rackspace" | |
task :upload do | |
# Set up CloudFiles and paths | |
container = cf.container('cloudsdale_production_assets') | |
shared_path = Pathname.new(ENV["SHARED_PATH"]) | |
assets_path = shared_path.join("assets") | |
remote_files = container.objects | |
local_files = Dir.glob(assets_path.join('**', '*.*')).collect{ |file| file.slice!(shared_path.to_s + '/'); file } | |
if remote_files.sort == local_files.sort | |
puts "Remote and local the same. Skipping..." | |
else | |
puts "Starting remote sync..." | |
# See if there are files existing localy but not remotely | |
(local_files - remote_files).each do |file| | |
object = container.create_object(file, false) | |
object.load_from_filename(shared_path.join(file)) | |
puts "Uploaded #{file}" | |
end | |
# See if there is any files that exists remotely but are removed localy | |
(remote_files - local_files).each do |file| | |
container.delete_object(file) | |
puts "Removed #{file}" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment