Class: Capistrano::SharedConfig::Integration

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/shared_config/integration.rb

Class Method Summary collapse

Class Method Details

.load_into(capistrano_config) ⇒ Object



8
9
10
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
# File 'lib/capistrano/shared_config/integration.rb', line 8

def self.load_into(capistrano_config)
  capistrano_config.load do
    set(:shared_config_files, fetch(:shared_config_files, []))
    set(:shared_config_symlinks, fetch(:shared_config_symlinks, shared_config_files))

    set(:run_shared_config_symlinks, fetch(:run_shared_config_symlinks, [:after, 'deploy:update_code']))
    set(:run_shared_config_sync, fetch(:run_shared_config_sync, [:after, 'deploy:update_code']))
    set(:run_early_shared_config_check, fetch(:run_early_shared_config_check, [:before, 'deploy:update_code']))

    set(:_shared_config_files, (ENV['FILE'] ? [ENV['FILE']] : shared_config_files).
      map{|name| ConfigFile.new(name, binding)}
    )

    namespace :shared_config do
      desc 'Create shared config folder'
      task :setup do
        run "mkdir #{File.join(shared_path, 'config')}"
      end
      after 'deploy:setup', 'shared_config:setup'

      desc 'Create symlinks for config files from shared_config_symlinks array'
      task :symlinks do
        next if shared_config_symlinks.empty?
        commands = shared_config_symlinks.map do |name|
          full_name = ConfigFile.name(name)
          "ln -nfs #{File.join(shared_path, 'config', full_name)} #{File.join(latest_release, 'config', full_name)}"
        end

        run commands.join(' && ')
      end
      on run_shared_config_symlinks.first, 'shared_config:symlinks', only: run_shared_config_symlinks.last

      desc 'Sync all config files'
      task :sync do
        _shared_config_files.each do |file|
          put(file.content, File.join(shared_path, 'config', file.name))
        end
      end
      on run_shared_config_sync.first, 'shared_config:sync', only: run_shared_config_sync.last

      desc 'Check all config files'
      task :check do
        _shared_config_files.each do |file|
          raise Capistrano::CommandError.new(file.error) unless file.valid?
        end
      end
      on run_early_shared_config_check.first, 'shared_config:check', only: run_early_shared_config_check.last
      before 'shared_config:sync', 'shared_config:check'

      task :show do
        _shared_config_files.each do |file|
          puts '', file.name
          puts ?= * 80
          puts file.content
          puts ?= * 80
        end
      end
    end
  end
end