Last active
August 29, 2015 14:02
-
-
Save matthieupinte/a61523a5865bdf66b9d8 to your computer and use it in GitHub Desktop.
Sample deploy with Capistrano
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this lines to your Gemfile: | |
``` | |
# Use Capistrano for deployment | |
gem 'capistrano' | |
gem 'capistrano-rails' | |
``` | |
Run `bundle install` | |
Run `cap install` | |
Edit config/deploy/staging.rb: | |
change `server 'exemple.com', roles: %w{web app}, my_property: :my_value` | |
to `server 'remote.com', user: 'deploy'` | |
Edit config/deploy.rb: | |
line `set :application, 'my app name'` | |
line `set :repo_url, 'git@example.com:me/my_repo.git'` | |
change ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp } | |
to `set :branch, 'master'` | |
On the remote server: | |
`root@remote $ adduser deploy` | |
`root@remote $ passwd -l deploy` | |
On your local machine: | |
`me@localhost $ ssh-keygen -t rsa -C 'me@email.com'` (if you don't have ssh key) | |
`me@localhost $ ssh-add -l` (if you see nothing, run: `me@localhost $ ssh-add`) | |
`me@localhost $ ssh-copy-id -i ~/.ssh/id_rsa.pub deploy@remote-server.com` | |
On the remote server: | |
`root@remote $ su deploy && cd ~/` | |
`deploy@remote $ chmod 700 .ssh` | |
`deploy@remote $ chmod 600 .ssh/authorized_keys` | |
On your local machine, test: | |
`ssh -A deploy@remote-server.com 'git ls-remote git@exemple.com:username/repository.git'` | |
(list the remote objects of your git repository) | |
if you get error: "host key verification failed", log in into the remote-server, and run: | |
`deploy@remote $ ssh git@github.com` | |
On the remote server: | |
`root@remote $ chown deploy:deploy /var/www/my_app` | |
`root@remote $ umask 0002` | |
`root@remote $ chmod g+s /var/www/my_app` | |
`root@remote $ mkdir /var/www/myapp/{releases,shared}` | |
On your local machine, in the project directory, test: | |
`me@localhost $ cap staging git:check` | |
if everything alright, you can deploy "staging": | |
`me@localhost $ git commit -am "Initial commit" && git push origin master` | |
`me@localhost $ cap staging deploy` | |
Change branches, servers or anything to make it work as you want... | |
Sources: | |
http://capistranorb.com/documentation/getting-started/installation/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment