Class: Dodebui::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/dodebui/cli.rb

Overview

commandline interface for dodebui

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCli

Returns a new instance of Cli.



16
17
18
19
# File 'lib/dodebui/cli.rb', line 16

def initialize
  @dodebuifiles ||= ['Dodebuifile']
  @original_dir = Dir.getwd
end

Instance Attribute Details

#build_distributionsObject

Returns the value of attribute build_distributions.



9
10
11
# File 'lib/dodebui/cli.rb', line 9

def build_distributions
  @build_distributions
end

#source_templatesObject

Returns the value of attribute source_templates.



9
10
11
# File 'lib/dodebui/cli.rb', line 9

def source_templates
  @source_templates
end

#wdObject (readonly)

Returns the value of attribute wd.



10
11
12
# File 'lib/dodebui/cli.rb', line 10

def wd
  @wd
end

Class Method Details

.loggerObject



12
13
14
# File 'lib/dodebui/cli.rb', line 12

def self.logger
  @logger ||= Logger.new(STDOUT)
end

Instance Method Details

#buildObject



109
110
111
112
113
114
115
116
117
118
# File 'lib/dodebui/cli.rb', line 109

def build
  threads = []
  @distributions.each do |dist|
    threads << Thread.new do
      dist.build.build
    end
  end
  # wait for all threads
  threads.each(&:join)
end

#dodebuifile?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
# File 'lib/dodebui/cli.rb', line 21

def dodebuifile?
  @dodebuifiles.each do |fn|
    return fn if File.exist?(fn)
  end
  nil
end

#ensure_images_updatedObject



90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/dodebui/cli.rb', line 90

def ensure_images_updated
  # ensure images are up to date
  threads = []
  @distributions.each do |dist|
    threads << Thread.new do
      dist.ensure_image_updated
    end
  end

  # wait for all threads
  threads.each(&:join)
end

#find_dodebuifile_locationObject

:nodoc:



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dodebui/cli.rb', line 28

def find_dodebuifile_location # :nodoc:
  here = Dir.pwd
  until (fn = dodebuifile?)
    Dir.chdir('..')
    return nil if Dir.pwd == here
    here = Dir.pwd
  end
  [fn, here]
ensure
  Dir.chdir(@original_dir)
end

#load_dodebiufileObject



40
41
42
43
44
45
46
47
48
# File 'lib/dodebui/cli.rb', line 40

def load_dodebiufile
  dodebuifile, location = find_dodebuifile_location
  fail 'No Dodebuifile found' if dodebuifile.nil?
  @dodebuifile = File.join(location, dodebuifile)
  @wd = location
  Cli.logger.info("Working directory #{@wd}")
  Cli.logger.info("Config file #{@dodebuifile}")
  load_dodebiufile_raw @dodebuifile
end

#load_dodebiufile_raw(path) ⇒ Object



50
51
52
53
54
55
# File 'lib/dodebui/cli.rb', line 50

def load_dodebiufile_raw(path)
  File.open(path, 'r') do |infile|
    code = infile.read
    eval(code) # rubocop:disable Lint/Eval
  end
end

#loggerObject



79
80
81
# File 'lib/dodebui/cli.rb', line 79

def logger
  Cli.logger
end

#prepare_distributions(distributions = []) ⇒ Object



83
84
85
86
87
88
# File 'lib/dodebui/cli.rb', line 83

def prepare_distributions(distributions = [])
  @distributions = distributions.map do |name|
    Distribution.new(name, self)
  end
  ensure_images_updated
end

#prepare_sourcesObject



103
104
105
106
107
# File 'lib/dodebui/cli.rb', line 103

def prepare_sources
  @distributions.each do |dist|
    dist.build.source
  end
end

#runObject



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/dodebui/cli.rb', line 57

def run
  Cli.logger.info("Initializing dodebui #{VERSION}")

  load_dodebiufile

  test_docker

  prepare_distributions build_distributions

  prepare_sources

  build
end

#test_dockerObject



71
72
73
74
75
76
77
# File 'lib/dodebui/cli.rb', line 71

def test_docker
  Docker.options[:read_timeout] = 3600
  data = Docker.version
  Cli.logger.info(
    "Connecting to Docker server successful (version #{data['Version']})"
  )
end