Fixing compatibility issues with middleman v4.0.0.beta.1
This commit is contained in:
parent
000cabda96
commit
9eece01aef
|
@ -6,3 +6,11 @@ master
|
||||||
|
|
||||||
* Respect user details of git repo. #70
|
* Respect user details of git repo. #70
|
||||||
* Prevent bad commits deploying. (git) #77
|
* Prevent bad commits deploying. (git) #77
|
||||||
|
|
||||||
|
development
|
||||||
|
===
|
||||||
|
|
||||||
|
2.0.0
|
||||||
|
===
|
||||||
|
|
||||||
|
* Fixing compatibility issues with middleman v4.0.0.beta.1
|
||||||
|
|
38
README.md
38
README.md
|
@ -26,9 +26,9 @@ following to `config.rb`:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
activate :deploy do |deploy|
|
activate :deploy do |deploy|
|
||||||
deploy.method = :rsync
|
deploy.deploy_method = :rsync
|
||||||
deploy.host = 'www.example.com'
|
deploy.host = 'www.example.com'
|
||||||
deploy.path = '/srv/www/site'
|
deploy.path = '/srv/www/site'
|
||||||
# Optional Settings
|
# Optional Settings
|
||||||
# deploy.user = 'tvaughan' # no default
|
# deploy.user = 'tvaughan' # no default
|
||||||
# deploy.port = 5309 # ssh port, default: 22
|
# deploy.port = 5309 # ssh port, default: 22
|
||||||
|
@ -44,7 +44,7 @@ following to `config.rb`:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
activate :deploy do |deploy|
|
activate :deploy do |deploy|
|
||||||
deploy.method = :git
|
deploy.deploy_method = :git
|
||||||
# Optional Settings
|
# Optional Settings
|
||||||
# deploy.remote = 'custom-remote' # remote name or git url, default: origin
|
# deploy.remote = 'custom-remote' # remote name or git url, default: origin
|
||||||
# deploy.branch = 'custom-branch' # default: gh-pages
|
# deploy.branch = 'custom-branch' # default: gh-pages
|
||||||
|
@ -70,11 +70,11 @@ Activate the extension by adding the following to `config.rb`:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
activate :deploy do |deploy|
|
activate :deploy do |deploy|
|
||||||
deploy.method = :ftp
|
deploy.deploy_method = :ftp
|
||||||
deploy.host = 'ftp.example.com'
|
deploy.host = 'ftp.example.com'
|
||||||
deploy.path = '/srv/www/site'
|
deploy.path = '/srv/www/site'
|
||||||
deploy.user = 'tvaughan'
|
deploy.user = 'tvaughan'
|
||||||
deploy.password = 'secret'
|
deploy.password = 'secret'
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -84,10 +84,10 @@ Activate the extension by adding the following to `config.rb`:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
activate :deploy do |deploy|
|
activate :deploy do |deploy|
|
||||||
deploy.method = :sftp
|
deploy.deploy_method = :sftp
|
||||||
deploy.host = 'sftp.example.com'
|
deploy.host = 'sftp.example.com'
|
||||||
deploy.port = 22
|
deploy.port = 22
|
||||||
deploy.path = '/srv/www/site'
|
deploy.path = '/srv/www/site'
|
||||||
# Optional Settings
|
# Optional Settings
|
||||||
# deploy.user = 'tvaughan' # no default
|
# deploy.user = 'tvaughan' # no default
|
||||||
# deploy.password = 'secret' # no default
|
# deploy.password = 'secret' # no default
|
||||||
|
@ -115,15 +115,15 @@ Deploy your site to more than one configuration using environment variables.
|
||||||
case ENV['TARGET'].to_s.downcase
|
case ENV['TARGET'].to_s.downcase
|
||||||
when 'production'
|
when 'production'
|
||||||
activate :deploy do |deploy|
|
activate :deploy do |deploy|
|
||||||
deploy.method = :rsync
|
deploy.deploy_method = :rsync
|
||||||
deploy.host = 'www.example.com'
|
deploy.host = 'www.example.com'
|
||||||
deploy.path = '/srv/www/production-site'
|
deploy.path = '/srv/www/production-site'
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
activate :deploy do |deploy|
|
activate :deploy do |deploy|
|
||||||
deploy.method = :rsync
|
deploy.deploy_method = :rsync
|
||||||
deploy.host = 'staging.example.com'
|
deploy.host = 'staging.example.com'
|
||||||
deploy.path = '/srv/www/staging-site'
|
deploy.path = '/srv/www/staging-site'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
|
@ -4,5 +4,5 @@ require 'middleman-deploy/commands'
|
||||||
|
|
||||||
::Middleman::Extensions.register(:deploy) do
|
::Middleman::Extensions.register(:deploy) do
|
||||||
require 'middleman-deploy/extension'
|
require 'middleman-deploy/extension'
|
||||||
::Middleman::Deploy
|
::Middleman::Deploy::Extension
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,24 +8,53 @@ require 'middleman-deploy/strategies'
|
||||||
module Middleman
|
module Middleman
|
||||||
module Cli
|
module Cli
|
||||||
# This class provides a "deploy" command for the middleman CLI.
|
# This class provides a "deploy" command for the middleman CLI.
|
||||||
class Deploy < Thor
|
class Deploy < Thor::Group
|
||||||
include Thor::Actions
|
include Thor::Actions
|
||||||
|
|
||||||
check_unknown_options!
|
check_unknown_options!
|
||||||
|
|
||||||
namespace :deploy
|
namespace :deploy
|
||||||
|
|
||||||
|
class_option :environment,
|
||||||
|
aliases: '-e',
|
||||||
|
default: ENV['MM_ENV'] || ENV['RACK_ENV'] || 'production',
|
||||||
|
desc: 'The environment Middleman will run under'
|
||||||
|
|
||||||
|
class_option :verbose,
|
||||||
|
type: :boolean,
|
||||||
|
default: false,
|
||||||
|
desc: 'Print debug messages'
|
||||||
|
|
||||||
|
class_option :instrument,
|
||||||
|
type: :string,
|
||||||
|
default: false,
|
||||||
|
desc: 'Print instrument messages'
|
||||||
|
|
||||||
|
class_option :build_before,
|
||||||
|
type: :boolean,
|
||||||
|
aliases: '-b',
|
||||||
|
desc: 'Run `middleman build` before the deploy step'
|
||||||
|
|
||||||
|
def self.subcommand_help options
|
||||||
|
# TODO
|
||||||
|
end
|
||||||
|
|
||||||
# Tell Thor to exit with a nonzero exit code on failure
|
# Tell Thor to exit with a nonzero exit code on failure
|
||||||
def self.exit_on_failure?
|
def self.exit_on_failure?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'deploy [options]', Middleman::Deploy::TAGLINE
|
|
||||||
method_option 'build_before',
|
|
||||||
type: :boolean,
|
|
||||||
aliases: '-b',
|
|
||||||
desc: 'Run `middleman build` before the deploy step'
|
|
||||||
def deploy
|
def deploy
|
||||||
|
env = options['environment'] ? :production : options['environment'].to_s.to_sym
|
||||||
|
verbose = options['verbose'] ? 0 : 1
|
||||||
|
instrument = options['instrument']
|
||||||
|
|
||||||
|
@app = ::Middleman::Application.new do
|
||||||
|
config[:mode] = :build
|
||||||
|
config[:environment] = env
|
||||||
|
::Middleman::Logger.singleton(verbose, instrument)
|
||||||
|
end
|
||||||
build_before(options)
|
build_before(options)
|
||||||
process
|
process
|
||||||
end
|
end
|
||||||
|
@ -37,18 +66,19 @@ module Middleman
|
||||||
|
|
||||||
if build_enabled
|
if build_enabled
|
||||||
# http://forum.middlemanapp.com/t/problem-with-the-build-task-in-an-extension
|
# http://forum.middlemanapp.com/t/problem-with-the-build-task-in-an-extension
|
||||||
run('middleman build') || exit(1)
|
run("middleman build -e #{options['environment']}") || exit(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def print_usage_and_die(message)
|
def print_usage_and_die(message)
|
||||||
raise Error, "ERROR: #{message}\n#{Middleman::Deploy::README}"
|
raise StandardError, "ERROR: #{message}\n#{Middleman::Deploy::README}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def process
|
|
||||||
server_instance = ::Middleman::Application.server.inst
|
|
||||||
|
|
||||||
camelized_method = self.deploy_options.method.to_s.split('_').map { |word| word.capitalize}.join
|
|
||||||
|
def process
|
||||||
|
server_instance = @app
|
||||||
|
camelized_method = self.deploy_options.deploy_method.to_s.split('_').map { |word| word.capitalize}.join
|
||||||
method_class_name = "Middleman::Deploy::Methods::#{camelized_method}"
|
method_class_name = "Middleman::Deploy::Methods::#{camelized_method}"
|
||||||
method_instance = method_class_name.constantize.new(server_instance, self.deploy_options)
|
method_instance = method_class_name.constantize.new(server_instance, self.deploy_options)
|
||||||
|
|
||||||
|
@ -59,19 +89,19 @@ module Middleman
|
||||||
options = nil
|
options = nil
|
||||||
|
|
||||||
begin
|
begin
|
||||||
options = ::Middleman::Application.server.inst.options
|
options = ::Middleman::Deploy.options
|
||||||
rescue NoMethodError
|
rescue NoMethodError
|
||||||
print_usage_and_die 'You need to activate the deploy extension in config.rb.'
|
print_usage_and_die 'You need to activate the deploy extension in config.rb.'
|
||||||
end
|
end
|
||||||
|
|
||||||
unless options.method
|
unless options.deploy_method
|
||||||
print_usage_and_die 'The deploy extension requires you to set a method.'
|
print_usage_and_die 'The deploy extension requires you to set a method.'
|
||||||
end
|
end
|
||||||
|
|
||||||
case options.method
|
case options.deploy_method
|
||||||
when :rsync, :sftp
|
when :rsync, :sftp
|
||||||
unless options.host && options.path
|
unless options.host && options.path
|
||||||
print_usage_and_die "The #{options.method} method requires host and path to be set."
|
print_usage_and_die "The #{options.deploy_method} method requires host and path to be set."
|
||||||
end
|
end
|
||||||
when :ftp
|
when :ftp
|
||||||
unless options.host && options.user && options.password && options.path
|
unless options.host && options.user && options.password && options.path
|
||||||
|
@ -83,6 +113,9 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Add to CLI
|
||||||
|
Base.register(Middleman::Cli::Deploy, 'deploy', 'deploy [options]', Middleman::Deploy::TAGLINE)
|
||||||
|
|
||||||
# Alias "d" to "deploy"
|
# Alias "d" to "deploy"
|
||||||
Base.map('d' => 'deploy')
|
Base.map('d' => 'deploy')
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,15 +4,30 @@ require 'middleman-core'
|
||||||
# Extension namespace
|
# Extension namespace
|
||||||
module Middleman
|
module Middleman
|
||||||
module Deploy
|
module Deploy
|
||||||
class Options < Struct.new(:method, :host, :port, :user, :password, :path, :clean, :remote, :branch, :strategy, :build_before, :flags, :commit_message); end
|
|
||||||
|
|
||||||
class << self
|
cattr_accessor :options
|
||||||
def options
|
|
||||||
@@options
|
class Extension < Extension
|
||||||
end
|
|
||||||
|
option :deploy_method, nil
|
||||||
|
option :host, nil
|
||||||
|
option :port, nil
|
||||||
|
option :user, nil
|
||||||
|
option :password, nil
|
||||||
|
option :path, nil
|
||||||
|
option :clean, nil
|
||||||
|
option :remote, nil
|
||||||
|
option :branch, nil
|
||||||
|
option :strategy, nil
|
||||||
|
option :build_before, nil
|
||||||
|
option :flags, nil
|
||||||
|
option :commit_message, nil
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def initialize(app, options_hash = {}, &block)
|
||||||
|
super
|
||||||
|
|
||||||
def registered(app, options_hash = {}, &block)
|
|
||||||
options = Options.new(options_hash)
|
|
||||||
yield options if block_given?
|
yield options if block_given?
|
||||||
|
|
||||||
# Default options for the rsync method.
|
# Default options for the rsync method.
|
||||||
|
@ -27,18 +42,13 @@ module Middleman
|
||||||
|
|
||||||
options.build_before ||= false
|
options.build_before ||= false
|
||||||
|
|
||||||
@@options = options
|
|
||||||
|
|
||||||
app.send :include, Helpers
|
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_method :included, :registered
|
def after_configuration
|
||||||
|
::Middleman::Deploy.options = options
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module Helpers
|
|
||||||
def options
|
|
||||||
::Middleman::Deploy.options
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,6 +9,10 @@ module Middleman
|
||||||
@server_instance = server_instance
|
@server_instance = server_instance
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def build_dir
|
||||||
|
self.server_instance.config.setting(:build_dir).value
|
||||||
|
end
|
||||||
|
|
||||||
def process
|
def process
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,7 +22,7 @@ module Middleman
|
||||||
|
|
||||||
ftp = open_connection
|
ftp = open_connection
|
||||||
|
|
||||||
Dir.chdir(self.server_instance.build_dir) do
|
Dir.chdir(self.build_dir) do
|
||||||
filtered_files.each do |filename|
|
filtered_files.each do |filename|
|
||||||
if File.directory?(filename)
|
if File.directory?(filename)
|
||||||
upload_directory(ftp, filename)
|
upload_directory(ftp, filename)
|
||||||
|
|
|
@ -7,7 +7,7 @@ module Middleman
|
||||||
|
|
||||||
camelized_strategy = self.options.strategy.to_s.split('_').map { |word| word.capitalize}.join
|
camelized_strategy = self.options.strategy.to_s.split('_').map { |word| word.capitalize}.join
|
||||||
strategy_class_name = "Middleman::Deploy::Strategies::Git::#{camelized_strategy}"
|
strategy_class_name = "Middleman::Deploy::Strategies::Git::#{camelized_strategy}"
|
||||||
strategy_instance = strategy_class_name.constantize.new(self.server_instance.build_dir, self.options.remote, self.options.branch, self.options.commit_message)
|
strategy_instance = strategy_class_name.constantize.new(self.build_dir, self.options.remote, self.options.branch, self.options.commit_message)
|
||||||
|
|
||||||
strategy_instance.process
|
strategy_instance.process
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,7 +21,7 @@ module Middleman
|
||||||
|
|
||||||
dest_url = "#{user}#{self.host}:#{self.path}"
|
dest_url = "#{user}#{self.host}:#{self.path}"
|
||||||
flags = self.flags || '-avz'
|
flags = self.flags || '-avz'
|
||||||
command = "rsync #{flags} '-e ssh -p #{self.port}' #{self.server_instance.build_dir}/ #{dest_url}"
|
command = "rsync #{flags} '-e ssh -p #{self.port}' #{self.build_dir}/ #{dest_url}"
|
||||||
|
|
||||||
if self.clean
|
if self.clean
|
||||||
command += ' --delete'
|
command += ' --delete'
|
||||||
|
|
|
@ -12,7 +12,7 @@ module Middleman
|
||||||
Net::SFTP.start(self.host, self.user, password: self.pass, port: self.port) do |sftp|
|
Net::SFTP.start(self.host, self.user, password: self.pass, port: self.port) do |sftp|
|
||||||
sftp.mkdir(self.path)
|
sftp.mkdir(self.path)
|
||||||
|
|
||||||
Dir.chdir(self.server_instance.build_dir) do
|
Dir.chdir(self.build_dir) do
|
||||||
filtered_files.each do |filename|
|
filtered_files.each do |filename|
|
||||||
if File.directory?(filename)
|
if File.directory?(filename)
|
||||||
upload_directory(sftp, filename)
|
upload_directory(sftp, filename)
|
||||||
|
|
Loading…
Reference in a new issue