简体   繁体   中英

Rails 4.2 capistrano 3 deployment

I am totally new to rails deployment. After googling, I still find it hard to understand how to deploy rails apps.

So, my questions are:

  1. After setting up the VPS with all rails dependencies, where do I store my codebase? The root directory of the VPS or some specific locations eg www/ or public/ ?

  2. Should I upload the whole rails app folder or just part of it? I have paperclip in my rails app, and paperclip creates a system/ directory in the public/ folder, so should I upload system/ ?

  3. In Capistrano 3, there is a repo_url field, I know they support file://, https://, ssh://, or svn+ssh:// , but most of the articles about capistrano put github repositories into that. However, I do not have such a github repo. What should I input then?

Thank you for your attention.

Answers to the specific questions raised:

After setting up the VPS with all rails dependencies, where do I store my codebase? The root directory of the VPS or some specific locations eg www/ or public/?

It will be deployed to the folder pointed by :deploy_to parameter. If not specified, :deploy_to defaults to /var/www/#{fetch(:application) See: https://github.com/capistrano/capistrano/blob/05f63f5f333bb261f2a4c4497174361c48143252/lib/capistrano/defaults.rb#L3

Should I upload the whole rails app folder or just part of it? I have paperclip in my rails app, and paperclip creates a system/ directory in the public/ folder, so should I upload system/?

Paperclip system folder is specific to the environment; each environment (development, production,...) will have its own system folder which will store the files uploaded on that specific environment. This folder should not be part of the code being deployed.

The recommended way of handing such folders is the keep them in a shared folder on the server, and create symlinks in the current version of the code so that the same folder is used for storing/retrieving attachments. See Section 3. Update custom links section in http://robmclarty.com/blog/how-to-deploy-a-rails-4-app-with-git-and-capistrano for more details about this.

As mentioned there, the same applies to config/database.yml file, and any other file containing environment specific configurations.

In Capistrano 3, there is a repo_url field, I know they support file://, https://, ssh://, or svn+ssh://, but most of the articles about capistrano put github repositories into that. However, I do not have such a github repo. What should I input then?

Depends on where the code you are deploying is stored. If it is in a local folder, use the file::// format to specify where the files are located.

You can set up your own private git server , then in deploy.rb you can put something like

set :repo_url, 'ssh://user@server_ip/path/to/your_git_repo.git'

When you commit your changes to the git repo, you do not have to upload the app to the server. Capistrano will upload the app for you when you deploy.

where do i put my code base? This is determined by what you put in deploy.rb eg

set :deploy_to, '/path/to/my_codebase'

Whether to upload the /system directory will depend on whether you want the paperclip images on your version control. If not you can add the directory to gitignore . Here is a tutorial on how to deploy on ubuntu 14.04 passenger and NGINX. if you are not using Passenger and Nginx you can skip to how to configure capistrano and make adjustments depending on your setup.

EDIT

You need to install git on your development machine and set up a git server on your VPS as explained on the link above, add your remote server to your local machine using

git remote add origin <server>

where 'server' is the url to your git repo in the VPS eg

ssh://VPS_user@VPS_ip/path/to/your_git_repo.git

Now when you commit and push your changes to the server, capistrano will deploy the latest version on your git server.

Here is a link with a guide on how to get started with git

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM