Skip to content

Commit 9ccea97

Browse files
Fix wrong logic for getting latest image (#201)
1 parent cc81743 commit 9ccea97

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ Changes since the last non-beta release.
1414

1515
_Please add entries here for your pull requests that have not yet been released._
1616

17+
### Fixed
18+
19+
- Fixed issue where latest image may be incorrect. [PR 201](https://github.com/shakacode/control-plane-flow/pull/201) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
20+
- Fixed issue where `build-image` command hangs forever waiting for image to be available. [PR 201](https://github.com/shakacode/control-plane-flow/pull/201) by [Rafael Gomes](https://github.com/rafaelgomesxyz).
21+
1722
## [2.2.0] - 2024-06-07
1823

1924
### Fixed

lib/command/build_image.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def call # rubocop:disable Metrics/MethodLength
4141
progress.puts("\nPushed image to '/org/#{config.org}/image/#{image_name}'.\n\n")
4242

4343
step("Waiting for image to be available", retry_on_failure: true) do
44-
image_name == cp.latest_image(refresh: true)
44+
images = cp.query_images["items"]
45+
images.find { |image| image["name"] == image_name }
4546
end
4647
end
4748
end

lib/core/controlplane.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ def profile_delete(profile)
3939

4040
# image
4141

42-
def latest_image(a_gvc = gvc, a_org = org, refresh: false)
42+
def latest_image(a_gvc = gvc, a_org = org)
4343
@latest_image ||= {}
44-
@latest_image[a_gvc] = nil if refresh
4544
@latest_image[a_gvc] ||=
4645
begin
4746
items = query_images(a_gvc, a_org)["items"]
@@ -69,7 +68,7 @@ def latest_image_from(items, app_name: gvc, name_only: true)
6968
if matching_items.empty?
7069
name_only ? "#{app_name}:#{NO_IMAGE_AVAILABLE}" : nil
7170
else
72-
latest_item = matching_items.max_by { |item| extract_image_number(item["name"]) }
71+
latest_item = matching_items.max_by { |item| DateTime.parse(item["created"]) }
7372
name_only ? latest_item["name"] : latest_item
7473
end
7574
end

spec/command/cleanup_images_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
end
159159

160160
context "with multiple apps" do
161-
let!(:app_prefix) { dummy_test_app_prefix("with-image-retention") }
161+
let!(:app_prefix) { dummy_test_app_prefix("image-retention") }
162162
let!(:app1) { dummy_test_app("image-retention", "1", create_if_not_exists: true) }
163163
let!(:app2) { dummy_test_app("image-retention", "2", create_if_not_exists: true) }
164164

spec/command/run_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@
256256
run_cpl_command!("delete", "-a", app, "--workload", "rails-runner", "--yes")
257257
end
258258

259-
it "updates runner workload" do
259+
it "updates runner workload", :slow do
260260
result = nil
261261

262262
spawn_cpl_command("run", "-a", app, "--entrypoint", "none", "--", "ls") do |it|
@@ -279,7 +279,7 @@
279279
run_cpl_command!("delete", "-a", app, "--workload", "rails-runner", "--yes")
280280
end
281281

282-
it "updates runner workload" do
282+
it "updates runner workload", :slow do
283283
result = nil
284284

285285
spawn_cpl_command("run", "-a", app, "--entrypoint", "none", "--", "ls") do |it|

0 commit comments

Comments
 (0)