Class: Circus::Act

Inherits:
Object
  • Object
show all
Defined in:
lib/circus/act.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, dir, props = {}) ⇒ Act

Returns a new instance of Act.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/circus/act.rb', line 8

def initialize(name, dir, props = {})
  @name = name
  @dir = dir
  @props = props
  
  # Merge act specific properties
  if File.exists? act_file
    act_cfg = YAML.load(File.read(act_file))
    @props.merge! act_cfg
  end
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



6
7
8
# File 'lib/circus/act.rb', line 6

def dir
  @dir
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/circus/act.rb', line 6

def name
  @name
end

#profileObject (readonly)

Returns the value of attribute profile.



6
7
8
# File 'lib/circus/act.rb', line 6

def profile
  @profile
end

#propsObject (readonly)

Returns the value of attribute props.



6
7
8
# File 'lib/circus/act.rb', line 6

def props
  @props
end

Instance Method Details

#act_fileObject



70
71
72
# File 'lib/circus/act.rb', line 70

def act_file
  File.join(@dir, 'act.yaml')
end

#assemble(logger, output_root_dir, overlay_root) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/circus/act.rb', line 42

def assemble(logger, output_root_dir, overlay_root)
  detect! unless @profile
  
  overlay_dir = File.join(overlay_root, name)
  FileUtils.mkdir_p(overlay_dir)
  return false unless profile.package_for_deploy(logger, overlay_dir)
  
  begin
    # Squash the output file
    include_dirs = ["#{overlay_dir}/*"]
    include_dirs << "#{@dir}/*" if profile.package_base_dir?
    include_dirs.concat(profile.extra_dirs)
    output_name = File.join(output_root_dir, "#{name}.act")
  
    ExternalUtil.run_external(logger, 'Output packaging', 
      "mksquashfs #{include_dirs.join(' ')} #{output_name} -noappend -noI -noD -noF 2>&1")
  ensure
    profile.cleanup_after_deploy(logger, overlay_dir)
  end
end

#detect!Object



25
26
27
28
29
30
31
# File 'lib/circus/act.rb', line 25

def detect!
  # Run each profile against the directory to try to find one that matches
  profile_clazz = Circus::Profiles::PROFILES.find { |p| p.accepts?(@name, @dir, @props) }
  raise "No profile can run #{@dir}" unless profile_clazz
  
  @profile = profile_clazz.new(@name, @dir, @props)
end

#package_for_dev(logger, run_root_dir) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/circus/act.rb', line 33

def package_for_dev(logger, run_root_dir)
  detect! unless @profile
  
  # Create our run directory, and tell the profile to package into it
  run_dir = File.join(run_root_dir, @name)
  FileUtils.mkdir_p run_dir
  profile.package_for_dev(logger, run_dir)
end

#should_package?Boolean

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/circus/act.rb', line 20

def should_package?
  return false if @props['no-package']
  true
end

#upload(output_root_dir, act_store) ⇒ Object



63
64
65
66
67
68
# File 'lib/circus/act.rb', line 63

def upload(output_root_dir, act_store)
  detect! unless @profile

  output_name = File.join(output_root_dir, "#{name}.act")
  act_store.upload_act(output_name)
end