Merge pull request #28 from tobiaswerner/master

Add SFTP deployment
This commit is contained in:
Tom Vaughan 2013-06-08 16:15:31 -07:00
commit 04fccda46b
3 changed files with 56 additions and 0 deletions

View file

@ -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]

View file

@ -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"

View file

@ -23,4 +23,5 @@ Gem::Specification.new do |s|
# Additional dependencies
s.add_runtime_dependency("ptools")
s.add_runtime_dependency("net-sftp")
end