Class: Bcnd::QuayIo
- Inherits:
-
Object
- Object
- Bcnd::QuayIo
- Defined in:
- lib/bcnd/quay_io.rb
Defined Under Namespace
Classes: Connection
Instance Attribute Summary collapse
-
#conn ⇒ Object
Returns the value of attribute conn.
Instance Method Summary collapse
- #automated_build_status(repo:, git_sha:) ⇒ Object
- #automated_builds_for(repo:, git_sha:) ⇒ Object
- #docker_image_id_for_tag(repo:, tag:) ⇒ Object
-
#initialize(token) ⇒ QuayIo
constructor
A new instance of QuayIo.
- #put_tag(repo:, image_id:, tag:) ⇒ Object
- #wait_for_automated_build(repo:, git_sha:, timeout: 3600) ⇒ Object
Constructor Details
#initialize(token) ⇒ QuayIo
Returns a new instance of QuayIo.
47 48 49 |
# File 'lib/bcnd/quay_io.rb', line 47 def initialize(token) @conn = Connection.new(token) end |
Instance Attribute Details
#conn ⇒ Object
Returns the value of attribute conn.
45 46 47 |
# File 'lib/bcnd/quay_io.rb', line 45 def conn @conn end |
Instance Method Details
#automated_build_status(repo:, git_sha:) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/bcnd/quay_io.rb', line 58 def automated_build_status(repo:, git_sha:) builds = automated_builds_for(repo: repo, git_sha: git_sha) phases = builds.map { |b| b["phase"] } if !phases.include?("complete") && phases.include?("error") return :failed end if phases.include?("complete") return :finished else return :building end end |
#automated_builds_for(repo:, git_sha:) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/bcnd/quay_io.rb', line 51 def automated_builds_for(repo:, git_sha:) builds = conn.get(path: "/repository/#{repo}/build/?limit=20")["builds"] builds.select do |b| b["trigger_metadata"]["commit"] == git_sha.downcase end end |
#docker_image_id_for_tag(repo:, tag:) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/bcnd/quay_io.rb', line 89 def docker_image_id_for_tag(repo:, tag:) resp = conn.get( path: "/repository/#{repo}/tag/", query_params: { "specificTag" => tag } ) = resp["tags"] .find { |tag| tag["end_ts"].nil? }["docker_image_id"] end |
#put_tag(repo:, image_id:, tag:) ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/bcnd/quay_io.rb', line 102 def put_tag(repo:, image_id:, tag:) conn.put( path: "/repository/#{repo}/tag/#{tag}", body: { image: image_id } ) end |
#wait_for_automated_build(repo:, git_sha:, timeout: 3600) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/bcnd/quay_io.rb', line 73 def wait_for_automated_build(repo:, git_sha:, timeout: 3600) loop do status = automated_build_status(repo: repo, git_sha: git_sha) case status when :failed raise "The docker build failed" when :finished puts "" return when :building print '.' sleep 5 end end end |