Skip to content

Commit 1a11420

Browse files
Fix issue where run command fails when runner workload has ENV but original workload does not (#227)
1 parent 3de0445 commit 1a11420

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ 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 `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).
1720

1821
## [4.0.0] - 2024-08-21
1922

lib/command/base.rb

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -465,21 +465,12 @@ def progress
465465
$stderr
466466
end
467467

468-
def step_error(error, abort_on_error: true)
469-
message = error.message
470-
if abort_on_error
471-
progress.puts(" #{Shell.color('failed!', :red)}\n\n")
472-
Shell.abort(message)
473-
else
474-
Shell.write_to_tmp_stderr(message)
475-
end
476-
end
477-
478-
def step_finish(success)
468+
def step_finish(success, abort_on_error: true)
479469
if success
480470
progress.puts(" #{Shell.color('done!', :green)}")
481471
else
482472
progress.puts(" #{Shell.color('failed!', :red)}\n\n#{Shell.read_from_tmp_stderr}\n\n")
473+
exit(ExitCode::ERROR_DEFAULT) if abort_on_error
483474
end
484475
end
485476

@@ -499,10 +490,10 @@ def step(message, abort_on_error: true, retry_on_failure: false) # rubocop:disab
499490
success = yield
500491
end
501492
rescue RuntimeError => e
502-
step_error(e, abort_on_error: abort_on_error)
493+
Shell.write_to_tmp_stderr(e.message)
503494
end
504495

505-
step_finish(success)
496+
step_finish(success, abort_on_error: abort_on_error)
506497
end
507498
end
508499

lib/command/run.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def update_runner_workload # rubocop:disable Metrics/CyclomaticComplexity, Metri
207207
original_env_str = original_container_spec["env"]&.sort_by { |env| env["name"] }.to_s
208208
env_str = container_spec["env"]&.sort_by { |env| env["name"] }.to_s
209209
if original_env_str != env_str
210-
container_spec["env"] = original_container_spec["env"]
210+
container_spec["env"] = original_container_spec["env"] || []
211211
should_update = true
212212
end
213213

spec/command/run_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,5 +252,27 @@
252252
expect(result[:stderr]).to include("Gemfile")
253253
end
254254
end
255+
256+
context "when runner workload has ENV but original workload does not" do
257+
let!(:app) { dummy_test_app }
258+
259+
before do
260+
run_cpflow_command!("apply-template", "app", "rails", "rails-runner-with-different-env", "-a", app)
261+
run_cpflow_command!("build-image", "-a", app)
262+
run_cpflow_command!("deploy-image", "-a", app)
263+
end
264+
265+
after do
266+
run_cpflow_command!("delete", "-a", app, "--yes")
267+
end
268+
269+
it "updates runner workload", :slow do
270+
result = run_cpflow_command("run", "-a", app, "--entrypoint", "none", "--", "ls")
271+
272+
expect(result[:status]).to eq(0)
273+
expect(result[:stderr]).to include("Updating runner workload")
274+
expect(result[:stderr]).to include("Gemfile")
275+
end
276+
end
255277
end
256278
end

0 commit comments

Comments
 (0)