Class: Capistrano::Deploy::Strategy::BuildCopy

Inherits:
Base
  • Object
show all
Defined in:
lib/capistrano/recipes/deploy/strategy/build_copy.rb

Instance Method Summary collapse

Instance Method Details

#check!Object



81
82
83
84
85
86
87
# File 'lib/capistrano/recipes/deploy/strategy/build_copy.rb', line 81

def check!
  super.check do |d|
    d.local.command(source.local.command)
    d.local.command(compress(nil, nil).first)
    d.remote.command(decompress(nil).first)
  end
end

#copy_cacheObject

Returns the location of the local copy cache, if the strategy should use a local cache + copy instead of a new checkout/export every time. Returns nil unless :copy_cache has been set. If :copy_cache is true, a default cache location will be returned.



93
94
95
96
97
# File 'lib/capistrano/recipes/deploy/strategy/build_copy.rb', line 93

def copy_cache
  @copy_cache ||= configuration[:copy_cache] == true ?
    File.join(Dir.tmpdir, configuration[:application]) :
    configuration[:copy_cache]
end

#deploy!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/capistrano/recipes/deploy/strategy/build_copy.rb', line 11

def deploy!
  logger.debug("start build strategy #{copy_cache}")
  if copy_cache
    if File.exists?(copy_cache)
      logger.debug "refreshing local cache to revision #{revision} at #{copy_cache}"
      system(source.sync(revision, copy_cache))
    else
      logger.debug "preparing local cache at #{copy_cache}"
      system(source.checkout(revision, copy_cache))
    end
    
    logger.debug "copying cache to deployment staging area #{destination}"
    Dir.chdir(copy_cache) do
      FileUtils.mkdir_p(destination)
      queue = Dir.glob("*", File::FNM_DOTMATCH)
      while queue.any?
        item = queue.shift
        name = File.basename(item)

        next if name == "." || name == ".."
        next if copy_exclude.any? { |pattern| File.fnmatch(pattern, item) }

        if File.directory?(item)
          queue += Dir.glob("#{item}/*", File::FNM_DOTMATCH)
          FileUtils.mkdir(File.join(destination, item))
        else
          FileUtils.ln(File.join(copy_cache, item), File.join(destination, item))
        end
      end
    end
  else
    logger.debug "getting (via #{copy_strategy}) revision #{revision} to #{destination}"
    system(command)

    if copy_exclude.any?
      logger.debug "processing exclusions..."
      copy_exclude.each { |pattern| FileUtils.rm_rf(File.join(destination, pattern)) }
    end
  end
  logger.debug("start  build command")
  system(build_command)
  Dir.chdir(tmpdir) 
  if File.directory? build_target_path
      FileUtils.mv(build_target_path,destination_tmp)
      #Capistrano::CLI.ui.ask('break point')
      FileUtils.rm_rf(destination)
      FileUtils.mv(destination_tmp, destination)
  else
      FileUtils.mkdir_p(destination_tmp)
      FileUtils.cp(build_target_path,File.join(destination_tmp,"/"))
      Dir.chdir(destination_tmp)
      system("#{decompress_package_file(build_target_path).join(" ")}")
      FileUtils.rm(File.join(destination_tmp,File.basename(build_target_path)))
      Dir.chdir(tmpdir)
      FileUtils.rm_rf(destination)
      FileUtils.mv(destination_tmp, destination)
  end
  File.open(File.join(destination, "REVISION"), "w") { |f| f.puts(revision) }
  logger.trace "compressing #{destination} to #{filename} at #{tmpdir}"
  Dir.chdir(tmpdir) { system(compress(File.basename(destination), File.basename(filename)).join(" ")) }

  content = File.open(filename, "rb") { |f| f.read }
  put content, remote_filename 
  run "cd #{configuration[:releases_path]} && #{decompress(remote_filename).join(" ")} && rm #{remote_filename}"
ensure
  FileUtils.rm filename rescue nil
  FileUtils.rm_rf destination rescue nil
  FileUtils.rm_rf destination_tmp rescue nil
end