GithubHelp home page GithubHelp logo

middleman-s3_sync's Introduction

Middleman::S3Sync

Join the chat at https://gitter.im/fredjean/middleman-s3_sync Code Climate Build Status

This gem determines which files need to be added, updated and optionally deleted and only transfer these files up. This reduces the impact of an update on a web site hosted on S3.

Why not Middleman Sync?

Middleman Sync does a great job to push Middleman generated websites to S3. The only issue I have with it is that it pushes every files under build to S3 and doesn't seem to properly delete files that are no longer needed.

Version Support

  • Use middleman-s3_sync version 4.x for Middleman 4.x
  • Use middleman-s3_sync version 3.x for Middleman 3.x

Installation

Add this line to your application's Gemfile:

gem 'middleman-s3_sync'

And then execute:

$ bundle

Or install it yourself as:

$ gem install middleman-s3_sync

Usage

You need to add the following code to your config.rb file:

activate :s3_sync do |s3_sync|
  s3_sync.bucket                     = 'my.bucket.com' # The name of the S3 bucket you are targeting. This is globally unique.
  s3_sync.region                     = 'us-west-1'     # The AWS region for your bucket.
  s3_sync.aws_access_key_id          = 'AWS KEY ID'
  s3_sync.aws_secret_access_key      = 'AWS SECRET KEY'
  s3_sync.delete                     = false # We delete stray files by default.
  s3_sync.after_build                = false # We do not chain after the build step by default.
  s3_sync.prefer_gzip                = true
  s3_sync.path_style                 = true
  s3_sync.reduced_redundancy_storage = false
  s3_sync.acl                        = 'public-read'
  s3_sync.encryption                 = false
  s3_sync.prefix                     = ''
  s3_sync.version_bucket             = false
  s3_sync.index_document             = 'index.html'
  s3_sync.error_document             = '404.html'
end

You can then start synchronizing files with S3 through middleman s3_sync.

Configuration Defaults

The following defaults apply to the configuration items:

Setting Default
aws_access_key_id -
aws_secret_access_key -
bucket -
delete true
after_build false
prefer_gzip true
reduced_redundancy_storage false
path_style true
encryption false
acl 'public-read'
version_bucket false

Setting AWS Credentials

There are several ways to provide the AWS credentials for s3_sync:

Through config.rb

You can set the aws_access_key_id and aws_secret_access_key in the block that is passed to the activate method.

I strongly discourage using this method. This will lead you to add and commit these changes to your SCM and potentially expose sensitive information to the world.

Through .s3_sync File

You can create a .s3_sync at the root of your middleman project. The credentials are passed in the YAML format. The keys match the options keys.

The .s3_sync file takes precedence to the configuration passed in the activate method.

A sample .s3_sync file is included at the root of this repo.

Make sure to add .s3_sync to your ignore list if you choose this approach. Not doing so may expose credentials to the world.

Through the Command Line

The aws credentials can also be passed via a command line options --aws_access_key_id (-k) and --aws_secret_access_key (-s). They should override any other settings if specified.

Through Environment

You can also pass the credentials through environment variables. They map to the following values:

Setting Environment Variable
aws_access_key_id ENV['AWS_ACCESS_KEY_ID']
aws_secret_access_key ENV['AWS_SECRET_ACCESS_KEY']
bucket ENV['AWS_BUCKET']

The environment is used when the credentials are not set in the activate method or passed through the .s3_sync configuration file.

Through IAM role

Alternatively, if you are running builds on EC2 instance which has approrpiate IAM role, then you don't need to think about specifying credentials at all – they will be pulled from AWS metadata service.

IAM Policy

Here's a sample IAM policy that will allow a user to update the site contained in a bucket named "mysite.com":

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "s3:*",
      "Resource": "arn:aws:s3:::mysite.com"
    },
    {
      "Effect": "Allow",
      "Action": "s3:*",
      "Resource": "arn:aws:s3:::mysite.com/*"
    }
  ]
}

This will give full access to both the bucket and it's contents.

Command Line Usage

Push All Content to S3

There are situations where you might need to push the files to S3. In such case, you can pass the --force (-f) option:

$ middleman s3_sync --force

Overriding the destination bucket

You can override the destination bucket using the --bucket (-b) switch. The command is:

$ middleman s3_sync --bucket=my.new.bucket

Overriding the destination prefix

You can override the destination prefix using the --prefix (-p) switch. The command is:

$ middleman s3_sync --prefix=my/new/prefix

Specify a Middleman environment

You can specify which environment to run Middleman under using the --environment (-e) option:

$ middleman s3_sync --environment=production

You can set up separate sync environments in config.rb like this:

	configure :staging do
		activate :s3_sync do |s3_sync|
			s3_sync.bucket = '<bucket'
			... 
    	end
    end

See the Usage section above for all the s3_sync. options to include. Currently, the .s3_sync file does not allow separate environments.

Dry Run

You can perform a dry run to see what would be the result of a sync operation using the --dry_run (-d) option:

$ middleman s3_sync --dry_run

Print instrument messages

The --instrument (-i) option will output more information about Middleman and s3_sync.

Run build before synchronizing

The --build (-B) option will ensure that Middleman build is run before the synchronization with the S3 bucket.

AWS Configuration

Pushing to a folder within a bucket

You can push to a folder within an S3 bucket by adding using the prefix option in the config block:

activate :s3_sync do |s3_sync|
  # ...
  s3_sync.prefix = 'prefix'
end

Bucket Versioning

You can enable bucket versioning by setting the version_bucket setting to true within the bucket configuration.

Versioning is enabled at the bucket level, not at the object level.

You can find out more about versioning here.

HTTP Caching

By default, middleman-s3_sync does not set caching headers. In general, the default settings are sufficient. However, there are situations where you might want to set a different HTTP caching policy. This may be very helpful if you are using the asset_hash extension.

Setting a policy based on the mime-type of a file

You can set a caching policy for every files that match a certain mime-type. For example, setting max-age to 0 and kindly asking the browser to revalidate the content for HTML files would take the following form:

caching_policy 'text/html', max_age: 0, must_revalidate: true

As a result, the following Cache-Control header would be set to max-age:0, must-revalidate

Setting a Default Policy

You can set the default policy by passing an options hash to default_caching_policy in your config.rb file after the activate :s3_sync ... end block:

default_caching_policy max_age:(60 * 60 * 24 * 365)

This will apply the policy to any file that do not have a mime-type specific policy.

Caching Policies

The Caching Tutorial is a great introduction to HTTP caching. The caching policy code in this gem is based on it.

The following keys can be set:

Key Value Header Description
max_age seconds max-age Specifies the maximum amount of time that a representation will be considered fresh. This value is relative to the time of the request
s_maxage seconds s-maxage Only applies to shared (proxies) caches
public boolean public Marks authenticated responses as cacheable.
private boolean private Allows caches that are specific to one user to store the response. Shared caches (proxies) may not.
no_cache boolean no-cache Forces caches to submit the request to the origin server for validation before releasing a cached copy, every time.
no_store boolean no-store Instructs caches not to keep a copy of the representation under any conditions.
must_revalidate boolean must-revalidate Tells the caches that they must obey any freshness information you give them about a representation.
proxy_revalidate boolean proxy-revalidate Similar as must-revalidate, but only for proxies.

Setting Expires Header

You can pass the expires key to the caching_policy and default_caching_policy methods if you insist on setting the expires header on a results. You will need to pass it a Time object indicating when the resource is set to expire.

Note that the Cache-Control header will take precedence over the Expires header if both are present.

A Note About Browser Caching

