I am using Capistrano to deploy my Rails application to a VPS (as shown in episode 335 on railscasts.com). I have some custom fonts I’m using for the application and don’t want to check them into source-control for licensing reasons (See clarification at bottom).
What’s the best way to go about this? Should I edit the deploy.rb file to sftp the assets/webfonts directory from my local computer? Maybe I just need to copy them manually to the my_app/shared/assets directory on the VPS, but I’d rather it be automated as part of the deploy task.
Here’s my current deploy.rb file:
require "rvm/capistrano"
require "bundler/capistrano"
server "ip_address", :web, :app, :db, primary: true
set :application, "armory"
set :user, "username"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
set :scm, "git"
set :github_user, "gorrillamcd"
set :repository, "git@github.com:#{github_user}/Armory.git"
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
after "deploy", "deploy:cleanup" # keep only the last 5 releases
namespace :deploy do
%w[start stop restart].each do |command|
desc "#{command} unicorn server"
task command, roles: :app, except: {no_release: true} do
run "/etc/init.d/unicorn_#{application} #{command}"
end
end
task :setup_config, roles: :app do
sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
run "mkdir -p #{shared_path}/config"
put File.read("config/database.base.yml"), "#{shared_path}/config/database.yml"
puts "Now edit the config files in #{shared_path}."
end
after "deploy:setup", "deploy:setup_config"
task :symlink_config, roles: :app do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
run "ln -nfs #{shared_path}/config/initializers/stripe.rb #{release_path}/config/initializers/stripe.rb"
end
after "deploy:finalize_update", "deploy:symlink_config"
desc "Make sure local git is in sync with remote."
task :check_revision, roles: :web do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
before "deploy", "deploy:check_revision"
end
Edit: Sorry for being so vague beforehand. I’m using Museo Slab from myfonts.com and a public repo on github (check my user profile if you want to see it). I read through the license and found this:
3.The Licensed Webfont(s) may be used on any Website owned or controlled by the Licensee
4.Agencies responsible for multiple clients’ Websites, for example web design agencies or hosting providers, may not share a single Webfont license across multiple clients’ Websites.
Those two lines of the license make me believe that checking the font into a public repository would be against the license, since it could be used on sites that are not mine without obtaining a new license for the font (even though they were free to begin with). I imagine that other people have had this problem before. So my question is, What’s the normal/best way to handle deploy, with Capistrano, fonts (or any file for that matter) that can’t be checked into source control?
I would pack the web fonts in an archive and put that archive somewhere separate from the repository. (Amazon S3 is a prime candidate.) Then, I’d have the release process retrieve and unpack this archive at deploy time.
This lets you put your entire app in your public repository — the Capistrano scripts, the Rake tasks, etc. — but leaves the actual font binaries out, with their location specified as a matter of configuration. This is consistent with 12-factor app principles, treating these webfonts as an external resource needed by but not contained within your application.
You could, for example, specify a
WEBFONTS_URLenvironment variable, and add afetch_webfontsRake task. This task would automatically pull these resources into your application, and would do nothing in the case thatWEBFONTS_URLis unspecified — e.g. if someone else did a checkout of your repo without having these fonts. (You could even make the task do appropriate things with stylesheets, ensuring that the fresh-checkout users get a working app without 404ing on font files.) Rake allows you to add dependencies to existing tasks, so you can ensure this happens automatically as part ofassets:precompile, which Capistrano very likely already invokes.Additionally, this approach works equally well on development and production: you can take a fresh checkout of your own repo, specify the appropriate
WEBFONTS_URL, and end up with a working set of fonts on your local machine. (The dotenv gem makes it easy to get development configuration into environment variables, keeping all your environments consistent.) Just be sure that you.gitignorethe results so you don’t accidentally make them public after all.