Giter Club home page Giter Club logo

asset_sync's Introduction

Gem Version GitHub Build Status Coverage Status

Asset Sync

Synchronises Assets between Rails and S3.

Asset Sync is built to run with the new Rails Asset Pipeline feature introduced in Rails 3.1. After you run bundle exec rake assets:precompile your assets will be synchronised to your S3 bucket, optionally deleting unused files and only uploading the files it needs to.

This was initially built and is intended to work on Heroku but can work on any platform.

Upgrading?

Upgraded from 1.x? Read UPGRADING.md

Installation

Since 2.x, Asset Sync depends on gem fog-core instead of fog.
This is due to fog is including many unused storage provider gems as its dependencies.

Asset Sync has no idea about what provider will be used,
so you are responsible for bundling the right gem for the provider to be used.

In your Gemfile:

gem "asset_sync"
gem "fog-aws"

Or, to use Azure Blob storage, configure as this.

gem "asset_sync"
gem "gitlab-fog-azure-rm"

# This gem seems unmaintianed
# gem "fog-azure-rm"

To use Backblaze B2, insert these.

gem "asset_sync"
gem "fog-backblaze"

Extended Installation (Faster sync with turbosprockets)

It's possible to improve asset:precompile time if you are using Rails 3.2.x the main source of which being compilation of non-digest assets.

turbo-sprockets-rails3 solves this by only compiling digest assets. Thus cutting compile time in half.

NOTE: It will be deprecated in Rails 4 as sprockets-rails has been extracted out of Rails and will only compile digest assets by default.

Configuration

Rails

Configure config/environments/production.rb to use Amazon S3 as the asset host and ensure precompiling is enabled.

  #config/environments/production.rb
  config.action_controller.asset_host = "//#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"

Or, to use Google Storage Cloud, configure as this.

  #config/environments/production.rb
  config.action_controller.asset_host = "//#{ENV['FOG_DIRECTORY']}.storage.googleapis.com"

Or, to use Azure Blob storage, configure as this.

  #config/environments/production.rb
  config.action_controller.asset_host = "//#{ENV['AZURE_STORAGE_ACCOUNT_NAME']}.blob.core.windows.net/#{ENV['FOG_DIRECTORY']}"

Or, to use Backblaze B2, configure as this.

  #config/environments/production.rb
  config.action_controller.asset_host = "//f000.backblazeb2.com/file/#{ENV['FOG_DIRECTORY']}"

On HTTPS: the exclusion of any protocol in the asset host declaration above will allow browsers to choose the transport mechanism on the fly. So if your application is available under both HTTP and HTTPS the assets will be served to match.

The only caveat with this is that your S3 bucket name must not contain any periods so, mydomain.com.s3.amazonaws.com for example would not work under HTTPS as SSL certificates from Amazon would interpret our bucket name as not a subdomain of s3.amazonaws.com, but a multi level subdomain. To avoid this don't use a period in your subdomain or switch to the other style of S3 URL.

  config.action_controller.asset_host = "//s3.amazonaws.com/#{ENV['FOG_DIRECTORY']}"

Or, to use Google Storage Cloud, configure as this.

  config.action_controller.asset_host = "//storage.googleapis.com/#{ENV['FOG_DIRECTORY']}"

Or, to use Azure Blob storage, configure as this.

  #config/environments/production.rb
  config.action_controller.asset_host = "//#{ENV['AZURE_STORAGE_ACCOUNT_NAME']}.blob.core.windows.net/#{ENV['FOG_DIRECTORY']}"

On non default S3 bucket region: If your bucket is set to a region that is not the default US Standard (us-east-1) you must use the first style of url //#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com or amazon will return a 301 permanently moved when assets are requested. Note the caveat above about bucket names and periods.

If you wish to have your assets sync to a sub-folder of your bucket instead of into the root add the following to your production.rb file

  # store assets in a 'folder' instead of bucket root
  config.assets.prefix = "/production/assets"

Also, ensure the following are defined (in production.rb or application.rb)

  • config.assets.digest is set to true.
  • config.assets.enabled is set to true.

Additionally, if you depend on any configuration that is setup in your initializers you will need to ensure that

  • config.assets.initialize_on_precompile is set to true

AssetSync

AssetSync supports the following methods of configuration.

  • Built-in Initializer (configured through environment variables)
  • Rails Initializer
  • A YAML config file

Using the Built-in Initializer is the default method and is supposed to be used with environment variables. It's the recommended approach for deployments on Heroku.

If you need more control over configuration you will want to use a custom rails initializer.

Configuration using a YAML file (a common strategy for Capistrano deployments) is also supported.

The recommend way to configure asset_sync is by using environment variables however it's up to you, it will work fine if you hard code them too. The main reason why using environment variables is recommended is so your access keys are not checked into version control.

Built-in Initializer (Environment Variables)

The Built-in Initializer will configure AssetSync based on the contents of your environment variables.

Add your configuration details to heroku

heroku config:add AWS_ACCESS_KEY_ID=xxxx
heroku config:add AWS_SECRET_ACCESS_KEY=xxxx
heroku config:add FOG_DIRECTORY=xxxx
heroku config:add FOG_PROVIDER=AWS
# and optionally:
heroku config:add FOG_REGION=eu-west-1
heroku config:add ASSET_SYNC_COMPRESSION=gz
heroku config:add ASSET_SYNC_MANIFEST=true
heroku config:add ASSET_SYNC_EXISTING_REMOTE_FILES=keep

Or add to a traditional unix system

export AWS_ACCESS_KEY_ID=xxxx
export AWS_SECRET_ACCESS_KEY=xxxx
export FOG_DIRECTORY=xxxx

Rackspace configuration is also supported

heroku config:add RACKSPACE_USERNAME=xxxx
heroku config:add RACKSPACE_API_KEY=xxxx
heroku config:add FOG_DIRECTORY=xxxx
heroku config:add FOG_PROVIDER=Rackspace

Google Storage Cloud configuration is supported as well. The preferred option is using the GCS JSON API which requires that you create an appropriate service account, generate the signatures and make them accessible to asset sync at the prescribed location

heroku config:add FOG_PROVIDER=Google
heroku config:add GOOGLE_PROJECT=xxxx
heroku config:add GOOGLE_JSON_KEY_LOCATION=xxxx
heroku config:add FOG_DIRECTORY=xxxx

If using the S3 API the following config is required

heroku config:add FOG_PROVIDER=Google
heroku config:add GOOGLE_STORAGE_ACCESS_KEY_ID=xxxx
heroku config:add GOOGLE_STORAGE_SECRET_ACCESS_KEY=xxxx
heroku config:add FOG_DIRECTORY=xxxx

The Built-in Initializer also sets the AssetSync default for existing_remote_files to keep.

Custom Rails Initializer (config/initializers/asset_sync.rb)

If you want to enable some of the advanced configuration options you will want to create your own initializer.

Run the included Rake task to generate a starting point.

rails g asset_sync:install --provider=Rackspace
rails g asset_sync:install --provider=AWS
rails g asset_sync:install --provider=AzureRM
rails g asset_sync:install --provider=Backblaze

The generator will create a Rails initializer at config/initializers/asset_sync.rb.

AssetSync.configure do |config|
  config.fog_provider = 'AWS'
  config.fog_directory = ENV['FOG_DIRECTORY']
  config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
  config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
  config.aws_session_token = ENV['AWS_SESSION_TOKEN'] if ENV.key?('AWS_SESSION_TOKEN')

  # Don't delete files from the store
  # config.existing_remote_files = 'keep'
  #
  # Increase upload performance by configuring your region
  # config.fog_region = 'eu-west-1'
  #
  # Set `public` option when uploading file depending on value,
  # Setting to "default" makes asset sync skip setting the option
  # Possible values: true, false, "default" (default: true)
  # config.fog_public = true
  #
  # Change AWS signature version. Default is 4
  # config.aws_signature_version = 4
  #
  # Change canned ACL of uploaded object. Default is unset. Will override fog_public if set.
  # Choose from: private | public-read | public-read-write | aws-exec-read |
  #              authenticated-read | bucket-owner-read | bucket-owner-full-control
  # config.aws_acl = nil
  #
  # Change host option in fog (only if you need to)
  # config.fog_host = 's3.amazonaws.com'
  #
  # Change port option in fog (only if you need to)
  # config.fog_port = "9000"
  #
  # Use http instead of https.
  # config.fog_scheme = 'http'
  #
  # Extra fog options.
  # Overrides any existing value (even those set by AssetSync)
  # config.fog_options = {}
  #
  # Automatically replace files with their equivalent gzip/brotli compressed version
  # config.compression = 'gz'
  #
  # Use the Rails generated 'manifest.yml' file to produce the list of files to
  # upload instead of searching the assets directory.
  # config.manifest = true
  #
  # Upload the manifest file also.
  # config.include_manifest = false
  #
  # Upload files concurrently
  # config.concurrent_uploads = false
  #
  # Number of threads when concurrent_uploads is enabled
  # config.concurrent_uploads_max_threads = 10
  #
  # Path to cache file to skip scanning remote
  # config.remote_file_list_cache_file_path = './.asset_sync_remote_file_list_cache.json'
  #
  # Path on remote storage to persist remote file list file
  # config.remote_file_list_remote_path = '/remote/asset_sync_remote_file.json'
  #
  # Fail silently.  Useful for environments such as Heroku
  # config.fail_silently = true
  #
  # Log silently. Default is `true`. But you can set it to false if more logging message are preferred.
  # Logging messages are sent to `STDOUT` when `log_silently` is falsy
  # config.log_silently = true
  #
  # Allow custom assets to be cacheable. Note: The base filename will be matched
  # If you have an asset with name `app.0b1a4cd3.js`, only `app.0b1a4cd3` will need to be matched
  # only one of `cache_asset_regexp` or `cache_asset_regexps` is allowed.
  # config.cache_asset_regexp = /\.[a-f0-9]{8}$/i
  # config.cache_asset_regexps = [ /\.[a-f0-9]{8}$/i, /\.[a-f0-9]{20}$/i ]
end

YAML (config/asset_sync.yml)

Run the included Rake task to generate a starting point.

rails g asset_sync:install --use-yml --provider=Rackspace
rails g asset_sync:install --use-yml --provider=AWS
rails g asset_sync:install --use-yml --provider=AzureRM
rails g asset_sync:install --use-yml --provider=Backblaze

The generator will create a YAML file at config/asset_sync.yml.

defaults: &defaults
  fog_provider: "AWS"
  fog_directory: "rails-app-assets"
  aws_access_key_id: "<%= ENV['AWS_ACCESS_KEY_ID'] %>"
  aws_secret_access_key: "<%= ENV['AWS_SECRET_ACCESS_KEY'] %>"

  # To use AWS reduced redundancy storage.
  # aws_reduced_redundancy: true
  #
  # You may need to specify what region your storage bucket is in
  # fog_region: "eu-west-1"
  #
  # Change AWS signature version. Default is 4
  # aws_signature_version: 4
  #
  # Change canned ACL of uploaded object. Default is unset. Will override fog_public if set.
  # Choose from: private | public-read | public-read-write | aws-exec-read |
  #              authenticated-read | bucket-owner-read | bucket-owner-full-control
  # aws_acl: null
  #
  # Change host option in fog (only if you need to)
  # fog_host: "s3.amazonaws.com"
  #
  # Use http instead of https. Default should be "https" (at least for fog-aws)
  # fog_scheme: "http"

  existing_remote_files: keep # Existing pre-compiled assets on S3 will be kept
  # To delete existing remote files.
  # existing_remote_files: delete
  # To ignore existing remote files and overwrite.
  # existing_remote_files: ignore
  # Automatically replace files with their equivalent gzip/brotli compressed version
  # compression: "gz"
  # Fail silently.  Useful for environments such as Heroku
  # fail_silently: true
  # Always upload. Useful if you want to overwrite specific remote assets regardless of their existence
  #  eg: Static files in public often reference non-fingerprinted application.css
  #  note: You will still need to expire them from the CDN's edge cache locations
  # always_upload: ['application.js', 'application.css', !ruby/regexp '/application-/\d{32}\.css/']
  # Ignored files. Useful if there are some files that are created dynamically on the server and you don't want to upload on deploy.
  # ignored_files: ['ignore_me.js', !ruby/regexp '/ignore_some/\d{32}\.css/']
  # Public path. To change the public directory.
  # public_path: 'public'
  # Prefix. To change the directory to sync relative to public_path.
  # prefix: 'assets'
  # Allow custom assets to be cacheable. Note: The base filename will be matched
  # If you have an asset with name "app.0b1a4cd3.js", only "app.0b1a4cd3" will need to be matched
  # cache_asset_regexps: ['cache_me.js', !ruby/regexp '/cache_some\.\d{8}\.css/']

development:
  <<: *defaults

test:
  <<: *defaults

production:
  <<: *defaults

Available Configuration Options

Most AssetSync configuration can be modified directly using environment variables with the Built-in initializer. e.g.

AssetSync.config.fog_provider == ENV['FOG_PROVIDER']

Simply upcase the ruby attribute names to get the equivalent environment variable to set. The only exception to that rule are the internal AssetSync config variables, they must be prepended with ASSET_SYNC_* e.g.

AssetSync.config.compression == ENV['ASSET_SYNC_COMPRESSION']

AssetSync (optional)

  • existing_remote_files: ('keep', 'delete', 'ignore') what to do with previously precompiled files. default: 'keep'
  • gzip_compression: (deprecated, can still be used but use compression when possible)
  • compression: ('gz', 'br') when enabled (non nil value set), will automatically replace files that have a gzip/brotli compressed equivalent with the compressed version. default: nil
  • manifest: (true, false) when enabled, will use the manifest.yml generated by Rails to get the list of local files to upload. experimental. default: 'false'
  • include_manifest: (true, false) when enabled, will upload the manifest.yml generated by Rails. default: 'false'
  • concurrent_uploads: (true, false) when enabled, will upload the files in different Threads, this greatly improves the upload speed. default: 'false'
  • concurrent_uploads_max_threads: when concurrent_uploads is enabled, this determines the number of threads that will be created. default: 10
  • remote_file_list_cache_file_path: if present, use this path to cache remote file list to skip scanning remote default: nil
  • remote_file_list_remote_path: if present, use this path to download remote file list file to cache file list in local to skip scanning remote. useful in container environment where you cannot maintain the local file, remote_file_list_cache_file_path also needed to make use of this option default: nil
  • enabled: (true, false) when false, will disable asset sync. default: 'true' (enabled)
  • ignored_files: an array of files to ignore e.g. ['ignore_me.js', %r(ignore_some/\d{32}\.css)] Useful if there are some files that are created dynamically on the server and you don't want to upload on deploy default: []
  • cache_asset_regexps: an array of files to add cache headers e.g. ['cache_me.js', %r(cache_some\.\d{8}\.css)] Useful if there are some files that are added to sprockets assets list and need to be set as 'Cacheable' on uploaded server. Only rails compiled regexp is matched internally default: []
Config Method add_local_file_paths

Adding local files by providing a block:

AssetSync.configure do |config|
  # The block should return an array of file paths
  config.add_local_file_paths do
    # Any code that returns paths of local asset files to be uploaded
    # Like Webpacker
    public_root = Rails.root.join("public")
    Dir.chdir(public_root) do
      packs_dir = Webpacker.config.public_output_path.relative_path_from(public_root)
      Dir[File.join(packs_dir, '/**/**')]
    end
  end
end

The blocks are run when local files are being scanned and uploaded

Config Method file_ext_to_mime_type_overrides

It's reported that mime-types 3.x returns application/ecmascript instead of application/javascript
Such change of mime type might cause some CDN to disable asset compression
So this gem has defined a default override for file ext js to be mapped to application/javascript by default

To customize the overrides:

AssetSync.configure do |config|
  # Clear the default overrides
  config.file_ext_to_mime_type_overrides.clear

  # Add/Edit overrides
  # Will call `#to_s` for inputs
  config.file_ext_to_mime_type_overrides.add(:js, :"application/x-javascript")
end

The blocks are run when local files are being scanned and uploaded

Fog (Required)

  • fog_provider: your storage provider AWS (S3) or Rackspace (Cloud Files) or Google (Google Storage) or AzureRM (Azure Blob) or Backblaze (Backblaze B2)
  • fog_directory: your bucket name

Fog (Optional)

  • fog_region: the region your storage bucket is in e.g. eu-west-1 (AWS), ord (Rackspace), japanwest (Azure Blob)
  • fog_path_style: To use buckets with dot in names, check fog/fog#2381 (comment)
  • fog_options: For extra fog options. Overrides any existing value (even those set by AssetSync)

AWS

  • aws_access_key_id: your Amazon S3 access key
  • aws_secret_access_key: your Amazon S3 access secret
  • aws_acl: set canned ACL of uploaded object, will override fog_public if set

Rackspace

  • rackspace_username: your Rackspace username
  • rackspace_api_key: your Rackspace API Key.

Google Storage

When using the JSON API

  • google_project: your Google Cloud Project name where the Google Cloud Storage bucket resides
  • google_json_key_location: path to the location of the service account key. The service account key must be a JSON type key

When using the S3 API

  • google_storage_access_key_id: your Google Storage access key
  • google_storage_secret_access_key: your Google Storage access secret

Azure Blob

  • azure_storage_account_name: your Azure Blob access key
  • azure_storage_access_key: your Azure Blob access secret

Backblaze B2

  • b2_key_id: Your Backblaze B2 key ID
  • b2_key_token: Your Backblaze B2 key token
  • b2_bucket_id: Your Backblaze B2 bucket ID

Rackspace (Optional)

  • rackspace_auth_url: Rackspace auth URL, for Rackspace London use: https://lon.identity.api.rackspacecloud.com/v2.0

Amazon S3 Multiple Region Support

If you are using anything other than the US buckets with S3 then you'll want to set the region. For example with an EU bucket you could set the following environment variable.

heroku config:add FOG_REGION=eu-west-1

Or via a custom initializer

AssetSync.configure do |config|
  # ...
  config.fog_region = 'eu-west-1'
end

Or via YAML

production:
  # ...
  fog_region: 'eu-west-1'

Amazon (AWS) IAM Users

Amazon has switched to the more secure IAM User security policy model. When generating a user & policy for asset_sync you must ensure the policy has the following permissions, or you'll see the error:

Expected(200) <=> Actual(403 Forbidden)

IAM User Policy Example with minimum require permissions (replace bucket_name with your bucket):

{
  "Statement": [
    {
      "Action": "s3:ListBucket",
      "Effect": "Allow",
      "Resource": "arn:aws:s3:::bucket_name"
    },
    {
      "Action": "s3:PutObject*",
      "Effect": "Allow",
      "Resource": "arn:aws:s3:::bucket_name/*"
    }
  ]
}

If you want to use IAM roles you must set config.aws_iam_roles = true in your initializers.

AssetSync.configure do |config|
  # ...
  config.aws_iam_roles = true
end

Automatic gzip/brotli compression

With the compression option enabled, when uploading your assets. If a file has a gzip/brotli (only 1 of them, depending on the option value set) compressed equivalent we will replace that asset with the compressed version and sets the correct headers for S3 to serve it. For example, if you have a file master.css and it was compressed to master.css.gz we will upload the .gz file to S3 in place of the uncompressed file.

If the compressed file is actually larger than the uncompressed file we will ignore this rule and upload the standard uncompressed version.

Option compression supported values:

  • nil => Disabled
  • 'gz' => Only consider gzip compressed one
  • 'br' => Only consider brotli compressed one

Fail Silently

With the fail_silently option enabled, when running rake assets:precompile AssetSync will never throw an error due to missing configuration variables.

With the new user_env_compile feature of Heroku (see above), this is no longer required or recommended. Yet was added for the following reasons:

With Rails 3.1 on the Heroku cedar stack, the deployment process automatically runs rake assets:precompile. If you are using ENV variable style configuration. Due to the methods with which Heroku compile slugs, there will be an error raised by asset_sync as the environment is not available. This causes heroku to install the rails31_enable_runtime_asset_compilation plugin which is not necessary when using asset_sync and also massively slows down the first incoming requests to your app.

To prevent this part of the deploy from failing (asset_sync raising a config error), but carry on as normal set fail_silently to true in your configuration and ensure to run heroku run rake assets:precompile after deploy.

Rake Task

A rake task is included within the asset_sync gem to perform the sync:

  namespace :assets do
    desc "Synchronize assets to S3"
    task :sync => :environment do
      AssetSync.sync
    end
  end

If AssetSync.config.run_on_precompile is true (default), then assets will be uploaded to S3 automatically after the assets:precompile rake task is invoked:

  if Rake::Task.task_defined?("assets:precompile:nondigest")
    Rake::Task["assets:precompile:nondigest"].enhance do
      Rake::Task["assets:sync"].invoke if defined?(AssetSync) && AssetSync.config.run_on_precompile
    end
  else
    Rake::Task["assets:precompile"].enhance do
      Rake::Task["assets:sync"].invoke if defined?(AssetSync) && AssetSync.config.run_on_precompile
    end
  end

You can disable this behavior by setting AssetSync.config.run_on_precompile = false.

Sinatra/Rack Support

You can use the gem with any Rack application, but you must specify two additional options; prefix and public_path.

AssetSync.configure do |config|
  config.fog_provider = 'AWS'
  config.fog_directory = ENV['FOG_DIRECTORY']
  config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
  config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
  config.prefix = 'assets'
  # Can be a `Pathname` or `String`
  # Will be converted into an `Pathname`
  # If relative, will be converted into an absolute path
  # via `::Rails.root` or `::Dir.pwd`
  config.public_path = Pathname('./public')
end

Then manually call AssetSync.sync at the end of your asset precompilation task.

namespace :assets do
  desc 'Precompile assets'
  task :precompile do
    target = Pathname('./public/assets')
    manifest = Sprockets::Manifest.new(sprockets, './public/assets/manifest.json')

    sprockets.each_logical_path do |logical_path|
      if (!File.extname(logical_path).in?(['.js', '.css']) || logical_path =~ /application\.(css|js)$/) && asset = sprockets.find_asset(logical_path)
        filename = target.join(logical_path)
        FileUtils.mkpath(filename.dirname)
        puts "Write asset: #{filename}"
        asset.write_to(filename)
        manifest.compile(logical_path)
      end
    end

    AssetSync.sync
  end
end

Webpacker (> 2.0) support

  1. Add webpacker files and disable run_on_precompile:
AssetSync.configure do |config|
  # Disable automatic run on precompile in order to attach to webpacker rake task
  config.run_on_precompile = false
  # The block should return an array of file paths
  config.add_local_file_paths do
    # Support webpacker assets
    public_root = Rails.root.join("public")
    Dir.chdir(public_root) do
      packs_dir = Webpacker.config.public_output_path.relative_path_from(public_root)
      Dir[File.join(packs_dir, '/**/**')]
    end
  end
end
  1. Add a asset_sync.rake in your lib/tasks directory that enhances the correct task, otherwise asset_sync runs before webpacker:compile does:
if defined?(AssetSync)
  Rake::Task['webpacker:compile'].enhance do
    Rake::Task["assets:sync"].invoke
  end
end

Caveat

By adding local files outside the normal Rails assets directory, the uploading part works, however checking that the asset was previously uploaded is not working because asset_sync is only fetching the files in the assets directory on the remote bucket. This will mean additional time used to upload the same assets again on every precompilation.

Running the specs

Make sure you have a .env file with these details:-

# for AWS provider
AWS_ACCESS_KEY_ID=<yourkeyid>
AWS_SECRET_ACCESS_KEY=<yoursecretkey>
FOG_DIRECTORY=<yourbucket>
FOG_REGION=<youbucketregion>

# for AzureRM provider
AZURE_STORAGE_ACCOUNT_NAME=<youraccountname>
AZURE_STORAGE_ACCESS_KEY=<youraccesskey>
FOG_DIRECTORY=<yourcontainer>
FOG_REGION=<yourcontainerregion>

Make sure the bucket has read/write permissions. Then to run the tests:-

foreman run rake

Todo

  1. Add some before and after filters for deleting and uploading
  2. Support more cloud storage providers
  3. Better test coverage
  4. Add rake tasks to clean old assets from a bucket

Credits

Inspired by:

License

MIT License. Copyright 2011-2013 Rumble Labs Ltd. rumblelabs.com

asset_sync's People

Contributors

amatsuda avatar anark avatar andyjeffries avatar arumugaraja-thirumani avatar atyndall avatar d-tasaki avatar davidjrice avatar ejholmes avatar fengb avatar freerobby avatar gordonbondon avatar griffindy avatar jordanrs avatar josacar avatar josephlord avatar jsmestad avatar kamui avatar karlfreeman avatar levent avatar manuelmeurer avatar marcgg avatar minasmart avatar mjonuschat avatar nomoon avatar overture8 avatar pikachuexe avatar rajyan avatar tosbourn avatar webmat avatar zinkkrysty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

asset_sync's Issues

Rake aboirted: Is a directory - /app/app/assets

Running with Rails 3.1.3 and Heroku cedar I get this error:

rake aborted!
Is a directory - /app/app/assets
/app/vendor/bundle/ruby/1.9.1/gems/asset_sync-0.2.3/lib/asset_sync/storage.rb:36:in `read'
/app/vendor/bundle/ruby/1.9.1/gems/asset_sync-0.2.3/lib/asset_sync/storage.rb:36:in `get_local_files'
/app/vendor/bundle/ruby/1.9.1/gems/asset_sync-0.2.3/lib/asset_sync/storage.rb:30:in `local_files'
/app/vendor/bundle/ruby/1.9.1/gems/asset_sync-0.2.3/lib/asset_sync/storage.rb:123:in `upload_files'
/app/vendor/bundle/ruby/1.9.1/gems/asset_sync-0.2.3/lib/asset_sync/storage.rb:134:in `sync'
/app/vendor/bundle/ruby/1.9.1/gems/asset_sync-0.2.3/lib/asset_sync/asset_sync.rb:29:in `sync'
/app/vendor/bundle/ruby/1.9.1/gems/asset_sync-0.2.3/lib/tasks/asset_sync.rake:6:in `block in <top (required)>'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/app/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/app/vendor/bundle/ruby/1.9.1/bin/rake:19:in `load'
/app/vendor/bundle/ruby/1.9.1/bin/rake:19:in `<main>'
Tasks: TOP => assets:precompile

Anything I could do to better debug this?

Fog directory can't be blank

Trying to run locally as described here: http://devcenter.heroku.com/articles/cdn-asset-host-rails31

Set the FOG_DIRECTORY but it does not seem to be picked up:

karl:viewthespace karl$ echo $FOG_DIRECTORY
vts-image-uploads

karl:viewthespace karl$ RAILS_GROUP=assets RAILS_ENV=development bundle exec rake assets:precompile --trace
rake/gempackagetask is deprecated.  Use rubygems/package_task instead
rake/rdoctask is deprecated.  Use rdoc/task instead (in RDoc 2.4.2+)
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/Users/karl/.rvm/rubies/ruby-1.9.2-p290/bin/ruby /Users/karl/.rvm/gems/ruby-1.9.2-p290@viewthespace/bin/rake assets:precompile:all RAILS_ENV=development RAILS_GROUPS=assets --trace
rake/gempackagetask is deprecated.  Use rubygems/package_task instead
rake/rdoctask is deprecated.  Use rdoc/task instead (in RDoc 2.4.2+)
** Invoke assets:precompile:all (first_time)
** Invoke add_assets_precompile_environment_var (first_time)
** Execute add_assets_precompile_environment_var
adding assets precompile env variable
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Invoke disable_rails_admin_initializer (first_time)
** Execute disable_rails_admin_initializer
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Invoke disable_rails_admin_initializer (first_time)
** Execute disable_rails_admin_initializer
** Execute environment
rake aborted!
Fog directory can't be blank
/Users/karl/.rvm/gems/ruby-1.9.2-p290@viewthespace/gems/asset_sync-0.2.1/lib/asset_sync/asset_sync.rb:24:in `sync'
/Users/karl/.rvm/gems/ruby-1.9.2-p290@viewthespace/gems/asset_sync-0.2.1/lib/tasks/asset_sync.rake:6:in `block in <top (required)>'
/Users/karl/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/Users/karl/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
/Users/karl/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/Users/karl/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/Users/karl/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/karl/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/karl/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/karl/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/Users/karl/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task'
/Users/karl/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:90:in `block (2 levels) in top_level'
/Users/karl/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/Users/karl/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:90:in `block in top_level'
/Users/karl/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/karl/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/Users/karl/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:62:in `block in run'
/Users/karl/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/karl/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/Users/karl/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'
/Users/karl/.rvm/gems/ruby-1.9.2-p290@viewthespace/bin/rake:19:in `load'
/Users/karl/.rvm/gems/ruby-1.9.2-p290@viewthespace/bin/rake:19:in `<main>'
Tasks: TOP => assets:precompile

I am running ruby-1.9.2 on rails3.1.3.

I am also getting this error on heroku.

thx!

-karl

config.existing_remote_files = 'delete' doesn't seem to work

I have the option set in my initializer but still my S3 folder is littered with old asset files.
On every deploy it says

 ** [out :: myapp.com] Fetching files to flag for delete
 ** [out :: myapp.com] Flagging 0 file(s) for deletion

What could be the cause?

Asset_sync when compiling dynamically

I have some assets that I don't want precompiled (like the admin panel) because they take time during our deploy and are served as part of the minified assets to all users. I can take them out of the precompile array and enable dynamically serving assets but when rails compiles them dynamically, asset_sync doesn't sync them to s3, yet the app still looks for the assets on s3. Is there a way around this?

Aws access key can't be blank, Aws access secret can't be blank, Aws bucket can't be blank

Hi

I follow the readme (Hardcode S3 credential)

When I launch assets:precompile I get : Aws access key can't be blank, Aws access secret can't be blank, Aws bucket can't be blank

But my credential is OK

defaults: &defaults
aws_access_key: 'KEY'
aws_access_secret: 'SECRET'
aws_region: 'eu-west-1'
existing_remote_files: keep
production:
<<: *defaults
aws_bucket: "bucket"

I try to "fixe" and this work when I change the asset_sync.rb in config : @config ||= Config.new to @config = Config.new

Seems the config is call 2 times, and the first it initialize aws_access_key with nil

Setting Expires header for uploaded items

The only issue I've seen with this gem is that it doesn't set an Expires HTTP header to the far-future when it uploads the assets to S3. This would be a great performance enhancement.

I may work on adding this myself, but I wanted to make sure that this was an appropriate addition.

Precompile failing to sync (403 Forbidden)

I have not been able to get my assets to sync to my amazon bucket. I know that my app has access to the bucket, as I have given it permission via a group policy shown below, but no matter what I have tried I can't get my assets to sync. I keep getting a HTTP 403 error code.

ruby-1.9.2-p290

gem 'rails', '3.1.1'
gem 'asset_sync', '~> 0.1.9'
AssetSync.configure do |config|
  config.aws_access_key = '[KEY]'
  config.aws_access_secret = '[SECRET]'
  config.aws_bucket = '[bucket]'
  config.existing_remote_files = "keep"
  # Increase upload performance by configuring your region
  # config.aws_region = "eu-west-1"
  # Automatically replace files with their equivalent gzip compressed version
  # config.gzip_compression = true
end

on push to heroku

-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       /tmp/build_10dnyp6p3sc0u/vendor/bundle/ruby/1.9.1/gems/airbrake-3.0.4/lib/airbrake.rb:134:in `send_notice': undefined method `send_to_airbrake' for nil:NilClass (NoMethodError)
       from /tmp/build_10dnyp6p3sc0u/vendor/bundle/ruby/1.9.1/gems/airbrake-3.0.4/lib/airbrake.rb:103:in `notify'
       from /tmp/build_10dnyp6p3sc0u/vendor/bundle/ruby/1.9.1/gems/airbrake-3.0.4/lib/airbrake/rake_handler.rb:15:in `display_error_message_with_airbrake'
       from /tmp/build_10dnyp6p3sc0u/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:142:in `rescue in standard_exception_handling'
       from /tmp/build_10dnyp6p3sc0u/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:132:in `standard_exception_handling'
       from /tmp/build_10dnyp6p3sc0u/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
       from /tmp/build_10dnyp6p3sc0u/vendor/bundle/ruby/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
       from /tmp/build_10dnyp6p3sc0u/vendor/bundle/ruby/1.9.1/bin/rake:19:in `load'
       from /tmp/build_10dnyp6p3sc0u/vendor/bundle/ruby/1.9.1/bin/rake:19:in `<main>'
       Precompiling assets failed, enabling runtime asset compilation
       Injecting rails31_enable_runtime_asset_compilation
       Please see this article for troubleshooting help:
       http://devcenter.heroku.com/articles/rails31_heroku_cedar#troubleshooting