Browser caching is well specified. It hasn't always been the case. Still, even modern browsers have different behaviors if it suits it's developers or their employers. Specs are meant to be ignored and so they are (I'm looking at you Chrome!). Setting the Cache-Control or Expires headers are not a guarrantie that the browsers and the proxies that stand between them and your content will behave the way you want them to. YMMV.

Path Specific Content Type

You can now set the content type of a path through the s3_sync.content_types hash. This hasi will take precendence over the content type discovered by the mime_types gem. The associated pull request has a few good examples on how to use this feature.

ACLs

middleman-s3_sync will set the resources's ACL to public-read by default. You can specificy a different ACL via the acl configuration option. The valid values are:

  • private
  • public-read
  • public-read-write
  • authenticated-read
  • bucket-owner-read
  • bucket-owner-full-control

The full values and their semantics are documented on AWS's documentation site.

Encryption

You can ask Amazon to encrypt your files at rest by setting the encryption option to true. Server side encryption is documented on the AWS documentation site .

GZipped Content Encoding

You can set the prefer_gzip option to look for a gzipped version of a resource. The gzipped version of the resource will be pushed to S3 instead of the original and the Content-Encoding and Content-Type headers will be set correctly. This will cause Amazon to serve the compressed version of the resource. In order for this to work, you need to have the :gzip extension activated in your config.rb.

Custom S3 Index and Error Documents

You can enable a custom index document and error document settings. The index_document option tells which file name gets used as the index document of a directory (typically, index.html), while error_document specifies the document to display for 4xx errors (ie, the 404 page).

A Debt of Gratitude

I used Middleman Sync as a template for building a Middleman extension. The code is well structured and easy to understand and it was easy to extend it to add my synchronization code. My gratitude goes to @karlfreeman and his work on Middleman sync.

Many thanks to Gnip and dojo4 for supporting and sponsoring work on middleman-s3_sync.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

middleman-s3_sync's People

Contributors

adamdill avatar aergonaut avatar ajsharp avatar alex88 avatar andrewkvalheim avatar antonkl avatar aprioni avatar atyndall avatar bobmaerten avatar bostonaholic avatar calyhre avatar chriseidhof avatar fredjean avatar gitter-badger avatar ivarvong avatar johnnyshields avatar joshukraine avatar kcurtin avatar lautis avatar leighmcculloch avatar matiasgarciaisaia avatar mcls avatar mrship avatar nordewal avatar ralovely avatar rmm5t avatar rylanb avatar vprigent avatar willglynn avatar willkoehler 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

middleman-s3_sync's Issues

Command line options don't seem to work

Using version 3.0.31 with middleman 3.3.4

--force, --bucket, and --verbose don't seem to have their intended effect. For example, when using --bucket, the bucket specified in middleman's config.rb is not overridden.

Edit:
Here's s3_sync options in my config.rb

activate :s3_sync do |s3_sync|
  s3_sync.bucket                     = "my-bucket-name"
  s3_sync.region                     = "us-west-1"
  s3_sync.after_build                = false
  s3_sync.add_caching_policy "text/html", :max_age => 0, :must_revalidate => true
  s3_sync.add_caching_policy "text/css", :max_age => (60 * 60 * 24 * 365)
  s3_sync.add_caching_policy "application/javascript", :max_age => (60 * 60 * 24 * 365)
  s3_sync.add_caching_policy "image/jpeg", :max_age => (60 * 60 * 24 * 365)
  s3_sync.add_caching_policy "image/png", :max_age => (60 * 60 * 24 * 365)
end

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

[documentation] Default Behaviour Is Incorrect

In the docs is the following:

s3_sync.after_build                = false # We chain after the build step by default. This may not be your desired behavior...

The comment implies that the default behaviour is for syncing to begin after build, however so far as I can see, there is no sync unless I set this to true, meaning that by default sync will not occur after build.

undefined method `aws_access_key_id'

Hello!

I’m setting this error consistently in 3.0.32:

/opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/middleman-s3_sync-3.0.32/lib/middleman/s3_sync.rb:54:in `connection': undefined method `aws_access_key_id' for nil:NilClass (NoMethodError)
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/middleman-s3_sync-3.0.32/lib/middleman/s3_sync.rb:43:in `bucket'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/middleman-s3_sync-3.0.32/lib/middleman/s3_sync.rb:98:in `block in bucket_files'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/middleman-s3_sync-3.0.32/lib/middleman/s3_sync.rb:97:in `tap'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/middleman-s3_sync-3.0.32/lib/middleman/s3_sync.rb:97:in `bucket_files'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/middleman-s3_sync-3.0.32/lib/middleman/s3_sync.rb:93:in `remote_paths'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/middleman-s3_sync-3.0.32/lib/middleman/s3_sync.rb:75:in `paths'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/middleman-s3_sync-3.0.32/lib/middleman/s3_sync.rb:62:in `resources'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/middleman-s3_sync-3.0.32/lib/middleman/s3_sync.rb:141:in `files_to_create'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/middleman-s3_sync-3.0.32/lib/middleman/s3_sync.rb:129:in `work_to_be_done?'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/middleman-s3_sync-3.0.32/lib/middleman/s3_sync.rb:22:in `sync'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/middleman-s3_sync-3.0.32/lib/middleman-s3_sync/extension.rb:24:in `block (2 levels) in registered'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/uber-0.0.8/lib/uber/options.rb:80:in `instance_exec'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/uber-0.0.8/lib/uber/options.rb:80:in `proc!'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/uber-0.0.8/lib/uber/options.rb:69:in `evaluate_for'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/uber-0.0.8/lib/uber/options.rb:60:in `evaluate'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/hooks-0.4.0/lib/hooks/hook.rb:53:in `execute_callback'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/hooks-0.4.0/lib/hooks/hook.rb:40:in `block in run'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/hooks-0.4.0/lib/hooks/hook.rb:39:in `each'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/hooks-0.4.0/lib/hooks/hook.rb:39:in `inject'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/hooks-0.4.0/lib/hooks/hook.rb:39:in `run'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/hooks-0.4.0/lib/hooks.rb:55:in `run_hook_for'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/hooks-0.4.0/lib/hooks/instance_hooks.rb:6:in `run_hook'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/middleman-core-3.3.5/lib/middleman-core/cli/build.rb:72:in `build'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/middleman-core-3.3.5/lib/middleman-core/cli.rb:72:in `method_missing'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/command.rb:29:in `run'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/command.rb:126:in `run'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/middleman-core-3.3.5/lib/middleman-core/cli.rb:20:in `start'
    from /opt/boxen/rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/middleman-core-3.3.5/bin/middleman:18:in `<top (required)>'
    from /opt/boxen/rbenv/versions/2.1.0/bin/middleman:23:in `load'
    from /opt/boxen/rbenv/versions/2.1.0/bin/middleman:23:in `<main>'

If I pin the gem to 3.0.26 everything works fine again.

Prefix in README

I think the README might read wrong where it states that the prefix when publishing to a folder in the bucket should contain a a forward slash at the beginning. I've been having trouble uploading and when I removed the forward slash at the beginning of the prefix it work.

Change 'after_build' option to run after gzipping

Currently with after_build = true, s3_sync runs before the Middleman gzip's the content, so the ungzipped content is uploaded.

Here is me running middleman build && middleman s3_sync with both after_build set to true and false. You'll see with it on, s3_sync uploads before the gzip occurs, and then when s3_sync run after (as the separate command) it considers all files identical (since it's based on filename) and we end up with non gzipped files on the server.

Running with after_build = true

➜ homepage git:(master) ✗ middleman build && middleman s3_sync
...
      create  build/index.html
...
      s3_sync  Gathering the paths to evaluate.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         s3_sync  ===========================================================                                                                                               |
Ready to apply updates to homepagetest.xxx
     s3_sync  Updating index.html
  ...
        gzip  build/index.html.gz (6.4 KB smaller)
        gzip  Total gzip savings: 419.1 KB
middleman build  13.94s user 1.66s system 78% cpu 19.977 total
     s3_sync  Gathering the paths to evaluate.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  s3_sync  ==========================================================                                                                                                |
All S3 files are up to date.

running with after_build = false

➜  homepage git:(master) ✗ middleman build && middleman s3_sync

   ...
      update  build/index.html
...
        gzip  build/index.html.gz (6.4 KB smaller)
...
        gzip  Total gzip savings: 419.8 KB
middleman build  12.55s user 1.53s system 99% cpu 14.125 total

     s3_sync  Gathering the paths to evaluate.
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        s3_sync  ==============================================================                                                                                            |
Ready to apply updates to homepagetest.xxx.
     s3_sync  Updating index.html (gzipped)

gzip not working?

Here's the code I have in my config.rb:

activate :s3_sync do |s3_sync|
  s3_sync.bucket                     = AWS_BUCKET
  s3_sync.aws_access_key_id          = AWS_ACCESS_KEY
  s3_sync.aws_secret_access_key      = AWS_SECRET
  s3_sync.delete                     = true
  s3_sync.prefer_gzip                = true
end

However, somehow, the files are not gzipped. Not sure if I'm doing it wrong, or if I found a bug.

Gzipped files don't seem to be uploaded

I just started using middleman-s3_sync instead of middleman-sync for the same reason you started this project, to "sync" instead of "upload everything every time". 😄

It seems like my gzipped files are not uploaded though.

$ bundle exec middleman build
      create  build/images/projects/productwidgets-2bccdd77.png
      create  build/images/projects/karmabox-3f10d448.png
      create  build/images/projects/periphereswissen-e84e2afc.png
      create  build/images/glyphicons-halflings-84f61363.png
      create  build/images/imprint_de-df22fd9d.png
      create  build/images/imprint_en-96cd7768.png
      create  build/images/glyphicons-halflings-white-a25c4705.png
      create  build/images/projects/carfinder-a85e7694.png
      create  build/images/logo-0c359c3e.jpg
      create  build/images/face-3f2b032a.jpg
      create  build/images/blank-54a69da1.gif
      create  build/fonts/zocial-regular-webfont-55d26298.svg
      create  build/fonts/zocial-regular-webfont-a7dc3960.woff
      create  build/fonts/zocial-regular-webfont-b0e173c9.ttf
      create  build/fonts/zocial-regular-webfont-bc2accd3.eot
      create  build/javascripts/site_head-5ce02500.js
      create  build/javascripts/libraries/site_head/modernizr-47817d41.js
      create  build/javascripts/site-daf3f650.js
      create  build/javascripts/libraries/site/jquery-89a6b84f.js
      create  build/javascripts/libraries/site/jquery.lazyload-9f33a126.js
      create  build/stylesheets/site-80d930b3.css
      create  build/projects/index.html
      create  build/blog/page/2/index.html
      create  build/blog/index.html
      create  build/contact/index.html
      create  build/blog/feed.xml
      create  build/blog/2014/03/06/load-remote-rails-links-and-forms-in-bootstrap-modals/index.html
      create  build/blog/2014/03/06/get-query-parameter-from-current-url-with-javascript/index.html
      create  build/blog/2014/01/10/how-to-drop-your-postgres-database-with-rails-4/index.html
      create  build/blog/2013/12/17/how-to-access-your-google-drive-files-with-ruby/index.html
      create  build/blog/2013/11/19/how-to-set-up-automatic-retweeting-using-a-google-apps-script-yahoo-pipes-and-twitterfeed/index.html
      create  build/blog/2013/10/29/the-joy-of-ruby-and-small-incremental-improvements/index.html
      create  build/blog/2013/10/06/making-php-development-bearable-for-ruby-developers-using-coffeescript-sass-and-haml/index.html
      create  build/blog/2013/08/13/bootstrap-navbar-helpers-for-rails-and-middleman/index.html
      create  build/imprint/index.html
      create  build/index.html
      create  build/blog/2013/05/22/new-gem-gemconfig-a-nifty-way-to-make-your-gem-configurable/index.html
      create  build/blog/2013/03/06/new-project-carfinder-dot-io-find-your-closest-carsharing-car/index.html
      create  build/sitemap.xml
      create  build/robots.txt
      create  build/blog/2013/01/11/new-gem-skimlinks/index.html
      create  build/blog/2012/12/19/new-gem-tries/index.html
      create  build/blog/2012/11/14/create-a-cache-key-from-method-argument-values/index.html
      create  build/blog/2012/10/07/how-to-make-everything-background-processable-through-sidekiq/index.html
      create  build/blog/2012/09/30/the-road-ahead-for-showspace/index.html
      create  build/blog/2012/08/22/how-to-install-and-secure-mysql-5-5-from-source-with-sprinkle/index.html
      create  build/blog/2012/06/17/how-to-upload-your-gmvault-backups-to-s3/index.html
      create  build/blog/2012/03/27/how-to-compile-custom-sass-stylesheets-dynamically-during-runtime/index.html
        gzip  build/blog/2012/03/27/how-to-compile-custom-sass-stylesheets-dynamically-during-runtime/index.html.gz (6.2 KB smaller)
        gzip  build/blog/2012/06/17/how-to-upload-your-gmvault-backups-to-s3/index.html.gz (4.4 KB smaller)
        gzip  build/blog/2012/08/22/how-to-install-and-secure-mysql-5-5-from-source-with-sprinkle/index.html.gz (4.6 KB smaller)
        gzip  build/blog/2012/09/30/the-road-ahead-for-showspace/index.html.gz (7.2 KB smaller)
        gzip  build/blog/2012/10/07/how-to-make-everything-background-processable-through-sidekiq/index.html.gz (5.3 KB smaller)
        gzip  build/blog/2012/11/14/create-a-cache-key-from-method-argument-values/index.html.gz (4.9 KB smaller)
        gzip  build/blog/2012/12/19/new-gem-tries/index.html.gz (4.1 KB smaller)
        gzip  build/blog/2013/01/11/new-gem-skimlinks/index.html.gz (4.5 KB smaller)
        gzip  build/blog/2013/03/06/new-project-carfinder-dot-io-find-your-closest-carsharing-car/index.html.gz (4.4 KB smaller)
        gzip  build/blog/2013/05/22/new-gem-gemconfig-a-nifty-way-to-make-your-gem-configurable/index.html.gz (3.8 KB smaller)
        gzip  build/blog/2013/08/13/bootstrap-navbar-helpers-for-rails-and-middleman/index.html.gz (4.2 KB smaller)
        gzip  build/blog/2013/10/06/making-php-development-bearable-for-ruby-developers-using-coffeescript-sass-and-haml/index.html.gz (9.5 KB smaller)
        gzip  build/blog/2013/10/29/the-joy-of-ruby-and-small-incremental-improvements/index.html.gz (7.2 KB smaller)
        gzip  build/blog/2013/11/19/how-to-set-up-automatic-retweeting-using-a-google-apps-script-yahoo-pipes-and-twitterfeed/index.html.gz (6.9 KB smaller)
        gzip  build/blog/2013/12/17/how-to-access-your-google-drive-files-with-ruby/index.html.gz (10.3 KB smaller)
        gzip  build/blog/2014/01/10/how-to-drop-your-postgres-database-with-rails-4/index.html.gz (4.3 KB smaller)
        gzip  build/blog/2014/03/06/get-query-parameter-from-current-url-with-javascript/index.html.gz (4.3 KB smaller)
        gzip  build/blog/2014/03/06/load-remote-rails-links-and-forms-in-bootstrap-modals/index.html.gz (4.2 KB smaller)
        gzip  build/blog/index.html.gz (11 KB smaller)
        gzip  build/blog/page/2/index.html.gz (8.6 KB smaller)
        gzip  build/contact/index.html.gz (2.4 KB smaller)
        gzip  build/imprint/index.html.gz (12.5 KB smaller)
        gzip  build/index.html.gz (1.7 KB smaller)
        gzip  build/javascripts/libraries/site/jquery-89a6b84f.js.gz (59.7 KB smaller)
        gzip  build/javascripts/libraries/site/jquery.lazyload-9f33a126.js.gz (2.2 KB smaller)
        gzip  build/javascripts/libraries/site_head/modernizr-47817d41.js.gz (2.8 KB smaller)
        gzip  build/javascripts/site-daf3f650.js.gz (64.2 KB smaller)
        gzip  build/javascripts/site_head-5ce02500.js.gz (2.8 KB smaller)
        gzip  build/projects/index.html.gz (6.7 KB smaller)
        gzip  build/stylesheets/site-80d930b3.css.gz (126.4 KB smaller)
        gzip  Total gzip savings: 401.2 KB
     s3_sync  Gathering the paths to evaluate.

     s3_sync
All S3 files are up to date.

None of the .gz files are present in my S3 folder though.

No need to print out alternate encoding files

Files where the content encoding and content md5 are matching should be treated like the other identical files. In this case, the gzipped file might have been recreated or modified and there isn't the need to be vocal about it.

`s3_sync_options` method not found

When trying to run middleman s3_sync from the command line (or bundle exec middleman s3_sync) I received the following error:

/Users/jon/.rvm/gems/[email protected]/gems/middleman-s3_sync-3.0.12/lib/middleman-s3_sync/commands.rb:27:in `s3_sync': undefined method `s3_sync_options' for #<Middleman::Application::MiddlemanApplication1:0x007f90097634a0> (NoMethodError)

Ruby: 2.0.0
Middleman: 3.0.14
Middleman-s3_sync: 3.0.12

Provide default settings

Hey,
maybe we should provide some defaults like

aws_access_key_id = ENV['AWS_KEY_ID']
aws_secret_access_key = ENV['AWS_SECRET_KEY']
delete = true
after_build = false
prefer_gzip = true

Problem with Upload to S3

Hi,
first: thanks for this gem its the thing I was always looking for :)

