Coder Social home page Coder Social logo

mina-rsync's Introduction

Mina::Rsync for Mina

Gem version

Deploy with Rsync to your server from any local (or remote) repository when using Mina.
Saves you from having to install Git on your production machine and allows you to customize which files you want to deploy. Also allows you to easily precompile things on your local machine before deploying.

Tour

  • Suitable for deploying any apps, be it Ruby, Rails, Node.js or others.
  • Exclude files from being deployed with Rsync's --exclude options.
  • Precompile files or assets easily before deploying, like JavaScript or CSS.
  • Caches your previously deployed code to speed up deployments ~1337%.
  • Currently works only with Git, so please shout out your interest in other SCMs.

Using

Install with:

gem install mina-rsync

Require it at the top of your Minafile (or config/deploy.rb):

require "mina/rsync"

Set some rsync_options to your liking:

set :rsync_options, %w[--recursive --delete --delete-excluded --exclude .git*]

Then invoke Mina::Rsync's tasks from your deploy task:

task :deploy do
  deploy do
    invoke "rsync:deploy"
  end
end

And after setting regular Mina options, deploy as usual!

mina deploy

Implementation

  1. Clones and updates your repository to rsync_stage (defaults to tmp/deploy) on your local machine.
  2. Checks out the branch set in the branch variable (defaults to master).
  3. Rsyncs to rsync_cache (defaults to shared/deploy) on the server.
  4. Copies the content of the cache directory to the build directory.

After that, Mina takes over and runs its usual tasks and symlinking.

Excluding files from being deployed

If you don't want to deploy everything you've committed to your repository, pass some --exclude options to Rsync:

set :rsync_options, %w[
  --recursive --delete --delete-excluded
  --exclude .git*
  --exclude /config/database.yml
  --exclude /test/***
]

Precompile assets before deploy

Mina::Rsync runs rsync:stage before rsyncing. Hook to that like this:

task :precompile do
  Dir.chdir settings.rsync_stage do
    system "rake", "assets:precompile"
  end
end

task "rsync:stage" do
  invoke "precompile"
end

Configuration

Set Mina variables with set name, value.

Name Default Description
repository . The path or URL to a Git repository to clone from.
branch master The Git branch to checkout.
rsync_stage tmp/deploy Path where to clone your repository for staging, checkouting and rsyncing. Can be both relative or absolute.
rsync_cache shared/deploy Path where to cache your repository on the server to avoid rsyncing from scratch each time. Can be both relative or absolute.
rsync_options [] Array of options to pass to rsync.
rsync_copy rsync --archive --acls --xattrs Command used to copy files from the cache directory to the build path on the server.

License

Mina::Rsync is released under a Lesser GNU Affero General Public License, which in summary means:

  • You can use this program for no cost.
  • You can use this program for both personal and commercial reasons.
  • You do not have to share your own program's code which uses this program.
  • You have to share modifications (e.g bug-fixes) you've made to this program.

For more convoluted language, see the LICENSE file.

About

Andri Möll made this happen.
Monday Calendar was the reason I needed this.

If you find Mina::Rsync needs improving, please don't hesitate to type to me now at [email protected] or create an issue online.

mina-rsync's People

Contributors

moll avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

mina-rsync's Issues

Path to rsync

I am having the following error

-----> Copying from cache directory to build path
rsync: --acls: unknown option
rsync error: syntax or usage error (code 1) at /SourceCache/rsync/rsync-42/rsync/main.c(1333) [client=2.6.9]

Not sure if this is generated in my dev machine or the server, I assume this step happens on the server.

So the error seems to be with the version of rsync I presume.
I have a newer version of rsync installed, but it is in a different path. So mina seems to be using the old system rsync.

Is there an option in mina-rsync to provide the path to the rsync binary?

thanks

Rails environment loading triggered in rsync cache directory

Checking connectivity... done.
-----> Staging...
Git checkout: HEAD is now at 3359fcf d
/Users/XXX/Projekty/xxx/tmp/deploy/config/initializers/devise.rb:225: warning: already initialized constant OpenSSL::SSL::VERIFY_PEER
/usr/local/rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55: warning: previous definition of VERIFY_PEER was here
rake aborted!
Errno::ENOENT: No such file or directory @ rb_sysopen - /Users/XXX/Projekty/xxx/tmp/deploy/config/application.yml
/Users/XXX/Projekty/xxx/vendor/bundle/ruby/2.1.0/gems/settingslogic-2.0.9/lib/settingslogic.rb:102:in `initialize'
(...)

error is igonred and the deploy goes on without problem

Obviously clean clone from the repo does not have server specific (private) config files, so this does pose a problem. I used settings_logic and figaro, both affected.

This is all I have in 'deploy' task:

task :deploy => :environment do
  deploy do
    invoke "rsync:deploy"
    invoke :'deploy:link_shared_paths'
and

This does not happen with default git driven deploys, of course.

undefined method `set_default' for main:Object (NoMethodError)

I do not have anything like set_default :repository, "." in config/deploy.rb and I do have require "mina/rsync" in the file.

(...)/vendor/bundle/ruby/2.1.0/gems/mina-rsync-1.1.0/lib/mina/rsync.rb:8:in
`<top (required)>': undefined method `set_default' for main:Object
(NoMethodError)(...)

Make this a module for Mina

Would it make sense to try to get this merged into Mina as a plugin? Git is on a module-level in Mina, seems like this would be a good fit.

It would also increase the number of users and thus (likely) the number of contributors too.

Not ignoring excluded files?

I am having a weird issue with mina-rsync:

As a part of my deployment I precompile some stuff via one of my gulp tasks. For that I need to install my node_modules.

Of course - I don't want the node_modules folder to be rsynced, so I added it as --excluded in :rsync_options. The problem is; The setting seems to be discarded. Any idea why that is?

mina deploy -v shows me the following (correct) rsync command, which seems to not be used, because it is correct and works as it should, when I run it on the command line:

rsync --exclude ".git*" --exclude "node_modules/" --exclude "settings.json" --exclude "typings" --recursive --delete --delete-excluded tmp/deploy/ [email protected]:~/path/to/project

Here are the important parts of my deploy.rb:

require 'rubygems'
require 'bundler/setup'
require 'mina/rsync'

# ...
set :repository, '.'
set :branch, 'master'
set :rsync_options, %w[
    --exclude ".git*" 
    --exclude "node_modules/" 
    --exclude "settings.json"  
    --exclude "typings"  
    --recursive  
    --delete  
    --delete-excluded
]

# ...

# precompile task
task :precompile do
  Dir.chdir settings.rsync_stage do

    puts "-----> removing old builds"
    system "rm", "-R", "js", "htdocs/dist"

    puts "-----> Installing modules"
    # npm install is here
    system "npm", "install", "--quiet";
    system "bundle", "install";

    puts "-----> installing typescript definitions"
    system "tsd", "reinstall";

    puts "-----> running gulp build"
    system "gulp", "build";

    def checkfile(file)
      if not File.exists?(file)
        throw "file " + file + " does not exist"
      else
        puts "Compiled file exists: " + file;
      end
    end;

    puts "-----> checking if compiled files exist"
    checkfile("htdocs/dist/main.css")
    checkfile("htdocs/dist/scripts.js")
    checkfile("htdocs/dist/scripts.min.js")
  end;
end;

task "rsync:stage" do
  invoke :precompile;
end;

desc "Deploys the current version to the server."
task :deploy => :environment do
  deploy do
    # Put things that will set up an empty directory into a fully set-up
    # instance of your project.
    invoke "rsync:deploy"
    invoke "deploy:cleanup"
    queue "npm install --production --quiet"
    queue "cd htdocs && bower install"


    to :launch do
      queue "forever stopall"
      queue "forever start #{deploy_to}/#{current_path}/js/index.js"
    end
  end
end

fatal: Not a git repository: 'tmp/deploy/.git'

$ mina deploy
-----> Staging...
fatal: Not a git repository: 'tmp/deploy/.git'
Git checkout: fatal: Not a git repository: 'tmp/deploy/.git'

Whatever surrouding git setup in deploy.rb I use or don't use, i get this error.

Execute something locally?

Hello,

I have a simple question: Is it possible to execute somthing locally, prior to rsyncing?
In my use case I would like to run my grunt tasks, so that my LESS in compiled and my Javascript minified. Is that possible?

Doesn't work with submodules

I can use this tool successfully but it doesn't recursively clone submodules (which I have). I know mina supports this. Can it be added or am I missing something?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.