-
Notifications
You must be signed in to change notification settings - Fork 33
Customizing Deployment
Out of the box, Autotune supports deploying to the local filesystem or to Amazon S3. Filesystem deployment is useful for development or single server installations. If you plan to use Autotune in any production capacity, you will almost certainly use Amazon S3.
Deployment targets are defined in your project's config/initializers/autotune.rb
file using the Autotune.deployment
method.
Lets start with a simple filesystem deployment target where we will deploy preview versions of the projects:
Autotune.deployment(
:preview,
:connect => 'file:///Users/ryanmark/autotune/public/preview'
:base_url => 'http://localhost:3000/preview'
)
The first parameter :preview
is the name of the target we are configuring. Autotune uses three different targets for deploying files.
-
:preview
Where built projects are deployed while they are in draft or if they've been changed after publish. -
:publish
Where built projects are deployed for public consumption. -
:media
Used by autotune to store thumbnails and sample projects.
To define a deployment target, you need at least three pieces of information:
- The name of the target (publish, preview or media)
- A connection string/destination URL
- An HTTP URL where the deployed files will be accessible after deploy
The :connect
parameter is the connection string, and follows the same rules as any URL connection string: protocol://username:password@server/path
. Currently Autotune only has built in support for file
and s3
protocols, but you can define your own deployer if you need support for ftp
or some other file store.
The :base_url
is the url where the deployed files can be accessed over HTTP. This URL is also passed to a blueprint during the build phase. The leading http
or https
is optional, in case you want to use a protocol-less url in your blueprint.
Lets look at an example S3 deployment:
Autotune.deployment(
:publish,
:connect => 's3://my-bucket/autotune'
:base_url => 'https://my-bucket.s3-website-us-east-1.amazonaws.com/autotune'
)
In this example we are deploying to a bucket we created called my-bucket
to a path autotune
. You'll notice the base url includes s3-website-us-east-1
. When deploying to an S3 bucket, you must enable static website hosting.
You'll also notice that there is no secret key or id for Amazon in this example. Autotune looks for your credentials in the standard AWS environment variables: AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
.
You will have at least three Autotune.deployment
lines in your autotune.rb
initializer, one for each target. If you wish to have different deployment locations based on your Rails environment (production, staging, development) you can wrap your Autotune.deployment
lines in simple if/else conditions:
if Rails.env == 'production'
...
elsif Rails.env == 'staging'
...
else
...
end
The Autotune.deployment
method will also take a block of code that is evaluated against a project or blueprint to decide where to deploy it.
Autotune.deployment(:publish) do |deployable, options|
if deployable.type == 'graphic'
{ :connect => 'graphics server'
:base_url => 'graphics url' }
else
{ :connect => 'misc server'
:base_url => 'misc url' }
end
end
At Vox Media we use this functionality to deploy blueprints of type app
, which are standalone websites, to a different location than type graphic
, which are meant to be embedded into other pages.
It is also possible to define your own deployer if your needs are not met by the filesystem or S3 options. See the code for Autotune::Deployers::File and Autotune::Deployers::S3 as examples.