Class: Potamus::Config
- Inherits:
-
Object
- Object
- Potamus::Config
- Defined in:
- lib/potamus/config.rb
Instance Method Summary collapse
- #branch ⇒ Object
- #branch_for_latest ⇒ Object
- #build_command ⇒ Object
- #commit ⇒ Object
- #dirty? ⇒ Boolean
- #git? ⇒ Boolean
- #image_name ⇒ Object
- #image_name_with_commit ⇒ Object
-
#initialize(root) ⇒ Config
constructor
A new instance of Config.
- #push_commands ⇒ Object
- #pushed? ⇒ Boolean
- #remote_commit ⇒ Object
- #remote_name ⇒ Object
- #tag_commands ⇒ Object
- #tags ⇒ Object
- #test_mode! ⇒ Object
Constructor Details
#initialize(root) ⇒ Config
Returns a new instance of Config.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/potamus/config.rb', line 7 def initialize(root) @root = File.(root) potamus_file_path = File.join(@root, 'PotamusFile') if File.file?(potamus_file_path) @options = YAML.load_file(potamus_file_path) else raise Error, "No Potamus file found at #{potamus_file_path}" end end |
Instance Method Details
#branch ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/potamus/config.rb', line 63 def branch stdout, stderr, status = Open3.capture3("cd #{@root} && git symbolic-ref HEAD") unless status.success? raise Error, "Could not get current commit (#{stderr})" end stdout.strip.sub('refs/heads/', '') end |
#branch_for_latest ⇒ Object
22 23 24 |
# File 'lib/potamus/config.rb', line 22 def branch_for_latest @options['branch_for_latest'] || 'master' end |
#build_command ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/potamus/config.rb', line 72 def build_command [ "cd #{@root}", '&&', 'docker', 'build', '.', '-t', image_name_with_commit, '--build-arg', 'commit_ref=' + commit, '--build-arg', 'branch=' + branch ].join(' ') end |
#commit ⇒ Object
51 52 53 |
# File 'lib/potamus/config.rb', line 51 def commit get_commit_ref(branch) end |
#dirty? ⇒ Boolean
42 43 44 45 46 47 48 49 |
# File 'lib/potamus/config.rb', line 42 def dirty? stdout, stderr, status = Open3.capture3("cd #{@root} && git status --short") unless status.success? raise Error, "Could not determine git status using `git status` (#{stderr})" end !stdout.strip.empty? end |
#git? ⇒ Boolean
38 39 40 |
# File 'lib/potamus/config.rb', line 38 def git? File.directory?(File.join(@root, '.git')) end |
#image_name ⇒ Object
26 27 28 |
# File 'lib/potamus/config.rb', line 26 def image_name @options['image_name'] || raise(Error, "image_name is required in the PotamusFile") end |
#image_name_with_commit ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/potamus/config.rb', line 30 def image_name_with_commit if @test_mode "#{image_name}:test" else "#{image_name}:#{commit}" end end |
#push_commands ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/potamus/config.rb', line 97 def push_commands if @test_mode return { 'test' => push_command('test') } end hash = {} hash[commit] = push_command(commit) .each do |tag| hash[tag] = push_command(tag) end hash end |
#pushed? ⇒ Boolean
59 60 61 |
# File 'lib/potamus/config.rb', line 59 def pushed? commit == remote_commit end |
#remote_commit ⇒ Object
55 56 57 |
# File 'lib/potamus/config.rb', line 55 def remote_commit get_commit_ref("#{remote_name}/#{branch}") end |
#remote_name ⇒ Object
18 19 20 |
# File 'lib/potamus/config.rb', line 18 def remote_name @options['remote_name'] || 'origin' end |
#tag_commands ⇒ Object
91 92 93 94 95 |
# File 'lib/potamus/config.rb', line 91 def tag_commands .each_with_object({}) do |tag, hash| hash[tag] = tag_command(tag) end end |
#tags ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/potamus/config.rb', line 82 def return [] if @test_mode array = [] array << branch array << 'latest' if branch == branch_for_latest array end |
#test_mode! ⇒ Object
110 111 112 |
# File 'lib/potamus/config.rb', line 110 def test_mode! @test_mode = true end |