简体   繁体   中英

update files from local to remote with git and capistrano

I have deployed my app in remote server with capistrano and git. I'm novice with capistrano and git, and my question is:

eg

I make a change and add code in any file from my local project, eg change 2 lines in controller or model or view or css or js or routes.rb or devise.rb...etc.

before I had a ftp and replace the files via ftp, I see that this way is not good for rails.

I want to know how can I send those changes to my production remote app in my vps remote server.

I have tried:

cap deploy

but is very very slowly and overload the server. I dont think that is way is correct

I dont know if this must be doing with capistrano or with git eg I suposse with git is:

git remote add origin user@ip.ip.ip.ip/~/project
git push origin master

Its possible use this code for deploy changes in production app in remote server? or have I that use capistrano for make changes in app in production server?

Sorry for mi ignorance but I'm novice with rails and capistrano and git.

Thank you

You can deploy code using either just git itself or with capistrano (together with git).

Using just Git

  1. You only need to run "git remote add origin user@ip.ip.ip.ip/~/project" one time, after this your settings are already saved. If you want to see your remote git repos, just type "git remote"
  2. After you have made your changes and run git commit (I assume you know how to do this already), then run "git push origin master" to push all your changes to the remote repo.
  3. Now SSH to your remote server, eg "ssh myuser@mydomain.com" (for Mac) or using Putty (for Windows)
  4. Once logged in to the remote server, navigate to your app root folder.
    • if you have never cloned your git repo to your remote server before, you will first need to run "git clone "
    • otherwise, just run "git pull origin master". This will fetch and pull the changes from Step 2 above to your remote server. And now you are finished!

Advantage: This approach only pulls your most recent changes to your remote server, so it is much faster.

Disadvantage: You have to manually run a lot of commands to SSH to server and git pull.

Using Capistrano

  1. You mention you can run "cap deploy" so I assume your Capistrano setup is fine. This approach is slower because it pulls your latest commit (and potentially your whole git repo) when you deploy.
  2. If you want to speed up your Capistrano deployment, you can add the following to your deploy.rb. This keeps a copy of your git repo on your remote server instead of doing a full git clone upon every deploy.

    set :deploy_via, :remote_cache

Advantage: Just type "cap deploy" and deployment happens (plus all the capistrano benefits of deployment rollback etc)

Disadvantage: Slower than just git pull.

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