Sadly I have a problem when I try to upload my files. I played around with a set of different options, but so far no success.

I get this:

middleman s3_sync --force
== LiveReload is waiting for a browser to connect
     s3_sync  Gathering the paths to evaluate.
/Users/chris/.rvm/gems/ruby-2.1.0/gems/middleman-s3_sync-3.0.25/lib/middleman/s3_sync.rb:83:in `block in bucket_files': undefined method `files' for nil:NilClass (NoMethodError)
    from /Users/chris/.rvm/gems/ruby-2.1.0/gems/middleman-s3_sync-3.0.25/lib/middleman/s3_sync.rb:82:in `tap'
    from /Users/chris/.rvm/gems/ruby-2.1.0/gems/middleman-s3_sync-3.0.25/lib/middleman/s3_sync.rb:82:in `bucket_files'
    from /Users/chris/.rvm/gems/ruby-2.1.0/gems/middleman-s3_sync-3.0.25/lib/middleman/s3_sync.rb:78:in `remote_paths'
    from /Users/chris/.rvm/gems/ruby-2.1.0/gems/middleman-s3_sync-3.0.25/lib/middleman/s3_sync.rb:60:in `paths'
    from /Users/chris/.rvm/gems/ruby-2.1.0/gems/middleman-s3_sync-3.0.25/lib/middleman/s3_sync.rb:47:in `resources'
    from /Users/chris/.rvm/gems/ruby-2.1.0/gems/middleman-s3_sync-3.0.25/lib/middleman/s3_sync.rb:126:in `files_to_create'
    from /Users/chris/.rvm/gems/ruby-2.1.0/gems/middleman-s3_sync-3.0.25/lib/middleman/s3_sync.rb:114:in `work_to_be_done?'
    from /Users/chris/.rvm/gems/ruby-2.1.0/gems/middleman-s3_sync-3.0.25/lib/middleman/s3_sync.rb:18:in `sync'
    from /Users/chris/.rvm/gems/ruby-2.1.0/gems/middleman-s3_sync-3.0.25/lib/middleman-s3_sync/commands.rb:37:in `s3_sync'
    from /Users/chris/.rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/command.rb:27:in `run'
    from /Users/chris/.rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/invocation.rb:120:in `invoke_command'
    from /Users/chris/.rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor.rb:363:in `dispatch'
    from /Users/chris/.rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/base.rb:439:in `start'
    from /Users/chris/.rvm/gems/ruby-2.1.0/gems/middleman-core-3.2.2/lib/middleman-core/cli.rb:77:in `method_missing'
    from /Users/chris/.rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/command.rb:29:in `run'
    from /Users/chris/.rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/command.rb:128:in `run'
    from /Users/chris/.rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/invocation.rb:120:in `invoke_command'
    from /Users/chris/.rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor.rb:363:in `dispatch'
    from /Users/chris/.rvm/gems/ruby-2.1.0/gems/thor-0.18.1/lib/thor/base.rb:439:in `start'
    from /Users/chris/.rvm/gems/ruby-2.1.0/gems/middleman-core-3.2.2/lib/middleman-core/cli.rb:22:in `start'
    from /Users/chris/.rvm/gems/ruby-2.1.0/gems/middleman-core-3.2.2/bin/middleman:18:in `<top (required)>'
    from /Users/chris/.rvm/gems/ruby-2.1.0/bin/middleman:23:in `load'
    from /Users/chris/.rvm/gems/ruby-2.1.0/bin/middleman:23:in `<main>'
    from /Users/chris/.rvm/gems/ruby-2.1.0/bin/ruby_executable_hooks:15:in `eval'
    from /Users/chris/.rvm/gems/ruby-2.1.0/bin/ruby_executable_hooks:15:in `<main>'

My config is

activate :s3_sync do |s3_sync|
  s3_sync.bucket                     = 'here is the full endpoint' # The name of the S3 bucket you are targetting. This is globally unique.
  s3_sync.region                     = 'us-west-1'     # The AWS region for your bucket.
  s3_sync.aws_access_key_id          = 'secret'
  s3_sync.aws_secret_access_key      = 'secret'
  s3_sync.delete                     = false # We delete stray files by default.
  s3_sync.after_build                = false # We do not chain after the build step by default. 
  s3_sync.prefer_gzip                = true
  s3_sync.path_style                 = true
  s3_sync.reduced_redundancy_storage = false
  s3_sync.acl                        = 'public-read'
  s3_sync.encryption                 = false
end

Thanks for your help!

.s3_sync accepting other configuration options

I see that the .s3_sync file can only provide AWS credentials. Why not allow it to override any of the other options? In my case it would be useful to be able to set prefix and bucket.
If you are alright with this functionality I'll make a pull request with the changes.

"A Note About Browser Caching"

The README says:

A Note About Browser Caching

Browser caching is well specified. It hasn't always been the case. Still, even modern browsers have different behaviors if it suits it's developers or their employers. Specs are meant to be ignored and so they are (I'm looking at you Chrome!). Setting the Cache-Control or Expires headers are not a guarrantie that the browsers and the proxies that stand between them and your content will behave the way you want them to. YMMV.

Could you elaborate? Under what circumstances does Chrome ignore Cache-Control or Expires headers?

Interested in adding support for gzip compression?

@fredjean this gem looks great. The only feature I see missing is the gzip_compression option in middleman-sync / asset_sync. It's pretty slick how asset_sync implements this. If you're interested I'll take a crack at porting that feature to middleman-s3_sync and submit a pull request.

Allow specific Content-Type and Charset for certain files

Is there a way to support setting the Content-Type too? Or is this already possible? I would like to set Content-Type to 'text/html;charset=utf-8' for some files in the bucket.

@cutemachine Could you elaborate on this? Are you looking to set the content based on path? glob? extension? We are already setting the content type based on the extension of the file (which is also done by fog as well). I do not think that we are setting the charset at this point though. Ideas on what you would like this to look like would be good.

Thanks!

Missing AWS access info when synching after build

I'm getting the following error when trying to use S3 Sync to upload when hooked after the build phase.

I am using a .s3_sync file in the root of my Middleman project so I can add it to .gitignore and keep my credentials out of source control.

It looks like S3 Sync isn't able to find the .s3_sync file to read the AWS access info.

Strangely, it works just fine if I sync manually with bundle exec middleman s3_sync.

My config.rb:

activate :s3_sync do |s3|
  s3.bucket = "static.aergonaut.com"
  s3.region = "us-east-1"
  s3.delete = true
  s3.after_build = true
  s3.prefer_gzip = true
end

Stack trace:

/Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/fog-1.15.0/lib/fog/core/service.rb:208:in `validate_options': Missing required arguments: aws_access_key_id, aws_secret_access_key (ArgumentError)
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/fog-1.15.0/lib/fog/core/service.rb:58:in `new'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/fog-1.15.0/lib/fog/storage.rb:20:in `new'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/middleman-s3_sync-3.0.16/lib/middleman/s3_sync.rb:39:in `connection'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/middleman-s3_sync-3.0.16/lib/middleman/s3_sync.rb:34:in `bucket'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/middleman-s3_sync-3.0.16/lib/middleman/s3_sync.rb:79:in `remote_paths'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/middleman-s3_sync-3.0.16/lib/middleman/s3_sync.rb:61:in `paths'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/middleman-s3_sync-3.0.16/lib/middleman/s3_sync.rb:48:in `resources'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/middleman-s3_sync-3.0.16/lib/middleman/s3_sync.rb:119:in `files_to_create'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/middleman-s3_sync-3.0.16/lib/middleman/s3_sync.rb:107:in `work_to_be_done?'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/middleman-s3_sync-3.0.16/lib/middleman/s3_sync.rb:20:in `sync'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/middleman-s3_sync-3.0.16/lib/middleman-s3_sync/extension.rb:20:in `block in registered'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/middleman-core-3.1.4/lib/vendored-middleman-deps/hooks-0.2.0/lib/hooks.rb:53:in `instance_exec'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/middleman-core-3.1.4/lib/vendored-middleman-deps/hooks-0.2.0/lib/hooks.rb:53:in `block in run_hook_for'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/middleman-core-3.1.4/lib/vendored-middleman-deps/hooks-0.2.0/lib/hooks.rb:49:in `each'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/middleman-core-3.1.4/lib/vendored-middleman-deps/hooks-0.2.0/lib/hooks.rb:49:in `run_hook_for'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/middleman-core-3.1.4/lib/vendored-middleman-deps/hooks-0.2.0/lib/hooks.rb:107:in `run_hook'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/middleman-core-3.1.4/lib/middleman-core/cli/build.rb:66:in `build'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/thor-0.18.1/lib/thor/command.rb:27:in `run'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/thor-0.18.1/lib/thor/invocation.rb:120:in `invoke_command'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/thor-0.18.1/lib/thor.rb:363:in `dispatch'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/thor-0.18.1/lib/thor/base.rb:439:in `start'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/middleman-core-3.1.4/lib/middleman-core/cli.rb:77:in `method_missing'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/thor-0.18.1/lib/thor/command.rb:29:in `run'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/thor-0.18.1/lib/thor/command.rb:128:in `run'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/thor-0.18.1/lib/thor/invocation.rb:120:in `invoke_command'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/thor-0.18.1/lib/thor.rb:363:in `dispatch'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/thor-0.18.1/lib/thor/base.rb:439:in `start'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/middleman-core-3.1.4/lib/middleman-core/cli.rb:22:in `start'
        from /Users/chris/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/middleman-core-3.1.4/bin/middleman:18:in `<top (required)>'
        from /Users/chris/.rbenv/versions/2.0.0-p195/bin/middleman:23:in `load'
        from /Users/chris/.rbenv/versions/2.0.0-p195/bin/middleman:23:in `<main>'

