Class: DockerFlow::Utils

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

Class Method Summary collapse

Class Method Details

.get_branchObject



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

def self.get_branch
  if self.is_ci
    branch = ENV['GIT_BRANCH'].gsub('origin/', '').strip
  else
    branch = self.system_command('git rev-parse --abbrev-ref HEAD').lines.first.strip
  end

  # make branch name tag-safe by replacing further slashes with .
  branch.gsub('/', '.')
end

.get_commit_versionObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/utils.rb', line 19

def self.get_commit_version

  begin
    version = self.system_command 'git describe --tags'
  rescue
    version = self.system_command 'git rev-parse --short HEAD'
  end

  version.lines.first.strip
end

.get_system_infoObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/utils.rb', line 34

def self.get_system_info
  system = Ohai::System.new
  system.all_plugins
  data = system.data

  {
      :os => "#{data[:platform]} #{data[:os]} #{data[:platform_version]}",
      :cpu => "#{data[:cpu]['0'][:model_name]}",
      :ram => "#{(data[:memory][:total].chomp('kB').to_f / 1000 / 1000).round(2)} GB (#{(data[:memory][:free].chomp('kB').to_f / 1000 / 1000).round(2)} GB free)"
  }

end

.is_ciObject



30
31
32
# File 'lib/utils.rb', line 30

def self.is_ci
  return (ENV.include? 'CI' and ENV['CI'] == 'true')
end


68
69
70
# File 'lib/utils.rb', line 68

def self.print_br
  puts '-' * DockerFlow.options[:line_length]
end

.put_build_information(info) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/utils.rb', line 51

def self.put_build_information(info)
  puts ' # Build information'
  puts "    Environment: #{info[:host_type]}"
  puts "    Git branch: #{info[:branch]} @ #{info[:commit_version]}"
  puts "    Container repository: #{info[:repository]}"
  puts "    Build container tag: #{info[:build_container_tag]}"
  puts "    Branch container tag: #{info[:branch_container_tag]}"
end

.put_project_title(title) ⇒ Object



47
48
49
# File 'lib/utils.rb', line 47

def self.put_project_title(title)
  puts " # Project: #{title}"
end

.put_system_infoObject



60
61
62
63
64
65
66
# File 'lib/utils.rb', line 60

def self.put_system_info
  puts ' # System information'
  info = self.get_system_info
  puts "    OS: #{info[:os]}"
  puts "    CPU: #{info[:cpu]}"
  puts "    RAM: #{info[:ram]}"
end