diff --git a/CHANGELOG b/CHANGELOG index a4a697763..e458ab343 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,10 @@ *SVN* +* Make the copy strategy check out to a temporary directory [Jamis Buck] + + +*1.99.0 (2.0 Preview 1)* April 24, 2007 + * Add `capify' script to make it easier to prepare a project for deployment using cap [Jamis Buck] * Make sure the sudo helper understands the SuSE dialect of the sudo password prompt [Steven Wisener] @@ -18,6 +23,7 @@ * Merged the Configuration and Actor classes, performed various other massive refactorings of the code [Jamis Buck] + *1.4.1* (February 24, 2007) * Use the no-auth-cache option with subversion so that username/password tokens do not get cached by capistrano usage [jonathan] diff --git a/Rakefile b/Rakefile index add75eb0d..afe2bc1f3 100644 --- a/Rakefile +++ b/Rakefile @@ -50,8 +50,8 @@ end desc "Publish the beta gem" task :pgem => [:package] do - Rake::SshFilePublisher.new("davidhh@wrath.rubyonrails.org", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload - `ssh davidhh@wrath.rubyonrails.org './gemupdate.sh'` + Rake::SshFilePublisher.new("wrath.rubyonrails.org", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload + `ssh wrath.rubyonrails.org './gemupdate.sh'` end desc "Clean up generated directories and files" @@ -59,4 +59,4 @@ task :clean do rm_rf "pkg" rm_rf "doc" rm_rf "coverage" -end \ No newline at end of file +end diff --git a/lib/capistrano/recipes/deploy/strategy/copy.rb b/lib/capistrano/recipes/deploy/strategy/copy.rb index 251ee9f74..026256ab5 100644 --- a/lib/capistrano/recipes/deploy/strategy/copy.rb +++ b/lib/capistrano/recipes/deploy/strategy/copy.rb @@ -1,5 +1,6 @@ require 'capistrano/recipes/deploy/strategy/base' require 'fileutils' +require 'tempfile' # Dir.tmpdir module Capistrano module Deploy @@ -51,7 +52,7 @@ def check! # Returns the basename of the release_path, which will be used to # name the local copy and archive file. def destination - @destination ||= File.basename(configuration[:release_path]) + @destination ||= File.join(tmpdir, File.basename(configuration[:release_path])) end # Returns the value of the :copy_strategy variable, defaulting to @@ -74,13 +75,18 @@ def command # Returns the name of the file that the source code will be # compressed to. def filename - @filename ||= "#{destination}.#{compression_extension}" + @filename ||= File.join(tmpdir, "#{File.basename(destination)}.#{compression_extension}") + end + + # The directory to which the copy should be checked out + def tmpdir + @tmpdir ||= configuration[:copy_dir] || Dir.tmpdir end # The location on the remote server where the file should be # temporarily stored. def remote_filename - @remote_filename ||= "/tmp/#{filename}" + @remote_filename ||= "/tmp/#{File.basename(filename)}" end # The compression method to use, defaults to :gzip. diff --git a/test/deploy/strategy/copy_test.rb b/test/deploy/strategy/copy_test.rb new file mode 100644 index 000000000..ce9cf14b5 --- /dev/null +++ b/test/deploy/strategy/copy_test.rb @@ -0,0 +1,119 @@ +require "#{File.dirname(__FILE__)}/../../utils" +require 'capistrano/logger' +require 'capistrano/recipes/deploy/strategy/copy' + +class DeployStrategyCopyTest < Test::Unit::TestCase + def setup + @config = { :logger => Capistrano::Logger.new(:output => StringIO.new), + :releases_path => "/u/apps/test/releases", + :release_path => "/u/apps/test/releases/1234567890", + :real_revision => "154" } + @source = mock("source") + @config.stubs(:source).returns(@source) + @strategy = Capistrano::Deploy::Strategy::Copy.new(@config) + end + + def test_deploy_with_defaults_should_use_tar_gz_and_checkout + Dir.expects(:tmpdir).returns("/temp/dir") + @source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout) + + @strategy.expects(:system).with(:local_checkout) + @strategy.expects(:system).with("tar czf /temp/dir/1234567890.tar.gz /temp/dir/1234567890") + @strategy.expects(:put).with(:mock_file_contents, "/tmp/1234567890.tar.gz") + @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) + File.expects(:read).with("/temp/dir/1234567890.tar.gz").returns(:mock_file_contents) + + FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz") + FileUtils.expects(:rm_rf).with("/temp/dir/1234567890") + + @strategy.deploy! + end + + def test_deploy_with_export_should_use_tar_gz_and_export + Dir.expects(:tmpdir).returns("/temp/dir") + @config[:copy_strategy] = :export + @source.expects(:export).with("154", "/temp/dir/1234567890").returns(:local_export) + + @strategy.expects(:system).with(:local_export) + @strategy.expects(:system).with("tar czf /temp/dir/1234567890.tar.gz /temp/dir/1234567890") + @strategy.expects(:put).with(:mock_file_contents, "/tmp/1234567890.tar.gz") + @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) + File.expects(:read).with("/temp/dir/1234567890.tar.gz").returns(:mock_file_contents) + + FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.gz") + FileUtils.expects(:rm_rf).with("/temp/dir/1234567890") + + @strategy.deploy! + end + + def test_deploy_with_zip_should_use_zip_and_checkout + Dir.expects(:tmpdir).returns("/temp/dir") + @config[:copy_compression] = :zip + @source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout) + + @strategy.expects(:system).with(:local_checkout) + @strategy.expects(:system).with("zip -qr /temp/dir/1234567890.zip /temp/dir/1234567890") + @strategy.expects(:put).with(:mock_file_contents, "/tmp/1234567890.zip") + @strategy.expects(:run).with("cd /u/apps/test/releases && unzip -q /tmp/1234567890.zip && rm /tmp/1234567890.zip") + + mock_file = mock("file") + mock_file.expects(:puts).with("154") + File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file) + File.expects(:read).with("/temp/dir/1234567890.zip").returns(:mock_file_contents) + + FileUtils.expects(:rm).with("/temp/dir/1234567890.zip") + FileUtils.expects(:rm_rf).with("/temp/dir/1234567890") + + @strategy.deploy! + end + + def test_deploy_with_bzip2_should_use_zip_and_checkout + Dir.expects(:tmpdir).returns("/temp/dir") + @config[:copy_compression] = :bzip2 + @source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout) + + @strategy.expects(:system).with(:local_checkout) + @strategy.expects(:system).with("tar cjf /temp/dir/1234567890.tar.bz2 /temp/dir/1234567890") + @strategy.expects(:put).with(:mock_file_contents, "/tmp/1234567890.tar.bz2") + @strategy.expects(:run).with("cd /u/apps/test/releases && tar xjf /tmp/1234567890.tar.bz2 && rm /tmp/1234567890.tar.bz2") + + mock_file = mock("file") + mock_file.expects(:puts).with("154") + File.expects(:open).with("/temp/dir/1234567890/REVISION", "w").yields(mock_file) + File.expects(:read).with("/temp/dir/1234567890.tar.bz2").returns(:mock_file_contents) + + FileUtils.expects(:rm).with("/temp/dir/1234567890.tar.bz2") + FileUtils.expects(:rm_rf).with("/temp/dir/1234567890") + + @strategy.deploy! + end + + def test_deploy_with_custom_copy_dir_should_use_that_as_tmpdir + Dir.expects(:tmpdir).never + @config[:copy_dir] = "/other/path" + @source.expects(:checkout).with("154", "/other/path/1234567890").returns(:local_checkout) + + @strategy.expects(:system).with(:local_checkout) + @strategy.expects(:system).with("tar czf /other/path/1234567890.tar.gz /other/path/1234567890") + @strategy.expects(:put).with(:mock_file_contents, "/tmp/1234567890.tar.gz") + @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("/other/path/1234567890/REVISION", "w").yields(mock_file) + File.expects(:read).with("/other/path/1234567890.tar.gz").returns(:mock_file_contents) + + FileUtils.expects(:rm).with("/other/path/1234567890.tar.gz") + FileUtils.expects(:rm_rf).with("/other/path/1234567890") + + @strategy.deploy! + end +end