Sha256: 99c9c8d5fa17fc7990533a46ef9c6a7f34d90ba3889566ae702f56c26a2d911a

Contents?: true

Size: 1.85 KB

Versions: 15

Compression:

Stored size: 1.85 KB

Contents

# encoding: utf-8

module Nanoc::Extra::Deployers

  # A deployer that deploys a site using rsync.
  #
  # The configuration has should include a `:dst` value, a string containing
  # the destination to where rsync should upload its data. It will likely be
  # in `host:path` format. It should not end with a slash. For example,
  # `"example.com:/var/www/sites/mysite/html"`.
  #
  # @example A deployment configuration with public and staging configurations
  #
  #   deploy:
  #     public:
  #       kind: rsync
  #       dst: "ectype:sites/stoneship/public"
  #     staging:
  #       kind: rsync
  #       dst: "ectype:sites/stoneship-staging/public"
  #       options: [ "-glpPrtvz" ]
  class Rsync < ::Nanoc::Extra::Deployer

    # Default rsync options
    DEFAULT_OPTIONS = [
      '-glpPrtvz',
      '--exclude=".hg"',
      '--exclude=".svn"',
      '--exclude=".git"'
    ]

    # @see Nanoc::Extra::Deployer#run
    def run
      require 'systemu'

      # Get params
      src = self.source_path + '/'
      dst = self.config[:dst]
      options = self.config[:options] || DEFAULT_OPTIONS

      # Validate
      raise 'No dst found in deployment configuration' if dst.nil?
      raise 'dst requires no trailing slash' if dst[-1,1] == '/'

      # Run
      if dry_run
        warn 'Performing a dry-run; no actions will actually be performed'
        run_shell_cmd([ 'echo', 'rsync', options, src, dst ].flatten)
      else
        run_shell_cmd([ 'rsync', options, src, dst ].flatten)
      end
    end

  private

    # Runs the given shell command. It will raise an error if execution fails 
    # (results in a nonzero exit code).
    def run_shell_cmd(args)
      status = systemu(args, 'stdout' => $stdout, 'stderr' => $stderr)
      raise "command exited with a nonzero status code #{$?.exitstatus} (command: #{args.join(' ')})" if !status.success?
    end

  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
nanoc-3.6.7 lib/nanoc/extra/deployers/rsync.rb
nanoc-3.6.6 lib/nanoc/extra/deployers/rsync.rb
nanoc-3.6.5 lib/nanoc/extra/deployers/rsync.rb
nanoc-3.6.4 lib/nanoc/extra/deployers/rsync.rb
nanoc-3.6.3 lib/nanoc/extra/deployers/rsync.rb
nanoc-3.6.2 lib/nanoc/extra/deployers/rsync.rb
nanoc-3.6.1 lib/nanoc/extra/deployers/rsync.rb
nanoc-3.6.0 lib/nanoc/extra/deployers/rsync.rb
nanoc-3.5.0 lib/nanoc/extra/deployers/rsync.rb
nanoc-3.5.0b2 lib/nanoc/extra/deployers/rsync.rb
nanoc-3.5.0b1 lib/nanoc/extra/deployers/rsync.rb
nanoc-3.4.3 lib/nanoc/extra/deployers/rsync.rb
nanoc-3.4.2 lib/nanoc/extra/deployers/rsync.rb
nanoc-3.4.1 lib/nanoc/extra/deployers/rsync.rb
nanoc-3.4.0 lib/nanoc/extra/deployers/rsync.rb