compiling from command line

[staging][~/goswim] heroku run rake assets:precompile --app staging-goswim
Running rake assets:precompile attached to terminal... up, run.6
/usr/local/bin/ruby /app/vendor/bundle/ruby/1.9.1/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
** [NewRelic][11/14/11 12:18:58 +0000 5e3c3c91-52bc-41eb-87a1-9dc3a92768fa (31)] INFO : Dispatcher: thin
** [NewRelic][11/14/11 12:18:58 +0000 5e3c3c91-52bc-41eb-87a1-9dc3a92768fa (31)] INFO : Application: staging-goswim
** [NewRelic][11/14/11 12:18:58 +0000 5e3c3c91-52bc-41eb-87a1-9dc3a92768fa (31)] INFO : New Relic Ruby Agent 3.2.0.1 Initialized: pid = 31
** [NewRelic][11/14/11 12:18:59 +0000 5e3c3c91-52bc-41eb-87a1-9dc3a92768fa (31)] INFO : NewRelic::Agent::Samplers::DelayedJobLockSampler sampler not available: No DJ worker present
** [NewRelic][11/14/11 12:19:09 +0000 5e3c3c91-52bc-41eb-87a1-9dc3a92768fa (31)] INFO : Resolved collector.newrelic.com to 204.93.223.153
** [NewRelic][11/14/11 12:19:10 +0000 5e3c3c91-52bc-41eb-87a1-9dc3a92768fa (31)] INFO : Resolved collector-3.newrelic.com to 204.93.223.137
Connected to NewRelic Service at collector-3.newrelic.com:80
** [NewRelic][11/14/11 12:19:10 +0000 5e3c3c91-52bc-41eb-87a1-9dc3a92768fa (31)] INFO : Reporting performance data every 60 seconds.
/usr/local/bin/ruby /app/vendor/bundle/ruby/1.9.1/bin/rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets
** [NewRelic][11/14/11 12:19:33 +0000 5e3c3c91-52bc-41eb-87a1-9dc3a92768fa (64)] INFO : Dispatcher: thin
** [NewRelic][11/14/11 12:19:33 +0000 5e3c3c91-52bc-41eb-87a1-9dc3a92768fa (64)] INFO : Application: staging-goswim
** [NewRelic][11/14/11 12:19:33 +0000 5e3c3c91-52bc-41eb-87a1-9dc3a92768fa (64)] INFO : New Relic Ruby Agent 3.2.0.1 Initialized: pid = 64
** [NewRelic][11/14/11 12:19:33 +0000 5e3c3c91-52bc-41eb-87a1-9dc3a92768fa (64)] INFO : NewRelic::Agent::Samplers::DelayedJobLockSampler sampler not available: No DJ worker present
** [NewRelic][11/14/11 12:19:42 +0000 5e3c3c91-52bc-41eb-87a1-9dc3a92768fa (31)] WARN : Disabling serialization: Read-only file system - /newrelic_agent_store.db
** [NewRelic][11/14/11 12:19:46 +0000 5e3c3c91-52bc-41eb-87a1-9dc3a92768fa (6)] INFO : Dispatcher: thin
** [NewRelic][11/14/11 12:19:46 +0000 5e3c3c91-52bc-41eb-87a1-9dc3a92768fa (6)] INFO : Application: staging-goswim
** [NewRelic][11/14/11 12:19:46 +0000 5e3c3c91-52bc-41eb-87a1-9dc3a92768fa (6)] INFO : New Relic Ruby Agent 3.2.0.1 Initialized: pid = 6
** [NewRelic][11/14/11 12:19:46 +0000 5e3c3c91-52bc-41eb-87a1-9dc3a92768fa (6)] INFO : NewRelic::Agent::Samplers::DelayedJobLockSampler sampler not available: No DJ worker present
rake aborted!
Expected(200) <=> Actual(403 Forbidden)
  request => {:connect_timeout=>60, :headers=>{"Date"=>"Mon, 14 Nov 2011 12:19:49 +0000", "Authorization"=>"AWS [KEY]:[pass]", "Host"=>"[bucket].s3.amazonaws.com:443", "Content-Length"=>0}, :host=>"[bucket].s3.amazonaws.com", :mock=>nil, :path=>"/", :port=>"443", :query=>{}, :read_timeout=>60, :scheme=>"https", :write_timeout=>60, :expects=>200, :idempotent=>true, :method=>"GET"}
  response => #<Excon::Response:0x00000005dd06f8 @body="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>59E95DA3405C280D</RequestId><HostId>FtbIFLAD3oK4LQLnqgX8uygY+8kRXbpLaTPWTUjdtmxrTE2n1J0UDlAzJHe6jf7d</HostId></Error>", @headers={"x-amz-request-id"=>"59E95DA3405C280D", "x-amz-id-2"=>"FtbIFLAD3oK4LQLnqgX8uygY+8kRXbpLaTPWTUjdtmxrTE2n1J0UDlAzJHe6jf7d", "Content-Type"=>"application/xml", "Transfer-Encoding"=>"chunked", "Date"=>"Mon, 14 Nov 2011 12:19:49 GMT", "Server"=>"AmazonS3"}, @status=403>

Tasks: TOP => assets:precompile

And a resultant Log from my S3 Bucket

fd69332feeccfaac7caf291d645bda05c982f1c6bb12d29015c3cdf7ef5a882d [bucket] [14/Nov/2011:11:08:28 +0000] 195.241.148.235 arn:aws:iam::[user]:user/[group] FCC131D7A7B1BE76 REST.GET.BUCKET - "GET / HTTP/1.1" 403 AccessDenied 231 - 15 - "-" "-" -
fd69332feeccfaac7caf291d645bda05c982f1c6bb12d29015c3cdf7ef5a882d [bucket] [14/Nov/2011:11:17:27 +0000] 10.194.22.16 3272ee65a908a7677109fedda345db8d9554ba26398b2ca10581de88777e2b61 2BE3A542843C517D REST.PUT.OBJECT logs2011-11-14-11-17-27-8464AC8CEC983217 "PUT /[bucket]/logs2011-11-14-11-17-27-8464AC8CEC983217 HTTP/1.1" 403 AccessDenied 231 818 19 - "-" "Jakarta Commons-HttpClient/3.0" -
fd69332feeccfaac7caf291d645bda05c982f1c6bb12d29015c3cdf7ef5a882d [bucket] [14/Nov/2011:11:22:14 +0000] 10.119.93.14 fd69332feeccfaac7caf291d645bda05c982f1c6bb12d29015c3cdf7ef5a882d 6120BB9FAEA5BFAA REST.GET.BUCKET - "GET /[bucket]?prefix=&max-keys=100&marker=&delimiter=/ HTTP/1.1" 200 - 1136 - 41 39 "-" "S3Console/0.4" -
fd69332feeccfaac7caf291d645bda05c982f1c6bb12d29015c3cdf7ef5a882d [bucket] [14/Nov/2011:11:22:21 +0000] 10.194.64.24 fd69332feeccfaac7caf291d645bda05c982f1c6bb12d29015c3cdf7ef5a882d 959249E37A0007D9 REST.GET.BUCKETPOLICY - "GET /[bucket]?policy HTTP/1.1" 404 NoSuchBucketPolicy 297 - 41 - "-" "S3Console/0.4" -

my user group policy should give my S3 user account access to all actions on the S3 bucket, and it shouldn't be rejected

{
  "Statement": [
    {
      "Sid": "staging",
      "Action": "s3:*",
      "Effect": "Allow",
      "Resource": "arn:aws:s3:::[bucket]/*"
    }
  ]
}

Error with rails 3.1.1

Hello,

According to 3.1.1 release note :

"rake assets:precompile loads the application but does not initialize it.

To the app developer, this means configuration add in config/initializers/* will not be executed.

Plugins developers need to special case their initializers that are meant to be run in the assets group by adding :group => :assets. [José Valim]"

Does'nt works with initializer or yml.

Mickael.

Does not work with heroku using the initializer.

This is my config/initializers/asset_sync.rb:

if Rails.groups.include?("assets")
  AssetSync.configure do |config|
    config.fog_provider          = ENV.fetch("FOG_PROVIDER")
    config.aws_access_key_id     = ENV.fetch("AWS_ACCESS_KEY_ID")
    config.aws_secret_access_key = ENV.fetch("AWS_SECRET_ACCESS_KEY")
    config.fog_directory         = ENV.fetch("FOG_DIRECTORY")
    config.fog_region            = ENV.fetch("FOG_REGION")
    config.existing_remote_files = "delete"
    config.gzip_compression      = true
    config.fail_silently         = false
  end
end

When I git push heroku, however, I get NO output from AssetSync:

-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
-----> Rails plugin injection

I have the user_env_compile plugin installed, and I can confirm that the environment variables are present when the environment is initialized (I have added puts statements to the asset_sync initializer to confirm this).

What I have to do to deploy the assets is locally run rake assets:precompile assets:clean. I have a (git-ignored) config/asset_sync.yml file that is used when compiling locally. I would rather not add my AWS credentials to the git repository.

I'm running:

  • asset_sync (0.2.8)
  • rails (3.2.1)
  • sprockets (2.1.2)

Any ideas what might be wrong? It's a pain to remember to manually sync the assets before git push heroku, so any help is appreciated :)

CSS not uploaded to S3

Hi,

I just started using asset_sync and am not sure if I'm missing something obvious. It could be that I have my asset pipeline misconfigured. I'm not seeing any of my CSS files being uploaded to my S3 bucket. Any idea why this might be the case? It exists in my Rails app on Heroku, but the corresponding file is not on S3.

Thanks for any insight!

EDIT: I did have to disable CSS compression because there is a Rails error having to do with SASS.... Not sure if that could have to do with it?

~Joel

asset_sync doesn't respect config.assets.prefix

For example, if you have different asset sets for staging, production, etc. you may wish to use this to store your assets in different directories:

staging.rb
config.assets.prefix = "assets-staging"

production.rb  
# use the default of:
# config.assets.prefix = "assets"

When you run the assets:precompile task, all assets in your staging environment are taken from your local public/assets and uploaded to /assets in the corresponding amazon bucket regardless of the prefix setting.

Null Asset Directory

Using jQuery.syntax for syntax highlighting on a rails 3.1 server we are getting issues once migrating our assets to the cloud. Syntax highlighting works locally with no JS errors, but when deployed to heroku using asset_sync we get /nulljquery.syntax.core.js GET requests to our server. Why would rails think that a precompiled asset was stored at this location when we can see that during asset precompilation, the file has already been stored on S3:

Ignoring: assets/jquery.syntax.core-d8b38d86909c8843afd05425d9ace884.js.gz

Here is the contents of our application.js file:

//= require jquery
//= require jquery_ujs
//= require jquery_nested_form
//= require jquery.syntax.min

refreshing assets within cloudfront

I made a change to my css and ran:

RAILS_GROUP=assets RAILS_ENV=development bundle exec rake assets:precompile --trace

I don't see any output of it uploading anything new.

/Users/karl/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
/Users/karl/.rvm/gems/ruby-1.9.2-p290@viewthespace/bin/rake
assets:precompile:all RAILS_ENV=development RAILS_GROUPS=assets --trace
rake/gempackagetask is deprecated.  Use rubygems/package_task instead
rake/rdoctask is deprecated.  Use rdoc/task instead (in RDoc 2.4.2+)
** Invoke assets:precompile:all (first_time)
** Invoke add_assets_precompile_environment_var (first_time)
** Execute add_assets_precompile_environment_var
adding assets precompile env variable
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Invoke disable_rails_admin_initializer (first_time)
** Execute disable_rails_admin_initializer
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Invoke disable_rails_admin_initializer (first_time)
** Execute disable_rails_admin_initializer
** Execute environment
Using: Directory Search of
/Users/karl/workspace/viewthespace/public/assets

And when i look at the application.css, it is the older version still.

So i have two questions:

  1. Why didn't it upload the new version?
  2. Even if it did upload the version, how would it get refreshed within amazon cloudfront?

thx!

Automagic asset compression

I've written a monkeypatch for AssetSync::Storage#upload_file that automagically replaces assets with gzipped versions. You may want to consider implementing its functionality (although perhaps in a user-configurable manner).

# automagically compress assets
if defined?(AssetSync)
  gem 'asset_sync', '= 0.1.8' # die early if asset_sync may have changed

  class AssetSync::Storage
    def upload_file(f)
      STDERR.puts "Uploading: #{f}"

      gzip = File.exist?("#{path}/#{f}.gz") # enable gzip compression if a gz asset exists
      name = gzip ? f + '.gz' : f # use the gzipped asset's contents
      mime = Mime::Type.lookup_by_extension File.extname(f)[1..-1] # detect MIME type

      file = bucket.files.create(
        :key              => "#{f}",
        :body             => File.open("#{path}/#{name}"),
        :public           => true,
        :cache_control    => "max-age=31557600",
        :content_type     => mime, # explicitly provide content-type for assets AWS isn't aware of
        :content_encoding => gzip ? 'gzip' : nil # gzipped-assets require Content-Encoding header
      )
    end
  end
end

asset_path in css.erb is not properly handled

Just bumped into the issue that css.erb is not handled properly. As you can see below, the region is missing.

css.erb

body {width:100%; height: 100%;padding:0; margin:0; font-family:Arial, verdana, sans-serif;background:#fff url('<%= asset_path 'main/bg_body.gif' %>') repeat-y center 0;}

processed css

body{width:100%;height:100%;padding:0;margin:0;font-family:Arial, verdana, sans-serif;background:#fff url("http://.s3.amazonaws.com/assets/main/bg_body-0cb881d8e11ed182a85fddb437b7687e.gif") repeat-y center 0}

Any other files have no problems.

Ruby 1.9.3-p0 / Rails 3.2.1 on Heroku
It works just fine on local

Assets aren't uploaded on Heroku deploy

I'm using Rails 3.1.RC6 and have added asset_sync into my project for deploy to Heroku. When I deploy with a new git push, the assets are not uploaded to my S3 bucket. However, if I run

heroku run rake assets:precompile

then they are uploaded successfully. This implies that the setup is correct but for some reason the rake task isn't getting run on deploy. I'll open a ticket with Heroku as well, but given that you mention this will work "automagically" I wondered if you had any ideas?

This asset host cannot be computed without a request in scope. Remove the second argument to your asset_host Proc if you do not need the request, or make it optional.

I get this when uploading to Heroku

   Running: rake assets:precompile
   AssetSync: using default configuration from built-in initializer
   Compiled jquery.js  (1ms)  (pid 1209)
   Compiled jquery_ujs.js  (0ms)  (pid 1209)
   Compiled jquery.iframe-transport.js  (0ms)  (pid 1209)
   Compiled jquery.remotipart.js  (5ms)  (pid 1209)
   Compiled bootstrap-alert.js  (0ms)  (pid 1209)
   Compiled bootstrap-dropdown.js  (0ms)  (pid 1209)
   Compiled bootstrap-modal.js  (0ms)  (pid 1209)
   Compiled bootstrap-tab.js  (0ms)  (pid 1209)
   Compiled bootstrap.js  (0ms)  (pid 1209)
   Compiled jquery.lightbox-0.5.min.js  (0ms)  (pid 1209)
   Compiled application.js  (123ms)  (pid 1209)
   Compiled bootstrap.css  (0ms)  (pid 1209)
   Compiled chart.css  (0ms)  (pid 1209)
   Compiled custom.css  (0ms)  (pid 1209)
   Compiled jquery.lightbox-0.5.css  (0ms)  (pid 1209)
   Compiled application.css  (13ms)  (pid 1209)
   Compiled iPhone.css.old  (0ms)  (pid 1209)
   Compiled scaffold.css.old  (0ms)  (pid 1209)
   Compiled rails_admin/jquery.colorpicker.js  (0ms)  (pid 1209)
   Compiled jquery.effects.core.js  (0ms)  (pid 1209)
   Compiled jquery.ui.core.js  (1ms)  (pid 1209)
   Compiled jquery.ui.widget.js  (0ms)  (pid 1209)
   Compiled jquery.ui.mouse.js  (2ms)  (pid 1209)
   Compiled jquery.ui.sortable.js  (68ms)  (pid 1209)
   Compiled jquery.ui.position.js  (0ms)  (pid 1209)
   Compiled jquery.ui.autocomplete.js  (6ms)  (pid 1209)
   Compiled jquery.ui.datepicker.js  (1ms)  (pid 1209)
   Compiled rails_admin/jquery.ui.timepicker.js  (0ms)  (pid 1209)
   Compiled rails_admin/ra.datetimepicker.js  (0ms)  (pid 1209)
   Compiled rails_admin/ra.filter-box.js  (0ms)  (pid 1209)
   Compiled rails_admin/ra.filtering-multiselect.js  (0ms)  (pid 1209)
   Compiled rails_admin/ra.filtering-select.js  (0ms)  (pid 1209)
   Compiled rails_admin/ra.remote-form.js  (0ms)  (pid 1209)
   Compiled rails_admin/jquery.pjax.js  (0ms)  (pid 1209)
   Compiled jquery_nested_form.js  (0ms)  (pid 1209)
   Compiled rails_admin/ra.nested-form-hooks.js  (151ms)  (pid 1209)
   Compiled rails_admin/ui.js  (176ms)  (pid 1209)
   Compiled rails_admin/themes/default/ui.js  (0ms)  (pid 1209)
   Compiled rails_admin/custom/ui.js  (0ms)  (pid 1209)
   Compiled rails_admin/rails_admin.js  (539ms)  (pid 1209)
   rake aborted!
   This asset host cannot be computed without a request in scope. Remove the second argument to your asset_host Proc if you do not need the request, or make it optional.
   (in /tmp/build_3abhna11koms2/vendor/bundle/ruby/1.9.1/bundler/gems/rails_admin-576e3e4cfada/app/assets/stylesheets/rails_admin/jquery.colorpicker.css.scss)

It's on Heroku with Ruby 1.9.3.p0 and Rails 3.2.1.

config.action_controller.asset_host = Proc.new do |source, request|
request.ssl? ? "https://#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com" : "http://#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"
end

If I change the above lines to the old one below, it works just fine.

config.action_controller.asset_host = "http://#{ENV['FOG_DIRECTORY']}.s3.amazonaws.com"

Is this related to the following Rails issue or seperate one?

rails/rails#2947

Sorry, 0.2.12 with Rails 3.2.2 on Heroku Does Not Work.

Doing heroku push staging master results in:

      <...>
       Your bundle is complete! It was installed into ./vendor/bundle
       Cleaning up the bundler cache.
-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       rake aborted!
       Fog provider can't be blank, Fog directory can't be blank

       Tasks: TOP => assets:precompile:nondigest
       (See full trace by running task with --trace)
       Precompiling assets failed, enabling runtime asset compilation
       Injecting rails31_enable_runtime_asset_compilation
       Please see this article for troubleshooting help:
       http://devcenter.heroku.com/articles/rails31_heroku_cedar#troubleshooting
-----> Rails plugin injection
       Injecting rails_log_stdout
       Injecting rails3_serve_static_assets

Yes, I have user_env_compile set:

# heroku labs --remote staging
=== App Features (xxxxx-xxxxx-5305)
[+] user_env_compile          # Add user config vars to the environment during slug compilation

=== User Features ([email protected])
[ ] heroku-shared-postgresql  # PostgreSQL 9.1 shared database service.

Thought it might be because I was using Ruby 1.9.3-p0, so I switched back to 1.9.2. No difference.

Tried heroku run rake assets:precompile --remote staging with (deprecation warnings removed):

Running rake assets:precompile attached to terminal... up, run.1
/app/vendor/ruby-1.9.3-p0/bin/ruby /app/vendor/bundle/ruby/1.9.1/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
WARNING on line 384 of /app/app/assets/stylesheets/theme_base.css.sass:
This selector doesn't have any properties and will not be rendered.
WARNING on line 434 of /app/app/assets/stylesheets/theme_base.css.sass:
This selector doesn't have any properties and will not be rendered.
WARNING on line 300 of /app/app/assets/stylesheets/partials/_screen.css.sass:
This selector doesn't have any properties and will not be rendered.
WARNING on line 409 of /app/app/assets/stylesheets/partials/_screen.css.sass:
This selector doesn't have any properties and will not be rendered.

rake aborted!
Fog provider can't be blank, Fog directory can't be blank

Tasks: TOP => assets:precompile:nondigest
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/app/vendor/ruby-1.9.3-p0/bin/ruby /app/ve...]

Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

md5 hash problem

Hi,

All image files do get uploaded to the bucket, but they are renamed to include the md5 hash and image_path helper in SASS still links to the original filename. Is this a bug?

Using a subfolder on production

Hi Guys,

we're using a subfolder /a/ on our production environment. This is done with passenger_base_uri /a
The app is now looking for /a/assets/ on our CloudFront domain, but your gem is putting everything in /assets/.
Can you support a subfolder setting in your config like fog_sub_directory or do I miss any other easy solution?

Best,
Konstantin

With compression enabled, what happens if browser doesn't support gzip?

Sorry first if this is the wrong place for the post, but I'm wondering about this:

With the gzip_compression option enabled, when uploading your assets. If a file has a gzip compressed equivalent we will replace that asset with the compressed version and sets the correct headers for S3 to serve it

Now I need to set the content-encoding to gzip for gz files, and then decide which one to serve for the user. But what this seems to do is remove the uncompressed file, so I'm wondering what will happen for browsers that don't support compression.

Error on running assets precompile

I'm not sure I'm understanding what's going on here, I've done the asset config, set fail silent to true as per docs, config looks ok, but after heroku deploy when I run the rake I get this:

$ heroku run rake assets:precompile --trace
Running rake assets:precompile --trace attached to terminal... up, run.1
** Invoke assets:precompile (first_time)
** Execute assets:precompile
mkdir -p /app/public/assets
rake aborted!
Permission denied - /app/public/assets

Where is the mkdir failing? on S3? Permissions issue on S3? Heroku issue?

Thanks for any help.

Apparently unnecessarily warning

Every time the environment is loaded the following warning is displayed:

AssetSync: using /Users/Leandro/Sites/NewProject/config/initializers/asset_sync.rb

The version of asset_sync i'm using is 0.1.7.

Files that already exist on S3 are still uploaded

We have many more than 1000 files in our S3 bucket, but the default value for max-keys in fog is 1000. This means that AssetSync::Storage::get_remote_files only returns the first 1000 files found, meaning that, although local_files_to_upload should be empty, it ends up containing many thousands of files.

Local files should perhaps be built from the manifest.yml

The manifest file specified in config.assets.manifest contains a mapping between local filenames and compiled assets. Perhaps AssetSync::Storage::local_files could read the manifest, rather than iterating over the contents of public/assets (which may not have been cleaned, and which definitely contains the files without the CRC as well as the files with the CRC).

excon 0.10.0 released and stack trace

Hello,

Gemfile (relevant parts) if you want to test:

gem 'asset_sync', '~> 0.3.1'
gem 'fog', :git => 'git://github.com/fog/fog.git'
gem 'excon', '>= 0.9.6'

I'm getting this now during precompilation:

** Invoke assets:precompile (first_time)
** Execute assets:precompile
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
Starting revision: SHA 57995716599e8886f39a685a76cabe1534d7fc50
AssetSync: using /Users/kain/Sites/myapp/rails/config/initializers/asset_sync.rb
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
** Invoke assets:precompile:nondigest (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
Starting revision: SHA 57995716599e8886f39a685a76cabe1534d7fc50
AssetSync: using /Users/kain/Sites/myapp/rails/config/initializers/asset_sync.rb
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:nondigest
AssetSync: Syncing.
Using: Manifest /Users/kain/Sites/myapp/rails/public/assets/manifest.yml
Uploading: /Users/kain/Sites/myapp/rails/public/assets/player-69ae6b7aee678556bd9a8117d61f02fd.js.gz in place of assets/player-69ae6b7aee678556bd9a8117d61f02fd.js saving 27.68%
rake aborted!
undefined method `empty?' for #<File:0x007fdccc2cec90>
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/excon-0.10.0/lib/excon/connection.rb:211:in `request_kernel'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/excon-0.10.0/lib/excon/connection.rb:92:in `request'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/bundler/gems/fog-2a4abcd092b7/lib/fog/core/connection.rb:20:in `request'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/bundler/gems/fog-2a4abcd092b7/lib/fog/aws/storage.rb:359:in `request'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/bundler/gems/fog-2a4abcd092b7/lib/fog/aws/requests/storage/put_object.rb:43:in `put_object'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/bundler/gems/fog-2a4abcd092b7/lib/fog/aws/models/storage/file.rb:133:in `save'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/bundler/gems/fog-2a4abcd092b7/lib/fog/core/collection.rb:50:in `create'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/asset_sync-0.3.1/lib/asset_sync/storage.rb:121:in `upload_file'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/asset_sync-0.3.1/lib/asset_sync/storage.rb:133:in `block in upload_files'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/asset_sync-0.3.1/lib/asset_sync/storage.rb:131:in `each'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/asset_sync-0.3.1/lib/asset_sync/storage.rb:131:in `upload_files'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/asset_sync-0.3.1/lib/asset_sync/storage.rb:140:in `sync'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/asset_sync-0.3.1/lib/asset_sync/asset_sync.rb:29:in `sync'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/asset_sync-0.3.1/lib/tasks/asset_sync.rake:3:in `block in <top (required)>'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/kain/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/bin/rake:19:in `load'
/Users/kain/.rvm/gems/ruby-1.9.3-p125/bin/rake:19:in `<main>'
Tasks: TOP => assets:precompile:nondigest

multiple environments on heroku

Every time I try to run 'heroku run bundle exec rake assets:precompile' against my staging environment, three files are generated: one for production, one for staging, and one without a digest. I'd like to only generate the fingerprinted staging assets and leave out the others.

Unknown region: "sa-east-1"

There is problem with São Paulo Region in fog. Whenever I ran rake assets:precompile i got the error above. The assets compile successfully but they are not synced.

I'm using asset_sync 0.3.1 that uses fog 0.9.0. The bug is reported on fog.

According to fog forums, it was corrected in newer versions of fog, at least it was corrected 3 months ago in fog.

Is that a case of updating dependencies?

Storage::get_remote_files returns non-asset files

Our bucket contains static assets uploaded by asset_sync (in an "assets" directory) as well as a bunch of other files (in other directories, such as "uploads"). Storage::get_remote_files returns everything. This is potentially dangerous, as Storage::delete_extra_remote_files would delete these non-asset files if we enabled it, and if issue 16 wasn't stopping Storage::get_remote_files from working.

Is there a verbose option?

It would be nice to see a summary of what happened during a sync operation but I didn't see anything in the config options.

Great library btw!

Assets compiled twice on server

Hello,
Rails 3.2.1, Capistrano, RVM, asset_sync (master), EC2

In order for asset_sync to upload something to S3 I had to write a Rake task as pointed out in another ticket:

Rake::Task["assets:precompile:nondigest"].enhance do
  Rake::Task["assets:environment"].invoke if Rake::Task.task_defined?("assets:environment")
  AssetSync.sync
end

The problem is that I'm seeing that during the deploy the server compiles the assets two times.

Capfile contains load 'deploy/assets', digest are enabled.

Maybe related:
rails/rails#3192

Default AssetSync.config.enabled in production/staging env

From a previous issue...

So I think possibly the best way is to have an Array of environments. (Defaulted to production and staging)

AssetSync.configure do |config|
  config.environments = [:production, :staging]
end

This could then be modified by the initializer.
Enabling via YAML and ENV variable might require accepting non-symbol environment names in a comma separated string.

Log what mode of configuration is being used

In the engine.rb it would be a good idea to re-enable logging to debug if we are:

  • using a built-in initializer
  • using a custom initializer
  • using a YAML file

We may also want to consider loading the ENV variables part of the built in initializer to ensure that if a user has defined a custom initializer but commented it out... we will still capture the other ENV vars. (Related to #49)

Public folder assets are not synced

Some gems, like ckeditor put their JS files in your public folder. Is there any way to ensure that /public/javascripts gets pushed to S3 along with all my other assets? I'm using latest asset_sync with initializer.rb

Refreshing of the asset cache

Sorry this is not an issue... just a question. How does asset_sync refresh the cloudfront cache when new assets are uploaded? From what i understand, cloudfront caches files for 24 hours.

thx!

Works with Rails 3.2.0?

I just upgraded to Rails 3.2.0 and asset_sync 0.2.5 and it doesn't seem to work.
I followed the upgrade instructions in the Readme and everything went fine, but when I deploy with Capistrano, the assets are not uploaded to S3.

This is my config/initializers/asset_sync.rb:

AssetSync.configure do |config|
  config.fog_provider          = 'AWS'
  config.aws_access_key_id     = AppConfig.aws[:key]
  config.aws_secret_access_key = AppConfig.aws[:secret]
  config.fog_directory         = AppConfig.aws[:bucket]

  # Increase upload performance by configuring your region
  config.fog_region = AppConfig.aws[:region]

  # Don't delete files from the store
  config.existing_remote_files = 'delete'

  # Automatically replace files with their equivalent gzip compressed version
  config.gzip_compression = true

  # Use the Rails generated 'manifest.yml' file to produce the list of files to
  # upload instead of searching the assets directory.
  # config.manifest = true

  # Fail silently. Useful for environments such as Heroku
  # config.fail_silently = true
end

and my lib/tasks/asset_sync.rake:

Rake::Task['assets:precompile'].enhance do
  AssetSync.sync
end

When I call AssetSync.sync from the Rails console on production after deploy, it works as expected and the assets are uploaded.

Doesn't look outside public/assets

Our rails app has a custom config.asset.prefix, when running the assets:precompile the asset sync only looks in the default asset location "public/assets"

"Using: Directory Search of ***/public/assets
Done."

