Class: DockerFlow::Utils
- Inherits:
-
Object
- Object
- DockerFlow::Utils
- Defined in:
- lib/utils.rb
Class Method Summary collapse
- .get_branch ⇒ Object
- .get_commit_version ⇒ Object
- .get_system_info ⇒ Object
- .is_ci ⇒ Object
- .print_br ⇒ Object
- .put_build_information(info) ⇒ Object
- .put_project_title(title) ⇒ Object
- .put_system_info ⇒ Object
Class Method Details
.get_branch ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/utils.rb', line 8 def self.get_branch if self.is_ci if ENV.include? 'GIT_BRANCH' branch = ENV['GIT_BRANCH'].gsub('origin/', '').strip else # Jenkins 2 with Jenkinsfile branch = ENV['BRANCH_NAME'].strip end 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_version ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/utils.rb', line 25 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_info ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/utils.rb', line 40 def self.get_system_info system = Ohai::System.new system.load_plugins system.run_plugins(true, %w(cpu platform memory)) 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_ci ⇒ Object
36 37 38 |
# File 'lib/utils.rb', line 36 def self.is_ci return (ENV.include? 'CI' and ENV['CI'] == 'true') end |
.print_br ⇒ Object
75 76 77 |
# File 'lib/utils.rb', line 75 def self.print_br puts '-' * DockerFlow.[:line_length] end |
.put_build_information(info) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/utils.rb', line 58 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
54 55 56 |
# File 'lib/utils.rb', line 54 def self.put_project_title(title) puts " # Project: #{title}" end |
.put_system_info ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/utils.rb', line 67 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 |