Error on after_build

I get the following error when I activate after_build:

s3_sync  Gathering the paths to evaluate.
/Users/allaire/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/middleman-s3_sync-3.0.34/lib/middleman/s3_sync.rb:58:in `connection': undefined method `aws_access_key_id' for nil:NilClass (NoMethodError)
    from /Users/allaire/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/middleman-s3_sync-3.0.34/lib/middleman/s3_sync.rb:44:in `bucket'
    from /Users/allaire/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/middleman-s3_sync-3.0.34/lib/middleman/s3_sync.rb:102:in `block in bucket_files'

When I run middleman s3_sync independently (after middleman build) it works well.

Verbose option raises exception when creating new files

When adding s3_sync.verbose option to the config.rb block, I get this error when a file has to be created in S3:

middleman-s3_sync-3.0.18/lib/middleman/s3_sync/resource.rb:174:in `remote_md5': undefined method `metadata' for nil:NilClass (NoMethodError)

I guess the problem is in https://github.com/fredjean/middleman-s3_sync/blob/master/lib/middleman/s3_sync/resource.rb#L96

If it's creating an object it is because there is no remote, so it can output the md5 of that.

undefined method 'green' - recent ansi change

Hello! I'm getting this error:
in say_status': undefined methodgreen' for " s3_sync":String (NoMethodError)

