Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where run command fails when runner workload has ENV but original workload does not #227

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading