Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Run a build script in Copy deploy strategy #82

Merged
merged 1 commit into from

2 participants

@brugidou

Use the :build_script configuration variable

The build script will be run before compression/exclusion of files,
if a :copy_cache is used, the build will run in the cache directory.

The reason for this is because it is very common to run a build script once before deploying (and not after deploying using the finalize_update task). Let me know if this is a good idea or if you have a better/smarter/prettier solution. We could consider extending this to also accept a block as a build_script.

Thanks for the feedback

@brugidou brugidou Run a build script in Copy deploy strategy
Use the :build_script configuration variable

The build script will be run before compression/exclusion of files,
if a :copy_cache is used, the build will run in the cache directory.
b9d3940
@leehambley leehambley merged commit 401a21b into capistrano:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 16, 2011
  1. @brugidou

    Run a build script in Copy deploy strategy

    brugidou authored
    Use the :build_script configuration variable
    
    The build script will be run before compression/exclusion of files,
    if a :copy_cache is used, the build will run in the cache directory.
This page is out of date. Refresh to see the latest.
View
26 lib/capistrano/recipes/deploy/strategy/copy.rb
@@ -38,6 +38,16 @@ module Strategy
# :copy_compression, which must be one of :gzip, :bz2, or
# :zip, and which specifies how the source should be compressed for
# transmission to each host.
+ #
+ # 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.
+ #
+ # set :build_script, "make all"
+ #
+ # Note that if you use :copy_cache, the :build_script is used on the
+ # cache and thus you get faster compilation if your script does not
+ # recompile everything.
class Copy < Base
# Obtains a copy of the source code locally (via the #command method),
# compresses it to a single file, copies that file to all target
@@ -58,6 +68,8 @@ def deploy!
raise Capistrano::Error, "shell command failed with return code #{$?}"
end
+ build(copy_cache)
+
FileUtils.mkdir_p(destination)
logger.debug "copying cache to deployment staging area #{destination}"
@@ -84,6 +96,8 @@ def deploy!
logger.debug "getting (via #{copy_strategy}) revision #{revision} to #{destination}"
system(command)
+ build(destination)
+
if copy_exclude.any?
logger.debug "processing exclusions..."
if copy_exclude.any?
@@ -108,6 +122,18 @@ def deploy!
FileUtils.rm_rf destination rescue nil
end
+ def build(directory)
+ return unless configuration[:build_script]
+
+ Dir.chdir(directory) do
+ self.system(configuration[:build_script])
+ # Check the return code of last system command and rollback if not 0
+ unless $? == 0
+ raise Capistrano::Error, "shell command failed with return code #{$?}"
+ end
+ end
+ end
+
def check!
super.check do |d|
d.local.command(source.local.command) if source.local.command
View
14 test/deploy/strategy/copy_test.rb
@@ -288,6 +288,20 @@ def test_with_copy_cache_with_excludes_should_not_copy_excluded_files
@strategy.deploy!
end
+ def test_with_build_script_should_run_script
+ @config[:build_script] = "mkdir bin"
+
+ Dir.expects(:tmpdir).returns("/temp/dir")
+ @source.expects(:checkout).with("154", "/temp/dir/1234567890").returns(:local_checkout)
+ @strategy.expects(:system).with(:local_checkout)
+
+ Dir.expects(:chdir).with("/temp/dir/1234567890").yields
+ @strategy.expects(:system).with("mkdir bin")
+
+ prepare_standard_compress_and_copy!
+ @strategy.deploy!
+ end
+
private
def prepare_directory_tree!(cache, exclude=false)
Something went wrong with that request. Please try again.