From 1a11420c6146606d64880c66669a9b33d9011bfc Mon Sep 17 00:00:00 2001 From: Rafael Gomes Date: Thu, 22 Aug 2024 08:29:27 -0300 Subject: [PATCH] Fix issue where `run` command fails when runner workload has ENV but original workload does not (#227) --- CHANGELOG.md | 3 +++ lib/command/base.rb | 17 ++++------------- lib/command/run.rb | 2 +- spec/command/run_spec.rb | 22 ++++++++++++++++++++++ 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84db1c70..1a2d029e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ Changes since the last non-beta release. _Please add entries here for your pull requests that have not yet been released._ +### Fixed + +- Fixed issue where `run` command fails when runner workload has ENV but original workload does not. [PR 227](https://github.com/shakacode/control-plane-flow/pull/227) by [Rafael Gomes](https://github.com/rafaelgomesxyz). ## [4.0.0] - 2024-08-21 diff --git a/lib/command/base.rb b/lib/command/base.rb index b0c645e3..2ddc5c80 100644 --- a/lib/command/base.rb +++ b/lib/command/base.rb @@ -465,21 +465,12 @@ def progress $stderr end - def step_error(error, abort_on_error: true) - message = error.message - if abort_on_error - progress.puts(" #{Shell.color('failed!', :red)}\n\n") - Shell.abort(message) - else - Shell.write_to_tmp_stderr(message) - end - end - - def step_finish(success) + def step_finish(success, abort_on_error: true) if success progress.puts(" #{Shell.color('done!', :green)}") else progress.puts(" #{Shell.color('failed!', :red)}\n\n#{Shell.read_from_tmp_stderr}\n\n") + exit(ExitCode::ERROR_DEFAULT) if abort_on_error end end @@ -499,10 +490,10 @@ def step(message, abort_on_error: true, retry_on_failure: false) # rubocop:disab success = yield end rescue RuntimeError => e - step_error(e, abort_on_error: abort_on_error) + Shell.write_to_tmp_stderr(e.message) end - step_finish(success) + step_finish(success, abort_on_error: abort_on_error) end end diff --git a/lib/command/run.rb b/lib/command/run.rb index f0af3ad9..59fd8470 100644 --- a/lib/command/run.rb +++ b/lib/command/run.rb @@ -207,7 +207,7 @@ def update_runner_workload # rubocop:disable Metrics/CyclomaticComplexity, Metri original_env_str = original_container_spec["env"]&.sort_by { |env| env["name"] }.to_s env_str = container_spec["env"]&.sort_by { |env| env["name"] }.to_s if original_env_str != env_str - container_spec["env"] = original_container_spec["env"] + container_spec["env"] = original_container_spec["env"] || [] should_update = true end diff --git a/spec/command/run_spec.rb b/spec/command/run_spec.rb index 3d2d4be9..72724489 100644 --- a/spec/command/run_spec.rb +++ b/spec/command/run_spec.rb @@ -252,5 +252,27 @@ expect(result[:stderr]).to include("Gemfile") end end + + context "when runner workload has ENV but original workload does not" do + let!(:app) { dummy_test_app } + + before do + run_cpflow_command!("apply-template", "app", "rails", "rails-runner-with-different-env", "-a", app) + run_cpflow_command!("build-image", "-a", app) + run_cpflow_command!("deploy-image", "-a", app) + end + + after do + run_cpflow_command!("delete", "-a", app, "--yes") + end + + it "updates runner workload", :slow do + result = run_cpflow_command("run", "-a", app, "--entrypoint", "none", "--", "ls") + + expect(result[:status]).to eq(0) + expect(result[:stderr]).to include("Updating runner workload") + expect(result[:stderr]).to include("Gemfile") + end + end end end