after running this command:
bundle exec middleman s3_sync --bucket=my-aws-bucket-name

I believe this recent ANSI change is breaking the upload.
6f78401

Thanks in advance! Hope you have a happy new year!

Type#platform? & Type#system? are deprecated

MIME::Type#platform? is deprecated and will be removed.
MIME::Type#system? is deprecated and will be removed.

with ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin11.4.2]

Fog warning: 'Might fail with https'

I just upgraded to the latest middleman-s3_sync, and now my sync is filled with warnings:
[WARNING] fog: the specified s3 bucket name(<domain name>) might fail with https.

Is that expected? Is there any way around it? Still seems to work, just irritating. ;)

Problem syncing with S3

Hello, I have problem syncing with S3.

Here is an error:
/lib/ruby/1.9.1/openssl/ssl-internal.rb:121:in `post_connection_check': hostname does not match the server certificate (OpenSSL::SSL::SSLError) (Excon::Errors::SocketError)

Am I doing something wrong?

Here is my configuration:

activate :s3_sync do |s3_sync|
  s3_sync.bucket                     = 'totocaster.com' 
  s3_sync.region                     = 'us-west-1' 
  s3_sync.delete                     = true
  s3_sync.after_build                = true
  s3_sync.prefer_gzip                = true
  s3_sync.path_style                 = false
  s3_sync.reduced_redundancy_storage = false
  s3_sync.acl                        = 'public-read'
  s3_sync.encryption                 = false
end

Extension seems not active

Hi there, I've this Gemfile:

source 'https://rubygems.org'
source 'https://rails-assets.org'

gem 'middleman'
gem 'middleman-livereload'
gem 'middleman-s3_sync'

gem 'rails-assets-bootstrap'

this config.rb

set :css_dir, 'stylesheets'
set :js_dir, 'javascripts'
set :images_dir, 'images'

configure :development do
  activate :livereload
  set :debug_assets, true
end

# Build-specific configuration
configure :build do
  activate :minify_css
  activate :minify_javascript
  activate :asset_hash
end

activate :s3_sync do |s3_sync|
  s3_sync.bucket                     = ENV['S3_BUCKET']
  s3_sync.region                     = ENV['S3_BUCKET_REGION']
  s3_sync.aws_access_key_id          = ENV['AWS_ACCESS_KEY_ID']
  s3_sync.aws_secret_access_key      = ENV['AWS_SECRET_ACCESS_KEY']
  s3_sync.reduced_redundancy_storage = true
end

the extension seems loaded since:

$ bundle exec middleman --help
Tasks:
middleman build [options]           # Builds the static site for deployment
middleman console [options]         # Start an interactive console in the context of your Middleman application
middleman extension NAME [options]  # Create Middleman extension scaffold NAME
middleman init NAME [options]       # Create new project NAME
middleman s3_sync                   # Pushes the minimum set of files needed to S3
middleman server [options]          # Start the preview server
middleman upgrade                   # Upgrade installed bundle
middleman version                   # Show version

however, trying to sync I get:

$ bundle exec middleman s3_sync
== LiveReload accepting connections from http://192.168.0.150:35729
You need to activate the s3_sync extension.

I'm using ruby 2.2.0 and this is my Gemfile.lock:

GEM
  remote: https://rubygems.org/
  remote: https://rails-assets.org/
  specs:
    CFPropertyList (2.3.0)
    activesupport (4.1.9)
      i18n (~> 0.6, >= 0.6.9)
      json (~> 1.7, >= 1.7.7)
      minitest (~> 5.1)
      thread_safe (~> 0.1)
      tzinfo (~> 1.1)
    ansi (1.4.3)
    builder (3.2.2)
    celluloid (0.16.0)
      timers (~> 4.0.0)
    chunky_png (1.3.3)
    coffee-script (2.3.0)
      coffee-script-source
      execjs
    coffee-script-source (1.8.0)
    compass (1.0.3)
      chunky_png (~> 1.2)
      compass-core (~> 1.0.2)
      compass-import-once (~> 1.0.5)
      rb-fsevent (>= 0.9.3)
      rb-inotify (>= 0.9)
      sass (>= 3.3.13, < 3.5)
    compass-core (1.0.3)
      multi_json (~> 1.0)
      sass (>= 3.3.0, < 3.5)
    compass-import-once (1.0.5)
      sass (>= 3.2, < 3.5)
    em-websocket (0.5.1)
      eventmachine (>= 0.12.9)
      http_parser.rb (~> 0.6.0)
    erubis (2.7.0)
    eventmachine (1.0.4)
    excon (0.43.0)
    execjs (2.2.2)
    ffi (1.9.6)
    fission (0.5.0)
      CFPropertyList (~> 2.2)
    fog (1.27.0)
      fog-atmos
      fog-aws (~> 0.0)
      fog-brightbox (~> 0.4)
      fog-core (~> 1.27, >= 1.27.3)
      fog-ecloud
      fog-json
      fog-profitbricks
      fog-radosgw (>= 0.0.2)
      fog-sakuracloud (>= 0.0.4)
      fog-serverlove
      fog-softlayer
      fog-storm_on_demand
      fog-terremark
      fog-vmfusion
      fog-voxel
      fog-xml (~> 0.1.1)
      ipaddress (~> 0.5)
      nokogiri (~> 1.5, >= 1.5.11)
    fog-atmos (0.1.0)
      fog-core
      fog-xml
    fog-aws (0.0.6)
      fog-core (~> 1.27)
      fog-json (~> 1.0)
      fog-xml (~> 0.1)
      ipaddress (~> 0.8)
    fog-brightbox (0.7.1)
      fog-core (~> 1.22)
      fog-json
      inflecto (~> 0.0.2)
    fog-core (1.27.3)
      builder
      excon (~> 0.38)
      formatador (~> 0.2)
      mime-types
      net-scp (~> 1.1)
      net-ssh (>= 2.1.3)
    fog-ecloud (0.0.2)
      fog-core
      fog-xml
    fog-json (1.0.0)
      multi_json (~> 1.0)
    fog-profitbricks (0.0.1)
      fog-core
      fog-xml
      nokogiri
    fog-radosgw (0.0.3)
      fog-core (>= 1.21.0)
      fog-json
      fog-xml (>= 0.0.1)
    fog-sakuracloud (1.0.0)
      fog-core
      fog-json
    fog-serverlove (0.1.1)
      fog-core
      fog-json
    fog-softlayer (0.3.30)
      fog-core
      fog-json
    fog-storm_on_demand (0.1.0)
      fog-core
      fog-json
    fog-terremark (0.0.3)
      fog-core
      fog-xml
    fog-vmfusion (0.0.1)
      fission
      fog-core
    fog-voxel (0.0.2)
      fog-core
      fog-xml
    fog-xml (0.1.1)
      fog-core
      nokogiri (~> 1.5, >= 1.5.11)
    formatador (0.2.5)
    haml (4.0.6)
      tilt
    hike (1.2.3)
    hitimes (1.2.2)
    hooks (0.4.0)
      uber (~> 0.0.4)
    http_parser.rb (0.6.0)
    i18n (0.6.11)
    inflecto (0.0.2)
    ipaddress (0.8.0)
    json (1.8.2)
    kramdown (1.5.0)
    listen (2.8.5)
      celluloid (>= 0.15.2)
      rb-fsevent (>= 0.9.3)
      rb-inotify (>= 0.9)
    map (6.5.5)
    middleman (3.3.7)
      coffee-script (~> 2.2)
      compass (>= 1.0.0, < 2.0.0)
      compass-import-once (= 1.0.5)
      execjs (~> 2.0)
      haml (>= 4.0.5)
      kramdown (~> 1.2)
      middleman-core (= 3.3.7)
      middleman-sprockets (>= 3.1.2)
      sass (>= 3.4.0, < 4.0)
      uglifier (~> 2.5)
    middleman-core (3.3.7)
      activesupport (~> 4.1.0)
      bundler (~> 1.1)
      erubis
      hooks (~> 0.3)
      i18n (~> 0.6.9)
      listen (>= 2.7.9, < 3.0)
      padrino-helpers (~> 0.12.3)
      rack (>= 1.4.5, < 2.0)
      rack-test (~> 0.6.2)
      thor (>= 0.15.2, < 2.0)
      tilt (~> 1.4.1, < 2.0)
    middleman-livereload (3.4.2)
      em-websocket (~> 0.5.1)
      middleman-core (>= 3.3)
      rack-livereload (~> 0.3.15)
    middleman-s3_sync (3.0.40)
      ansi (~> 1.4.3)
      fog (>= 1.25.0)
      map
      middleman-core (>= 3.0.0)
      pmap
      ruby-progressbar
      unf
    middleman-sprockets (3.4.1)
      middleman-core (>= 3.3)
      sprockets (~> 2.12.1)
      sprockets-helpers (~> 1.1.0)
      sprockets-sass (~> 1.3.0)
    mime-types (2.4.3)
    mini_portile (0.6.2)
    minitest (5.5.1)
    multi_json (1.10.1)
    net-scp (1.2.1)
      net-ssh (>= 2.6.5)
    net-ssh (2.9.2)
    nokogiri (1.6.5)
      mini_portile (~> 0.6.0)
    padrino-helpers (0.12.4)
      i18n (~> 0.6, >= 0.6.7)
      padrino-support (= 0.12.4)
      tilt (~> 1.4.1)
    padrino-support (0.12.4)
      activesupport (>= 3.1)
    pmap (1.0.2)
    rack (1.6.0)
    rack-livereload (0.3.15)
      rack
    rack-test (0.6.3)
      rack (>= 1.0)
    rails-assets-bootstrap (3.3.2)
      rails-assets-jquery (>= 1.9.1)
    rails-assets-jquery (2.1.3)
    rb-fsevent (0.9.4)
    rb-inotify (0.9.5)
      ffi (>= 0.5.0)
    ruby-progressbar (1.7.1)
    sass (3.4.10)
    sprockets (2.12.3)
      hike (~> 1.2)
      multi_json (~> 1.0)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    sprockets-helpers (1.1.0)
      sprockets (~> 2.0)
    sprockets-sass (1.3.1)
      sprockets (~> 2.0)
      tilt (~> 1.1)
    thor (0.19.1)
    thread_safe (0.3.4)
    tilt (1.4.1)
    timers (4.0.1)
      hitimes
    tzinfo (1.2.2)
      thread_safe (~> 0.1)
    uber (0.0.13)
    uglifier (2.7.0)
      execjs (>= 0.3.0)
      json (>= 1.8.0)
    unf (0.1.4)
      unf_ext
    unf_ext (0.0.6)

PLATFORMS
  ruby

DEPENDENCIES
  middleman
  middleman-livereload
  middleman-s3_sync
  rails-assets-bootstrap

Syntaxerror. Any idea on solution?

Do you have any idea on this error? Thanks!

Stack trace on build


/home/action/.rvm/gems/ruby-2.0.0-p247/gems/middleman-core-3.0.13/lib/middleman-core/core_extensions/extensions.rb:137:in `instance_eval': /home/action/workspace/landl/config.rb:87: syntax error, unexpected ':', expecting end-of-input (Syn
taxError)                                                                                                                                                                                                                                      
:activate :s3_sync do |s3_sync|                                                                                                                                                                                                                
           ^                                                                                                                                                                                                                                   
        from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/middleman-core-3.0.13/lib/middleman-core/core_extensions/extensions.rb:137:in `initialize'                                                                                            
        from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/middleman-core-3.0.13/lib/middleman-core/core_extensions/ruby_encoding.rb:22:in `initialize'                                                                                          
        from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/middleman-core-3.0.13/lib/middleman-core/core_extensions/data.rb:35:in `initialize'                                                                                                   
        from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/middleman-core-3.0.13/lib/middleman-core/application.rb:188:in `initialize'                                                                                                           
        from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/middleman-core-3.0.13/lib/middleman-core/core_extensions/request.rb:56:in `new'                                                                                                       
        from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/middleman-core-3.0.13/lib/middleman-core/core_extensions/request.rb:56:in `inst'                                                                                                      
        from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/middleman-core-3.0.13/lib/middleman-core/cli/build.rb:88:in `shared_instance'                                                                                                         
        from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/middleman-core-3.0.13/lib/middleman-core/cli/build.rb:57:in `build'                                                                                                                   
        from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/thor-0.15.4/lib/thor/task.rb:27:in `run'                                                                                                                                              
        from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/thor-0.15.4/lib/thor/invocation.rb:120:in `invoke_task'                                                                                                                               
        from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/thor-0.15.4/lib/thor.rb:275:in `dispatch'                                                                                                                                             
        from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/thor-0.15.4/lib/thor/base.rb:425:in `start'                                                                                                                                           
        from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/middleman-core-3.0.13/lib/middleman-core/cli.rb:77:in `method_missing'                                                                                                                
        from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/thor-0.15.4/lib/thor/task.rb:29:in `run'                                                                                                                                              
        from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/thor-0.15.4/lib/thor/task.rb:126:in `run'                                                                                                                                             
        from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/thor-0.15.4/lib/thor/invocation.rb:120:in `invoke_task'                                                                                                                               
        from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/thor-0.15.4/lib/thor.rb:275:in `dispatch'                                                                                                                                             
        from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/thor-0.15.4/lib/thor/base.rb:425:in `start'                                                                                                                                           
        from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/middleman-core-3.0.13/lib/middleman-core/cli.rb:22:in `start'                                                                                                                         
        from /home/action/.rvm/gems/ruby-2.0.0-p247/gems/middleman-core-3.0.13/bin/middleman:18:in `<top (required)>'                                                                                                                          
        from /home/action/.rvm/gems/ruby-2.0.0-p247/bin/middleman:23:in `load'                                                                                                                                                                 
        from /home/action/.rvm/gems/ruby-2.0.0-p247/bin/middleman:23:in `<main>'                                                                                                                                                               
        from /home/action/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `eval'                                                                                                                                                       
        from /home/action/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `<main>'                                                                                                                                                     

Gemfile


# If you have OpenSSL installed, we recommend updating
# the following line to use "https"
source 'http://rubygems.org'

gem "middleman", "~>3.0.13"

gem "susy"

gem "middleman-s3_sync"

config.rb


activate :s3_sync do |s3_sync|
  s3_sync.bucket                     = 'landl.se' # The name of the S3 bucket you are targetting. This is globally unique.
  s3_sync.region                     = 'eu-west-1'     # The AWS region for your bucket.
  s3_sync.aws_access_key_id          = 'hidden'
  s3_sync.aws_secret_access_key      = 'hidden'
  s3_sync.delete                     = false # We delete stray files by default.
  s3_sync.after_build                = false # We chain after the build step by default. This may not be your desired behavior...
  s3_sync.prefer_gzip                = true
  s3_sync.path_style                 = true
  s3_sync.reduced_redundancy_storage = true
  s3_sync.acl                        = 'public-read'
  s3_sync.encryption                 = false
end

Options is too generic a name for a helper method

Firstly, thanks for this excellent gem. I read the codebase extensively when building my own middleman extension gem - middleman-ember.

However, when I recently added configurable options for my gem, I noticed that the #options method you include in the InstanceMethods was conflicting with my own options method, as all InstanceMethods appear to be included into the global Middleman config instance. I renamed my options method to ember_options to avoid the conflict, but perhaps it makes sense for your options method to become s3_sync_options?, i.e.

class << self
  def s3_sync_options
    @@options
  end

  module Helpers
    def s3_sync_options
      ::Middleman::S3Sync.s3_sync_options
    end
  end
end

Cannot load ruby progressbar

This might be an n00b-error on my part, but I get this error on "middleman build":

/var/lib/gems/1.9.1/gems/middleman-s3_sync-3.0.12/lib/middleman-s3_sync.rb:4:in `require': cannot load such file -- ruby-progressbar (LoadError)

"bundle install" says it's complete, and I am using ruby-progressbar 1.1.0

"middleman s3_sync" works though, and the progressbar shows.

Deeper Checksum Check for GZipped Data

Using GZip to compress data stores the time stamp of the compressed file in its header. This is enough to change the checksum of the compressed if the original file was modified or touched in between. This may happen when the build directory is removed or a CI system builds and deploy the site. Comparing the MD5 hash of a local gzipped file to the etag of an S3 file is not sufficient to determine that the content is or is not identical.

We need to pull the body from S3, decompress it and compare it's MD5 to the original file's MD5 in order to be satisfied whether the file is identical or different.

AWS permission requirements

We're crafting an IAM user policy for use with this plugin. We weren't able to get it to work until we gave the IAM user read access to all buckets in our account. Write access is only required for the configured bucket. It seems like read should be similarly restricted.

enhancement: yield better message when bucket does not exist

OR, create bucket. I think a good failure message makes sense as opposed to automatic creation. This is certainly just a nice to have but I ran into it on the first test.

/Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/gems/middleman-s3_sync-3.0.31/lib/middleman/s3_sync.rb:96:in `block in bucket_files': undefined method `files' for nil:NilClass (NoMethodError)
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/gems/middleman-s3_sync-3.0.31/lib/middleman/s3_sync.rb:95:in `tap'
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/gems/middleman-s3_sync-3.0.31/lib/middleman/s3_sync.rb:95:in `bucket_files'
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/gems/middleman-s3_sync-3.0.31/lib/middleman/s3_sync.rb:91:in `remote_paths'
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/gems/middleman-s3_sync-3.0.31/lib/middleman/s3_sync.rb:73:in `paths'
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/gems/middleman-s3_sync-3.0.31/lib/middleman/s3_sync.rb:60:in `resources'
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/gems/middleman-s3_sync-3.0.31/lib/middleman/s3_sync.rb:139:in `files_to_create'
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/gems/middleman-s3_sync-3.0.31/lib/middleman/s3_sync.rb:127:in `work_to_be_done?'
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/gems/middleman-s3_sync-3.0.31/lib/middleman/s3_sync.rb:20:in `sync'
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/gems/middleman-s3_sync-3.0.31/lib/middleman-s3_sync/commands.rb:37:in `s3_sync'
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/gems/thor-0.18.1/lib/thor/command.rb:27:in `run'
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/gems/thor-0.18.1/lib/thor/invocation.rb:120:in `invoke_command'
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/gems/thor-0.18.1/lib/thor.rb:363:in `dispatch'
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/gems/thor-0.18.1/lib/thor/base.rb:439:in `start'
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/gems/middleman-core-3.1.4/lib/middleman-core/cli.rb:77:in `method_missing'
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/gems/thor-0.18.1/lib/thor/command.rb:29:in `run'
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/gems/thor-0.18.1/lib/thor/command.rb:128:in `run'
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/gems/thor-0.18.1/lib/thor/invocation.rb:120:in `invoke_command'
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/gems/thor-0.18.1/lib/thor.rb:363:in `dispatch'
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/gems/thor-0.18.1/lib/thor/base.rb:439:in `start'
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/gems/middleman-core-3.1.4/lib/middleman-core/cli.rb:22:in `start'
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/gems/middleman-core-3.1.4/bin/middleman:18:in `<top (required)>'
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/bin/middleman:23:in `load'
from /Users/kross/.rvm/gems/ruby-2.0.0-p247@acme/bin/middleman:23:in `<main>'

How to deploy with gzipped assets?

Hey there,

Thanks for this great gem! Really helpful. I've one issue though: I've set s3_sync.prefer_gzip to true but it won't deploy the gzipped assets. When I run middleman build, it creates the gzipped files but on middleman s3_sync, it only deploys the unzipped files to the bucket.

This is my config.rb:

configure :development do
    activate :livereload
end

set :css_dir, 'stylesheets'
set :js_dir, 'javascripts'
set :images_dir, 'images'

configure :build do
    activate :minify_css
    activate :minify_javascript
    activate :minify_html
    activate :asset_hash
    activate :relative_assets
    activate :gzip
end

activate :s3_sync do |s3_sync|
    s3_sync.bucket                     = 'example.com' # The name of the S3 bucket you are targetting. This is globally unique.
    s3_sync.region                     = 'eu-west-1'     # The AWS region for your bucket.
    s3_sync.aws_access_key_id          = '...'
    s3_sync.aws_secret_access_key      = '...'
    s3_sync.delete                     = true # We delete stray files by default.
    s3_sync.after_build                = false
    s3_sync.prefer_gzip                = true
    s3_sync.path_style                 = true
    s3_sync.reduced_redundancy_storage = false
    s3_sync.acl                        = 'public-read'
    s3_sync.encryption                 = false
    s3_sync.prefix                     = '141-testing'
    s3_sync.version_bucket             = false
end

caching_policy 'text/html', max_age: 0, must_revalidate: true
default_caching_policy max_age:(60 * 60 * 24 * 365)

Did I miss anything?

Thanks,
Aaron

Error during sync - undefined method `metadata`

I'm using the latest published versions of all MiddleMan related gems. My Gemfile.lock is here https://gist.github.com/jakemauer/6453177 if you want to check versions.

Running the standard middleman s3_sync command gets me about half way through generating the paths to evaluate and then it stalls. Eventually it fails yielding this trace:

/Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/gems/middleman-s3_sync-3.0.16/lib/middleman/s3_sync/resource.rb:154:in `redirect?': undefined method `metadata' for nil:NilClass (NoMethodError)
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/gems/middleman-s3_sync-3.0.16/lib/middleman/s3_sync/resource.rb:138:in `status'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/gems/middleman-s3_sync-3.0.16/lib/middleman/s3_sync/resource.rb:108:in `to_create?'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/gems/middleman-s3_sync-3.0.16/lib/middleman/s3_sync.rb:119:in `block in files_to_create'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/gems/middleman-s3_sync-3.0.16/lib/middleman/s3_sync.rb:119:in `select'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/gems/middleman-s3_sync-3.0.16/lib/middleman/s3_sync.rb:119:in `files_to_create'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/gems/middleman-s3_sync-3.0.16/lib/middleman/s3_sync.rb:107:in `work_to_be_done?'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/gems/middleman-s3_sync-3.0.16/lib/middleman/s3_sync.rb:20:in `sync'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/gems/middleman-s3_sync-3.0.16/lib/middleman-s3_sync/commands.rb:46:in `s3_sync'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/gems/thor-0.18.1/lib/thor/command.rb:27:in `run'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/gems/thor-0.18.1/lib/thor/invocation.rb:120:in `invoke_command'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/gems/thor-0.18.1/lib/thor.rb:363:in `dispatch'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/gems/thor-0.18.1/lib/thor/base.rb:439:in `start'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/gems/middleman-core-3.1.4/lib/middleman-core/cli.rb:77:in `method_missing'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/gems/thor-0.18.1/lib/thor/command.rb:29:in `run'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/gems/thor-0.18.1/lib/thor/command.rb:128:in `run'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/gems/thor-0.18.1/lib/thor/invocation.rb:120:in `invoke_command'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/gems/thor-0.18.1/lib/thor.rb:363:in `dispatch'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/gems/thor-0.18.1/lib/thor/base.rb:439:in `start'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/gems/middleman-core-3.1.4/lib/middleman-core/cli.rb:22:in `start'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/gems/middleman-core-3.1.4/bin/middleman:18:in `<top (required)>'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/bin/middleman:23:in `load'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/bin/middleman:23:in `<main>'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/bin/ruby_noexec_wrapper:14:in `eval'
    from /Users/jake/.rvm/gems/ruby-2.0.0-p195@standing-cloud/bin/ruby_noexec_wrapper:14:in `<main>

Improve documentation on .s3_sync file

The documentation isn't super clear if it's OK to leave out s3_sync.aws_access_key_id and s3_sync.aws_secret_access_key from the config.rb file if we use a .s3_sync file.

I suggest that we try to improve the documentation with a note about this case to assist new users.

How do I change the default_caching_policy?

Hello,

I'm pretty new to using middleman and ruby and so I'm having a hard time figuring out how to set a max_age or expires headers to enable browser caching. The readme mentioned adding this:

default_caching_policy max_age:(60 * 60 * 24 * 365)

However, it didn't mention where in the config.rb this should go. I've tried:

  • Before and inside the activate block, this results in the error: "undefined method `default_caching_policy'"
  • After the activate block; while this results in no error, it doesn't set the max_age either

Thanks, and sorry for the newb question.

Testing on real site

Been testing middleman and various extensions out in prep to move a production sized site to middleman...

Found a few things that may be easy fixes or version issues but they are very consistent and seem to be volume related

  1. Consistently blows up with the following error at 201 and 241 files in when creating or updating
/Users/rwboyer/.rvm/gems/ruby-2.0.0-p247/gems/excon-0.27.6/lib/excon/socket.rb:138:in `getaddrinfo': getaddrinfo: nodename nor servname provided, or not known (SocketError) (Excon::Errors::SocketError)
  1. Consistently SILENTLY fails when removing files at 139 files in. Just finishes but if you re-run and re-run it will delete 139 files and exit until it actually gets rid of all of them.

Just a note: This site has a few thousand pages and s3cmd, carrierwave (which I believe uses Fog/Excon as well) etc work fine. Using latest version as of today. Here is a typical session where it fails after 201/241 (when re-run it will sync another 241 files again and again then blow up with same result)

https://gist.github.com/rwboyer/7272362

RB

Adding CLI switch to define bucket

Would you consider adding a command line switch to define the bucket target?

E.g.

$ middleman s3_sync -b bucket-name-staging
$ middleman s3_sync -b bucket-name-production

Great work BTW!

Prefix is ignored

Hey—me again. There seem to be cases in which the prefix is ignored.

This is my config:

@base_url = "http://www.example.com"
@prefix = "141-testing"

configure :development do
    activate :livereload
end

set :css_dir, 'stylesheets'
set :js_dir, 'javascripts'
set :images_dir, 'images'

configure :build do
    activate :minify_css
    activate :minify_javascript
    activate :minify_html
    activate :asset_hash
    activate :relative_assets
    set :http_prefix, @base_url + '/' + @prefix + '/'
    activate :gzip
end

activate :s3_sync do |s3_sync|
    s3_sync.bucket                     = 'example.com'
    s3_sync.region                     = 'eu-west-1'
    s3_sync.aws_access_key_id          = 'XXX'
    s3_sync.aws_secret_access_key      = 'XXX'
    s3_sync.delete                     = true
    s3_sync.after_build                = false
    s3_sync.prefer_gzip                = true
    s3_sync.path_style                 = true
    s3_sync.reduced_redundancy_storage = false
    s3_sync.acl                        = 'public-read'
    s3_sync.encryption                 = false
    s3_sync.prefix                     = @prefix
    s3_sync.version_bucket             = false
end

caching_policy 'text/html', max_age: 0, must_revalidate: true
default_caching_policy max_age:(60 * 60 * 24 * 365)

This is what happens:

➜  example_com git:(master) rm -rf build && middleman build && middleman s3_sync        
            create  build/stylesheets/all-60340be8.css
            create  build/images/sprites/play-button-0ea3d61a.png
            create  build/images/sprites-s32bba63fec-b7234ca7.png
            create  build/images/sprites/logo-large-837bb009.png
            create  build/images/sprites/logo-small-f1358f61.png
            create  build/images/meta-2fb982ce.jpg
            create  build/images/preview-779979d2.jpg
            create  build/images/svg/logo-eef866ad.svg
            create  build/images/svg/play-button-24625fea.svg
            create  build/javascripts/respond.src-c5e2db8d.js
            create  build/javascripts/modernizr.custom-0507b55e.js
            create  build/javascripts/all-f4da3a37.js
            create  build/index.html
                gzip  build/javascripts/all-f4da3a37.js.gz (410 Bytes smaller)
                gzip  build/javascripts/modernizr.custom-0507b55e.js.gz (2.4 KB smaller)
                gzip  build/javascripts/respond.src-c5e2db8d.js.gz (2.4 KB smaller)
                gzip  build/index.html.gz (5.2 KB smaller)
                gzip  build/stylesheets/all-60340be8.css.gz (17.9 KB smaller)
                gzip  Total gzip savings: 28.2 KB
== LiveReload is waiting for a browser to connect
         s3_sync  Gathering the paths to evaluate.
         s3_sync                                                                                                                                                                      |
Ready to apply updates to example.com.
         s3_sync  Creating images/meta-2fb982ce.jpg
         s3_sync  Creating images/preview-779979d2.jpg
         s3_sync  Creating images/sprites-s32bba63fec-b7234ca7.png
         s3_sync  Creating images/sprites/logo-large-837bb009.png
         s3_sync  Creating images/sprites/logo-small-f1358f61.png
         s3_sync  Creating images/sprites/play-button-0ea3d61a.png
         s3_sync  Creating images/svg/logo-eef866ad.svg
         s3_sync  Creating images/svg/play-button-24625fea.svg
         s3_sync  Creating index.html (gzipped)
         s3_sync  Creating javascripts/all-f4da3a37.js (gzipped)
         s3_sync  Creating javascripts/modernizr.custom-0507b55e.js (gzipped)
         s3_sync  Creating javascripts/respond.src-c5e2db8d.js (gzipped)
         s3_sync  Creating stylesheets/all-60340be8.css (gzipped)

The files are deployed to the bucket's top level. I get the same result when I add the --force switch. I'm using version 3.0.29.

Use build_dir instead of hard coding build path

Thanks for this plugin. I currently deploy to 2 buckets, one staging, one production. I do something like:

set :env, ENV['ENV'] ||= 'development'
set :build_dir, "build/#{settings.env}"

to build into different sub directories, but s3_sync has the build path hardcoded as build so it actually uploads each environment. It would be helpful if you just read the build_dir and used that.

Is a directory - build/2013

After running middleman s3_sync, the CLI output shows the following error Is a directory - build/2013 (Errno::EISDIR), as though it doesn't support directories in the build directory. That can't be right. What did I do wrong?

Failing because of directories…

I'm not sure how to post this one… I'm actually assuming I'm doing something wrong. Running middleman s3_sync currently generates this error:

/gems/middleman-s3_sync-3.0.11/lib/middleman/s3_sync/resource.rb:139:in `read': Is a directory - build/articles/ (Errno::EISDIR)

EDIT: (accidentally hit submit) I'm using activate directory_indexes or whatever… but removing it doesn't change anything apparently. I'm quite confused.

How to define file types that will be gzipped? (e.g. SVG)

How does middleman-s3_sync determine wether a file should be gzipped during deployment? Is there a way to supply a list of file types? I’m asking because I noticed that SVG files don’t get gzipped even though s3_sync.prefer_gzip is set to true.

Thanks!

Caching Policy on compressed content

s3_sync should set the Vary: encoding header under the following conditions:

  • A caching policy is set
  • The gzipped content is pushed to the server.

Technically, S3 will doesn't not have the ability to server both compressed and uncompressed headers. It doesn't not look at the Accept-Encoding header. However, this is the correct way to present the compressed content back.

include deploy.rb

I'm using github for hosting projects public and do not want to include AWS-key into config.rb. Would it be possible to have the s3_sync config in a separate file and include it IF it exist?

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.