From 92e7724a1aa7d057a01f2203ea88e3526e11ad46 Mon Sep 17 00:00:00 2001 From: John Manoogian III Date: Mon, 6 May 2013 16:39:19 -0700 Subject: [PATCH 1/4] (optionally) force a build before any deploy --- lib/middleman-deploy/commands.rb | 1 + lib/middleman-deploy/extension.rb | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/middleman-deploy/commands.rb b/lib/middleman-deploy/commands.rb index 5acf3dd..6ef5841 100644 --- a/lib/middleman-deploy/commands.rb +++ b/lib/middleman-deploy/commands.rb @@ -28,6 +28,7 @@ module Middleman :aliases => "-c", :desc => "Remove orphaned files or directories on the remote host" def deploy + Middleman::Cli::Build.new.build if self.deploy_options.force_build send("deploy_#{self.deploy_options.method}") end diff --git a/lib/middleman-deploy/extension.rb b/lib/middleman-deploy/extension.rb index 53613bd..8a049a7 100644 --- a/lib/middleman-deploy/extension.rb +++ b/lib/middleman-deploy/extension.rb @@ -5,7 +5,7 @@ require "middleman-core" module Middleman module Deploy - class Options < Struct.new(:whatisthis, :method, :host, :port, :user, :password, :path, :clean, :remote, :branch, :after_build); end + class Options < Struct.new(:whatisthis, :method, :host, :port, :user, :password, :path, :clean, :remote, :branch, :after_build, :force_build); end class << self @@ -23,6 +23,7 @@ module Middleman options.branch ||= "gh-pages" options.after_build ||= false + options.force_build ||= false app.after_build do |builder| ::Middleman::Cli::Deploy.new.deploy if options.after_build From e854adb5a6d715cbf5a5746682fb2b17f76bfe8a Mon Sep 17 00:00:00 2001 From: Ryan McGeary Date: Thu, 30 May 2013 10:25:03 -0400 Subject: [PATCH 2/4] Fixed branch selection logic for git deploys * Before, because the logic was revered (see c0e46393c656eac6e47a83f54041457e3c6a6923), a brand new deploy would result in assuming that the deploy branch existed when it actually did not. This would cause initial deploys to fail. * This new logic is more concise, more readable, and still backwards compatible with ruby 1.8. --- lib/middleman-deploy/commands.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/middleman-deploy/commands.rb b/lib/middleman-deploy/commands.rb index 17f07b6..460d86e 100644 --- a/lib/middleman-deploy/commands.rb +++ b/lib/middleman-deploy/commands.rb @@ -158,7 +158,7 @@ EOF end #if there is a branch with that name, switch to it, otherwise create a new one and switch to it - if `git branch`.split("\n").delete_if{ |r| r =~ Regexp.new(branch,true) }.count == 0 + if `git branch`.split("\n").any? { |b| b =~ /#{branch}/i } `git checkout #{branch}` else `git checkout -b #{branch}` From f474cbd298b3f4a5aca06c3d24c50821e7faab41 Mon Sep 17 00:00:00 2001 From: Ryan McGeary Date: Thu, 30 May 2013 19:19:42 -0400 Subject: [PATCH 3/4] Added license declaration to gemspec --- middleman-deploy.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/middleman-deploy.gemspec b/middleman-deploy.gemspec index 92eeea2..dc23293 100644 --- a/middleman-deploy.gemspec +++ b/middleman-deploy.gemspec @@ -11,6 +11,7 @@ Gem::Specification.new do |s| s.homepage = "http://tvaughan.github.com/middleman-deploy/" s.summary = %q{Deploy a middleman built site over rsync, ftp, or git (e.g. gh-pages on github).} s.description = %q{Deploy a middleman built site over rsync, ftp, or git (e.g. gh-pages on github).} + s.license = "MIT" s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") From a1ae241553ccce7869cd51b6ac0a66c2bdc63390 Mon Sep 17 00:00:00 2001 From: tobiaswerner Date: Sat, 8 Jun 2013 22:46:43 +0200 Subject: [PATCH 4/4] Added SFTP deployment --- README.md | 16 +++++++++++++ lib/middleman-deploy/commands.rb | 39 ++++++++++++++++++++++++++++++++ middleman-deploy.gemspec | 1 + 3 files changed, 56 insertions(+) diff --git a/README.md b/README.md index 02cbcfe..54e0635 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,22 @@ Edit `config.rb`, and add: Adjust these values accordingly. +## Step 3d - SFTP setup + +**These settings are required.** + +Edit `config.rb`, and add: + + activate :deploy do |deploy| + deploy.method = :sftp + deploy.host = "ftp.example.com" + deploy.user = "tvaughan" + deploy.password = "secret" + deploy.path = "/srv/www/site" + end + +Adjust these values accordingly. + ## Step 4 middleman build [--clean] diff --git a/lib/middleman-deploy/commands.rb b/lib/middleman-deploy/commands.rb index 460d86e..4852f9a 100644 --- a/lib/middleman-deploy/commands.rb +++ b/lib/middleman-deploy/commands.rb @@ -220,6 +220,45 @@ EOF ftp.close end + def deploy_sftp + require 'net/sftp' + require 'ptools' + + host = self.deploy_options.host + user = self.deploy_options.user + pass = self.deploy_options.password + path = self.deploy_options.path + + puts "## Deploying via sftp to #{user}@#{host}:#{path}" + + Net::SFTP.start(host, user, :password => pass) do |sftp| + sftp.mkdir(path) + Dir.chdir(self.inst.build_dir) do + files = Dir.glob('**/*', File::FNM_DOTMATCH) + files.reject { |a| a =~ Regexp.new('\.$') }.each do |f| + if File.directory?(f) + begin + sftp.mkdir("#{path}/#{f}") + puts "Created directory #{f}" + rescue + end + else + begin + sftp.upload(f, "#{path}/#{f}") + rescue Exception => e + reply = e.message + err_code = reply[0,3].to_i + if err_code == 550 + sftp.upload(f, "#{path}/#{f}") + end + end + puts "Copied #{f}" + end + end + end + end + end + end # Alias "d" to "deploy" diff --git a/middleman-deploy.gemspec b/middleman-deploy.gemspec index dc23293..bca343a 100644 --- a/middleman-deploy.gemspec +++ b/middleman-deploy.gemspec @@ -23,4 +23,5 @@ Gem::Specification.new do |s| # Additional dependencies s.add_runtime_dependency("ptools") + s.add_runtime_dependency("net-sftp") end