Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

ST: Added :copy_via variable to :copy strategy in order to :scp or :sftp (default) to the remote machines #115

Merged
merged 1 commit into from Apr 2, 2013
Jump to file or symbol
Failed to load files and symbols.
+30 −1
Split
@@ -39,6 +39,11 @@ module Strategy
# :zip, and which specifies how the source should be compressed for
# transmission to each host.
#
+ # By default, files will be transferred across to the remote machines via 'sftp'. If you prefer
+ # to use 'scp' you can set the :copy_via variable to :scp.
+ #
+ # set :copy_via, :scp
+ #
# There is a possibility to pass a build command that will get
# executed if your code needs to be compiled or something needs to be
# done before the code is ready to run.
@@ -316,7 +321,10 @@ def decompress_remote_file
# Distributes the file to the remote servers
def distribute!
- upload(filename, remote_filename)
+ args = [filename, remote_filename]
+ args << { :via => configuration[:copy_via] } if configuration[:copy_via]
+
+ upload(*args)
decompress_remote_file
end
end
@@ -197,6 +197,27 @@ def test_deploy_with_copy_remote_dir_should_copy_to_that_dir
@strategy.deploy!
end
+ def test_deploy_with_copy_via_should_use_the_given_transfer_method
+ @config[:copy_via] = :scp
+ Dir.expects(:tmpdir).returns("/temp/dir")
+ Dir.expects(:chdir).yields
+ @source.expects(:checkout).returns(:local_checkout)
+
+ @strategy.expects(:system).with(:local_checkout)
+ @strategy.expects(:system).with("tar czf 1234567890.tar.gz 1234567890")
+ @strategy.expects(:upload).with("/temp/dir/1234567890.tar.gz", "/tmp/1234567890.tar.gz", {:via => :scp})
+ @strategy.expects(:run).with("cd /u/apps/test/releases && tar xzf /tmp/1234567890.tar.gz && rm /tmp/1234567890.tar.gz")
+
+ mock_file = mock("file")
+ mock_file.expects(:puts).with("154")
+ File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file)
+
+ FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz")
+ FileUtils.expects(:rm_rf).with("/temp/dir/1234567890")
+
+ @strategy.deploy!
+ end
+
def test_with_copy_cache_should_checkout_to_cache_if_cache_does_not_exist_and_then_copy
@config[:copy_cache] = true