Rails 3.2.1
Ruby 1.9.2
Asset_sync (0.3.1)

Rails.application.config.assets.prefix returns "/assets"

Seems to be a small issue with 0.2.4 and the Rails 3-2-stable branch. Rails.application.config.assets.prefix returns "/assets" if not set explicitly, which creates "/ /assets" on S3. Will check if explicitly setting config.assets.prefix to "assets" solves it.

Initializer looks like:

AssetSync.configure do |config|
config.fog_provider = 'AWS'
config.aws_access_key_id =
config.aws_secret_access_key =
config.fog_directory = 'assets-staging' #ENV['FOG_DIRECTORY']

Increase upload performance by configuring your region

config.fog_region = ''

Don't delete files from the store

config.existing_remote_files = "delete"

Automatically replace files with their equivalent gzip compressed version

config.gzip_compression = true

Use the Rails generated 'manifest.yml' file to produce the list of files to

upload instead of searching the assets directory.

config.manifest = true

end

[GitHub]a5fcbf2

Calculation of local_files_to_upload is incorrect

In AssetSync::Storage::upload_files, the list of files to upload is calculates as follows:

local_files_to_upload = (remote_files | local_files) - (remote_files & local_files)

This means that asset_sync will attempt to upload files that are present in remote_files but which are not present in local_files. This will break if, for example, the assets directory is cleaned, but old versions of assets are being kept on S3. Perhaps this should be changed to:

local_files_to_upload = local_files - remote_files

What do you suggest to disable asset_sync? (precompile => PhoneGap)

Hey guys,

I love the simplicity of asset_sync. I've recently set it up to deploy my mobile web app's assets to a CDN and it works like a charm!

However I need to precompile my assets for a PhoneGap app, and I can't find any obvious way to simply turn off AssetSync in that scenario.

I've created a dummy config/environments/hybrid.rb to tweak the asset pipeline for my app's needs.

I've tried creating config/initializers/asset_sync.rb and wrapping the config block in a if that checks for the proper Rails.env, but precompilation still fails with Fog provider can't be blank, Fog directory can't be blank.

Any suggestions?

I'm currently looking at the code to see if I can figure out a clean patch I could contribute. But if you already have something in mind, I'd love to hear about it.

Thanks!

plugin heroku-labs has been deprecated

... so what about

heroku plugins:install https://github.com/heroku/heroku-labs.git
heroku labs:enable user_env_compile -a myapp

to evoid the deploy precompile error on Heroku ?

-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       rake aborted!
       Fog provider can't be blank, Fog directory can't be blank
       
       Tasks: TOP => assets:precompile:nondigest

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.