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 |
# 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_version ⇒ Object
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_info ⇒ Object
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_ci ⇒ Object
30 31 32 |
# File 'lib/utils.rb', line 30 def self.is_ci return (ENV.include? 'CI' and ENV['CI'] == 'true') end |
.print_br ⇒ Object
68 69 70 |
# File 'lib/utils.rb', line 68 def self.print_br puts '-' * DockerFlow.[: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_info ⇒ Object
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 |