This article will walk you through configuring and deploying your Spree application to an environment configured with the Deployment Service.
endprologue.
INFO: This guide presumes you are running a Spree version of 0.60.x or later, and that your servers have be built using the Spree Deployment Service
In order to deploy your application to the standard Deployment Service configuration you will need to add the following to your Gemfile:
group :production do
gem ‘unicorn’
gem ‘mysql2’
gem ‘foreman’
gem ‘therubyracer’ #only required for 0.70.x or later
end
group :development do
gem ‘capistrano’
end
Once you saved the Gemfile, run bundle install and commit and push your changes to your remote git repository.
NOTE: Please note it’s important to ensure you’ve committed your Gemfile.lock file also.
Capistrano is the easiest way to deploy your application to your hosting environment, however you can use any system you prefer.
The Deployment Service will automatically generate a custom recipe for your environment, specific for your Spree version and including your server(s) and git repository details.
To add the basic Capistrano files to your application run the following command:
capify .This will create the config/deploy.rb
file that will contain the details about your server(s), application repository, etc. You can download your Capistrano deploy.rb for each of your configured environments from deployment edit page.
NOTE: The recipe is only available to environment that have chosen “My own custom Spree application”, and not the automatic demo store deployment.
Once you’ve downloaded the automatically generated recipe, replace the contents of your applications config/deploy.rb
with it.
The Deployment Service does not automatically set any authentication settings on your servers so you will need to this before continuing, there are two options available:
1. Manually set the spree user’s password by running the following command (when logged in as root):
passwd spree2. Avoid password prompt altogether by adding your SSH public key to spree user’s authorized_keys file, which can be found here:
/home/spree/.ssh/authorized_keysOnce you’ve completed all the changes above you’re ready to deploy your application.
Check everything is configured correctly:
cap deploy:checkDo a cold deploy, which checks out the application and migrates the database:
cap deploy:coldIf everything worked correctly you should now have your application deployed and database migrated.
INFO: You might want to restore a database dump to configure your data / users / etc.
If you’re having trouble deploying or starting your application for the first time here’s a couple of things to try:
- Review the following log files for indications of the problem:
- /data/spree/current/log/unicorn.stderr.log
- /data/spree/current/log/production.log
- /var/log/nginx/error.log
- /var/log/spree/web-1.log
- When deploying from private repositories it vital that you have ssh-agent running and your keys added, normally done by executing the following before running `cap`: