Git Product home page Git Product logo

git-deploy's Introduction

git-deploy

Description

git-deploy is a deployment tool to allow for quick and easy deployments based on the changes in a git repository.

It was originally used to update multiple WordPress installations on shared hosting environments. Ideally Capistrano would have been the perfect tool, but generally shared hosting environments only allow for FTP access, which Capistrano does not support. Likewise rather than using a standard FTP program, when doing a deployment, I only need to upload the files that have been changed. This saves me both time and bandwidth.

I needed something like Capistrano, but simpler.

git-deploy supports deployment over SSH and FTP.

Installation

git-deploy requires the Ruby gems net-ssh, net-sftp, net-scp.

You can install them like so:

sudo gem install net-ssh net-sftp net-scp

Usage

In the root directory of your source code, create a deploy.yml file.

Here is a sample code:

'ftp://example:[email protected]:21/path/to/installation':
  skip: false

You use the URI scheme to define the location of your installation. If you do not want to use the URI scheme, and instead use another identifier. Feel free to do so. Just enter the settings for the host like so:

'example':
  skip: false
  scheme: ftp
  user: example
  password: password
  host: example.com
  port: 21
  path: /path/to/installation
  overwrite_if_same_revision: true

Note: The port field is optional in both the URI scheme and the broken down options

Once you have done creating the deploy.yml, upload to your server a file called REVISION with the revision string for the current revision residing on the server

After you have commited your code to the repository. You can run

git deploy

Additional Keys

The configuration for a site has additional and optional options:

  • skip: true or false (default). Whether to skip the configuration

  • debug_mode: true or false (default). For FTP only. Outputs debugging information

  • passive: true or false (default). For FTP only. Enable passive connection.

  • local_path: string. Only consider files to upload in a particular local path.

How It Works

git-deploy stores file called REVISION on your server inside the root path to your application. This file stores the current revision of your application residing on your server.

When you run a git deploy, git-deploy downloads the REVISION file, and checks to see what files are different between revisions and either upload the changed files or deletes them from the server.

TODO

  • Create a Ruby gem for the script. Sadly gem-deploy was taken.

git-deploy's People

Contributors

aizatto avatar algimantas avatar djtarazona avatar domtra avatar jaywilliams avatar jcrows avatar lowfear avatar mkubenka avatar pocketarc avatar wprater 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  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  avatar  avatar  avatar  avatar

git-deploy's Issues

It's not creating Directory on server if not exist

Hi,
I tried ./git-deploy and there are few files change between last 2 commits. say..
modules/Email/Email.php
include/javascript/test.js

now on server (i am doing tesing)
/var/www/test/ is an empty folder

and my deploy.yml file has path = /var/www/test/

so when i fire ./git-deploy it says

/var/www/test/
Connecting to www.host.com
Remote Revision: c86ef64d9b996cf445bcb5cc4bb9811a07bf9dde
git diff --name-status c86ef64d9b996cf445bcb5cc4bb9811a07bf9dde..HEAD --
Uploading include/javascript/test.js
/var/lib/gems/1.8/gems/net-sftp-2.0.5/lib/net/sftp/operations/upload.rb:313:in on_open': Net::SFTP::StatusException open /var/www/test//include/javascript/test.js (2, "no such file") (Net::SFTP::StatusException) from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:into_proc'
from /var/lib/gems/1.8/gems/net-sftp-2.0.5/lib/net/sftp/request.rb:87:in call' from /var/lib/gems/1.8/gems/net-sftp-2.0.5/lib/net/sftp/request.rb:87:inrespond_to'
from /var/lib/gems/1.8/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:948:in dispatch_request' from /var/lib/gems/1.8/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:911:inwhen_channel_polled'
from /usr/lib/ruby/vendor_ruby/1.8/rubygems/custom_require.rb:36:in to_proc' from /var/lib/gems/1.8/gems/net-ssh-2.5.2/lib/net/ssh/connection/channel.rb:311:incall'

seems like it is not creating directories if it does not exist, if i do create blank dir then it works fine.

Problems using git-deploy on Ubuntu

Since im not really familliar with Ruby, im not sure if this is an issue with git-deploy, but maybe.

On pretty much fresh Ubuntu 10.04 installation, after
" sudo gem install net-ssh net-sftp net-scp "

git-deploy throws something like this:

psztucz@hp:$ ./git-deploy
/usr/lib/ruby/1.8/net/sftp.rb:43: undefined method register_service' for Net::SSH:Module (NoMethodError) from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:ingem_original_require'
from /usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in `require'
from ./git-deploy:13

Am i missing some lib? Or is it some weird Ruby issue?

FTP upload hangs and order of u/l haphasard

Hello, great tool! But have two issues with it, first is that it hangs and doesn't time-out, it simply stops working after a while and I have to stop the process and start it again...

Second issue is that the script seems to add files in one directory, then go to another one, then back to the previous one; resulting in a lot more FTP commands to switch to the necessary directories than if it just added all files in a particular directory and then moved on to the next one... not sure why that is happening for me.

If these two issues could be addressed I think you'd have a very powerful tool here.

Thanks again for all your good work!

Cannot use alternate syntax in deploy.yml

The docs state that you can use an alternative syntax to define the target FTP server and its configuration:

'example':
  skip: false
  scheme: ftp
  user: example
  password: password
  host: example.com
  port: 21
  path: /path/to/installation

However, at line 100 in your code you have

uri = URI.parse(uri)

and then later

options['path']     = uri.path     if uri.path

It seems that the URI.parse() method parses the 'example' as path, which is why when trying to connect the FTP, I get this error:

put: CWD /example
get: 550 Can't change directory to /example: No such file or directory

Since the uri.path seems to be defined (as parsed), then this line

ftp.chdir(options['path'].empty? ? options['chdir'] : '/' + options['path'])

tries to change the working directory to 'example' instead of the '/path/to/installation' path.

Am I missing something?

undefined local variable or method `settings'

