├── .gitignore ├── flipflops.gemspec ├── README.md └── lib └── flipflops.rb /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *~ 3 | -------------------------------------------------------------------------------- /flipflops.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |s| 2 | s.name = 'flipflops' 3 | s.version = '0.1.0' 4 | s.date = '2012-12-12' 5 | s.summary = "FlipFlops" 6 | s.description = "A simple server deployment tool" 7 | s.authors = ["Sankha Narayan Guria"] 8 | s.email = 'sankha93@gmail.com' 9 | s.files = ["lib/flipflops.rb"] 10 | s.homepage = 'https://github.com/sankha93/flipflops' 11 | end -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FlipFlops 2 | 3 | Just wear it and you are good to go! Erm, just kidding! Its a simple server deployment tool. 4 | 5 | ## Ok, how do I install? 6 | 7 | Its a Ruby gem, so just get it by 8 | 9 | gem install flipflops 10 | 11 | ## Hey, how do I use it? 12 | 13 | Its pretty simple to use as well. It works with git repos currently. Just create a Ruby script like: 14 | 15 | ``` 16 | require 'flipflops' 17 | s = FlipFlops.new 18 | s.login('host', 'username', 'password') # SSH login to the server 19 | .set_repo('https://github.com/username/repo.git') # Set the master repo to deploy from 20 | .exec_script('mysqld stop') # or whatever pre-deployment commands you would like to execute 21 | .set_path('public') # change directory 22 | .clone_repo # clone the master repository 23 | .exec_script('mysqld start') 24 | .close # close the connection 25 | 26 | ``` 27 | 28 | ## Lets make it better? 29 | 30 | Sure, I would love you to! File an issue if you find a bug, or have a feature request. Forks and pulls awesome too! -------------------------------------------------------------------------------- /lib/flipflops.rb: -------------------------------------------------------------------------------- 1 | require 'net/ssh' 2 | 3 | class FlipFlops 4 | 5 | @loggedin = false 6 | 7 | def set_repo(repo) 8 | @repo = repo 9 | self 10 | end 11 | 12 | def login(host, username, password, port = 22) 13 | puts "=== Logging in to " + host + " ===" 14 | begin 15 | @ssh = Net::SSH.start(host, username, {:password => password, :port => port}) 16 | @loggedin = true 17 | rescue Timeout::Error 18 | puts "Slippers.login: Connection timed out." 19 | rescue Errno::EHOSTUNREACH 20 | puts "Slippers.login: Host unreachable." 21 | rescue Errno::ECONNREFUSED 22 | puts "Slippers.login: Host refused connection." 23 | rescue Net::SSH::AuthenticationFailed 24 | puts "Slippers.login: Authentication failed. Check your username/password combination." 25 | end 26 | self 27 | end 28 | 29 | def set_path(path) 30 | puts "=== Changing directory to " + path + " ===" 31 | if @loggedin 32 | output = @ssh.exec!("cd " + path) 33 | puts output 34 | else 35 | puts "Slippers.set_path: No establised SSH connection found." 36 | end 37 | self 38 | end 39 | 40 | def update_repo 41 | puts "=== Updating the repo " + @repo + " ===" 42 | if @loggedin 43 | output = @ssh.exec!("git pull " + @repo) 44 | puts output 45 | else 46 | puts "Slippers.update_repo: No establised SSH connection found." 47 | end 48 | self 49 | end 50 | 51 | def clone_repo 52 | puts "=== Cloning the repo " + @repo + " ===" 53 | if @loggedin 54 | output = @ssh.exec!("git clone " + @repo) 55 | puts output 56 | else 57 | puts "Slippers.update_repo: No establised SSH connection found." 58 | end 59 | self 60 | end 61 | 62 | def exec_script(script) 63 | if @loggedin 64 | output = @ssh.exec!(script) 65 | puts output 66 | else 67 | puts "Slippers.exec_script: No establised SSH connection found." 68 | end 69 | self 70 | end 71 | 72 | def close 73 | if @loggedin 74 | puts "=== Closing connection ===" 75 | @ssh.close 76 | else 77 | puts "Slippers.close: No establised SSH connection found." 78 | end 79 | self 80 | end 81 | end --------------------------------------------------------------------------------