bobobo1618 / docpad-plugin-sunny

Uploads stuff to Google or Amazon storage.
31 stars 10 forks source link

Docpad Sunny

So this is another one of the only useful things I've published, yay! Actually distributing my projects is new to me.

Basically, after your Docpad installation finishes generating the static documents, this plugin is meant to upload them all to Amazon S3 or Google Storage, whichever you select. It uses the apparently awesome library, Sunny. Give Ryan some love.

As of 2.0.13, the plugin no longer automatically pushes. Instead, there is a command line option to docpad, deploy-sunny which deploys to Sunny supported providers for you.

Installation

In your Docpad site directory:

Configuration

Configuration is mainly set in your Docpad configuration file in the plugins section (look here for more explanation). The relevant shortname is sunny.

The options are:

An example section from a docpad config:

[...]
    port: 8000
    enabledPlugins:
        sunny: true # Not necessary, just for reference.
    site:
        [...]
    plugins:
        sunny:
            configFromEnv: true
            envPrefixes: ["DOCPAD_SUNNY_", "DOCPAD_", "MY_AWESOME_APP_SUNNY_"]
            cloudConfigs: [
                {
                    sunny: {
                        provider: 'google'
                        account: 'GOOGOPSDG76978SDG'
                        secretKey: 'SD&*G68S&^DG*&6s8SD'
                        ssl: true
                    }
                    container: 'herpderp.com'
                    acl: 'private'
                },
                {
                    sunny: {
                        provider: 'aws'
                        account: 'ADSDG876SDG87S'
                        authUrl: 's3-some-region.amazonaws.com'
                        secretKey: 'A(*G&(S97*S^DG('
                        ssl: true
                    }
                    container: 'meow'
                    acl: false #Uses the policy already set on S3.
                    retryLimit: -1 # Retry as long as is necessary until the upload works.
                }]
[...]

This will read two providers from the file (Google and Amazon). Google is set to private reads and Amazon to use whatever the default is on the bucket.

It is also set to pick up configuration from variables with the prefixes DOCPAD_SUNNY_, DOCPAD_, and MY_AWESOME_APP_SUNNY_ (so DOCPAD_SUNNY_ACCOUNT etc.)

Environment

There are 4 environment variables per prefix that must be configured and 2 optional, that can be set for SSL.

If no prefixes are set in the main configuration section, the default is DOCPAD_SUNNY_

Mandatory for it to work:

Optional:

Running

By default, the plugin won't run unless either NODE_ENV=production or onlyIfProduction is false in the configuration. So either set onlyIfProduction to false, run export NODE_ENV=production before running docpad or run NODE_ENV=production docpad generate.

Generated files will be added to the cloud providers whenever Docpad runs the generate hook.

Custom headers

The plugin actually checks each Docpad file for a piece of metadata named headers. If you put this field in, you can set up a list of HTTP headers that will be sent with the corresponding request. You can use it to force a mime type, set cache control etc.

Security

Since you may wish to use this in an OSS project such as a blog or somesuch or any real application where you want to distribute source but keep all your keys private, there are two options available for configuration:

Known bugs

None! :D

Known solutions to things that aren't quite bugs ;)

Gettings errors like this:

`Received error trying to connect to provider: Error: <?xml version="1.0" encoding="UTF-8"?>

TemporaryRedirectPlease re-send this request to the specified temporary endpoint. Continue to use the original request endpoint for future requests.[redacted][redacted][redacted][redacted].s3-ap-southeast-2.amazonaws.com` Can be fixed by setting the `authUrl` for the config that's having the problem to the endpoint given in the error. In this case, you could add `authUrl: '[redacted].s3-ap-southeast-2.amazonaws.com'` to your configuration. ## Contributors - Me - [nfriedly](https://github.com/nfriedly) - [Ryan Roemer](https://github.com/ryan-roemer) (wrote Sunny) ## License Do what you want so long as this repo be credited or referenced somehow, I ask that [Ryan Roemer](https://github.com/ryan-roemer) be credited also, since he wrote SunnyJS which does all the real work here.