I get the following error when trying to run the code with the same revision on server and local repository, with the option 'ignore_if_same_revision' set to 'true':

../git-deploy/bin/git-deploy:119:in `diff_committed': undefined local variable or method `settings' for #<Git::FTP:0xb7a5b664> (NameError)
    from ../git-deploy/bin/git-deploy:111:in `diff'
    from ../git-deploy/bin/git-deploy:94:in `automate'
    from ../git-deploy/bin/git-deploy:336
    from ../git-deploy/bin/git-deploy:291:in `each'
    from ../git-deploy/bin/git-deploy:291

The error occurs at line 119 in git-deploy:
if settings['ignore_if_same_revision']

The problem seems to be that 'settings' is not defined in this scope. I realized though that you actually merge 'settings' into 'options', which seems to be defined globally. This happens on line 305 here:
options.merge!(settings)

So a quick fix is to simply use 'options' instead of 'settings' in line 119 like this:
if @options['ignore_if_same_revision']

This fixed the problem for me. That said I'm no Ruby developer, so maybe I missed something.

Error with '@' char

Upload is failing when there is a @ in the file name (responsive @2x images) or in the password.
If needed, I'm on a Win7 64, with Ruby 2.0.0p353

Please fix that! 👍

Deploy fails on Git submodules

For example (app/components/DataGrid is a Git submodule):

put: STOR app/components/DataGrid
get: 150 Ok to send data.
/usr/lib/ruby/1.8/net/ftp.rb:454:in `read': Is a directory - app/components/DataGrid (Errno::EISDIR)
        from /usr/lib/ruby/1.8/net/ftp.rb:454:in `storbinary'
        from /usr/lib/ruby/1.8/net/ftp.rb:453:in `loop'
        from /usr/lib/ruby/1.8/net/ftp.rb:453:in `storbinary'
        from /usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
        from /usr/lib/ruby/1.8/net/ftp.rb:450:in `storbinary'
        from /usr/lib/ruby/1.8/net/ftp.rb:562:in `putbinaryfile'
        from /usr/lib/ruby/1.8/net/ftp.rb:591:in `put'
        from /home/gapon/bin/git-deploy:440:in `put'
        from /home/gapon/bin/git-deploy:230:in `upload'
        from /home/gapon/bin/git-deploy:216:in `each'
        from /home/gapon/bin/git-deploy:216:in `upload'
        from /home/gapon/bin/git-deploy:141:in `automate'
        from /home/gapon/bin/git-deploy:568
        from /home/gapon/bin/git-deploy:519:in `each'
        from /home/gapon/bin/git-deploy:519

Undefined method 'list' ?

after lots of struggling with the deploy.yml I'm now getting this: /usr/local/bin/git-deploy:285:in dir_empty?': undefined methodlist' for nil:NilClass (NoMethodError)

Regular FTP is working though (:

I can't delete files, causes error

If I delete a file locally, commit it, git deploy it, I get the following errors, and it doesn't remove it from my server.

Deleting index.html
c:/Ruby193/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:846:in `wait_for': Net::SFTP::StatusException (2, "no such file") (Net::SFTP::StatusException)
        from c:/Ruby193/lib/ruby/gems/1.9.1/gems/net-sftp-2.0.5/lib/net/sftp/session.rb:475:in `remove!'
        from c:/Ruby193/bin/git-deploy:254:in `delete'
        from c:/Ruby193/bin/git-deploy:210:in `block in upload'
        from c:/Ruby193/bin/git-deploy:193:in `each'
        from c:/Ruby193/bin/git-deploy:193:in `upload'
        from c:/Ruby193/bin/git-deploy:125:in `automate'
        from c:/Ruby193/bin/git-deploy:529:in `block in <main>'
        from c:/Ruby193/bin/git-deploy:484:in `each'
        from c:/Ruby193/bin/git-deploy:484:in `<main>'

put: CWD /localhost should not be invoked

First - I have tested everything via lftp, no error, everything works.

Steps:

  • My config file deploy-localhost.yml (just for testing purposes) looks like:
'localhost':
  debug_mode: true
  skip: false
  scheme: ftp
  user: anonymous
  password: [email protected]
  host: localhost
  port: 21
  path: /pub/nette-skeleton
  passive: true
  • After running git-deploy deploy-localhost, I get:
localhost
Connecting to localhost
connect: localhost, 21
get: 220 Welcome to cattie only FTP service.
put: USER anonymous
get: 331 Please specify the password.
put: PASS *************
get: 230 Login successful.
put: CWD /localhost
get: 550 Failed to change directory.

I guess put: CWD /localhost is the culprit of the failure - is it a bug or have I anything incorrect in my config file?

Thanks.
PS: BTW if one makes a typo in scheme, exception is thrown instead of some user-friendly error.

subdirectories are not ignored

hello,
i really like this way to deploy, it saves me so much time.
but i try to ignore some subfolders but it doesn't work.

this is my .gitignore

themes
wp-admin
wp-includes
wp-content/*
!wp-content/themes

.gitignore
.svn

themes, wp-includes are ignored, the rest dosn't work.
can someone help me with this?

thanks

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.