Skip to content

Commit

Permalink
Fix issue where run command fails when runner workload has ENV but …
Browse files Browse the repository at this point in the history
…original workload does not (#227)
  • Loading branch information
rafaelgomesxyz authored Aug 22, 2024
1 parent 3de0445 commit 1a11420
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 4 additions & 13 deletions lib/command/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/command/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 22 additions & 0 deletions spec/command/run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1a11420

Please sign in to comment.