Skip to content

Commit

Permalink
Stack: uodate build_deploy to pass allow_concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
kartiki975 committed Mar 20, 2024
1 parent 0834c0b commit e73b267
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Migrate from legacy Rails secrets to credentials (#1326)
* Rails secrets were [deprecated in Rails 7.1](https://github.com/rails/rails/pull/48472)
* [Guide on credentials](https://guides.rubyonrails.org/security.html#custom-credentials)
* For deployments, `allow_concurrency` defaults to the same value as `force`. If wanted, it can be set separately by passing the intended value for `allow_concurrency` to `build_deploy` method


# 0.39.0

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ For example:
fetch:
curl --silent https://app.example.com/services/ping/version
```

**Note:** Currently, deployments in emergency mode are configured to occur concurrently via [the `build_deploy` method](https://github.com/Shopify/shipit-engine/blob/main/app/models/shipit/stack.rb),
whose `allow_concurrency` keyword argument defaults to `force`, where `force` is true when emergency mode is enabled.
If you'd like to separate these two from one another, override this method as desired in your service.

<h3 id="kubernetes">Kubernetes</h3>

**<code>kubernetes</code>** allows to specify a Kubernetes namespace and context to deploy to.
Expand Down
1 change: 1 addition & 0 deletions app/controllers/shipit/deploys_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def create
current_user,
env: deploy_params[:env],
force: params[:force].present?,
allow_concurrency: params[:allow_concurrency].present?,
)
respond_with(@deploy.stack, @deploy)
rescue Task::ConcurrentTaskRunning
Expand Down
4 changes: 2 additions & 2 deletions app/models/shipit/stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ def trigger_task(definition_id, user, env: nil, force: false)
task
end

def build_deploy(until_commit, user, env: nil, force: false)
def build_deploy(until_commit, user, env: nil, force: false, allow_concurrency: force)
since_commit = last_deployed_commit.presence || commits.first
deploys.build(
user_id: user.id,
until_commit: until_commit,
since_commit: since_commit,
env: filter_deploy_envs(env&.to_h || {}),
allow_concurrency: force,
allow_concurrency: allow_concurrency,
ignored_safeties: force || !until_commit.deployable?,
max_retries: retries_on_deploy,
)
Expand Down
2 changes: 1 addition & 1 deletion test/models/deploys_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ def generate_commits(amount:, stack_id:, user_id:, validate:)

assert_difference -> { ReleaseStatus.count }, +1 do
assert_equal 'unknown', @commit.last_release_status.state
@deploy = @stack.trigger_deploy(@commit, AnonymousUser.new, force: true)
@deploy = @stack.trigger_deploy(@commit, AnonymousUser.new, force: true, allow_concurrency: true)
assert_equal 'pending', @commit.last_release_status.state
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/models/shipit/stack_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def self.deliver(event, stack, payload)
end

test "#active_task? is false if stack has a concurrent deploy in active state" do
@stack.trigger_deploy(shipit_commits(:third), AnonymousUser.new, force: true)
@stack.trigger_deploy(shipit_commits(:third), AnonymousUser.new, force: true, allow_concurrency: true)
refute @stack.active_task?
end

Expand Down

0 comments on commit e73b267

Please sign in to comment.